API Documentation
Loading...
Searching...
No Matches
Vector.hpp
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Vector
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
35#include <type_traits>
36#include <cmath>
37#include <type_traits>
38/**--------------------------------------------------------------------------------------------------
39Namespace: Parke
40Namespace that wraps all Logic created by Tyler Parke
41*-----------------------------------------------------------------------------------------------**/
42namespace NDEVR
43{
44 /**--------------------------------------------------------------------------------------------------
45 Class: Vector
46 \brief An element of a vector space. An element of the real coordinate space Rn
47 Basis vector, one of a set of vectors (a "basis") that, in linear combination, can represent every vector in a given vector space
48 Column vector or row vector, a one-dimensional matrix often representing the solution of a system of linear equations
49 Coordinate vector, in linear algebra, an explicit representation of an element of any abstract vector space.
50 Used as the basis for Vertex class, Ray class, Point class etc. Simply stores x,y,z etc in linear memory.
51
52 t_dims: The number of dimensions used in a vector.
53 t_type: The numerical type used to store the value in each dimension. This may be a bool, float, integer, angle, or even another vector
54 for multidimensional groupings.
55
56 Author: Tyler Parke
57
58 Date: 2017-09-13
59 *-----------------------------------------------------------------------------------------------**/
60 template<uint01 t_dims, class t_type>
61 class Vector
62 {
63 public:
64 constexpr Vector() noexcept
65 : m_values()
66 {}
67
68 /**--------------------------------------------------------------------------------------------------
69 Fn: constexpr Vector::Vector(const Vector<t_dims, t_vec_type>& vector)
70
71 Copy constructor.
72
73 Author: Tyler Parke
74
75 Date: 2017-11-13
76
77 Parameters:
78 vector - The vector to copy to this vector.
79 *-----------------------------------------------------------------------------------------------**/
80 template<class t_vec_type>
81 constexpr explicit Vector(const Vector<t_dims, t_vec_type>& vector) noexcept
82 : m_values()
83 {
84 for (uint01 dim = 0; dim < t_dims; ++dim)
85 m_values[dim] = cast<t_type>(vector[dim]);
86 }
87
88 /**--------------------------------------------------------------------------------------------------
89 Fn: constexpr explicit Vector::Vector(const t_type& scaler)
90
91 Sets values in each dimension to the value in the passed in scaler
92
93 Author: Tyler Parke
94
95 Date: 2017-09-13
96
97 Parameters:
98 scaler - The scaler to set all dimensions to.
99 *-----------------------------------------------------------------------------------------------**/
100
101 constexpr explicit Vector(const t_type& scaler) noexcept
102 : m_values()
103 {
104 for(uint01 dim = 0; dim < t_dims; ++dim)
105 m_values[dim] = scaler;
106 }
107
108 /**--------------------------------------------------------------------------------------------------
109 Fn: constexpr explicit Vector::Vector(const t_type& scaler)
110
111 Sets values in each dimension to the respective value in the passed in scaler. Note the Vector must
112 be 2 dimensions to use this function.
113
114 Author: Tyler Parke
115
116 Date: 2017-09-13
117
118 Parameters:
119 x - The scaler to set the 0th or X dimension to
120 y - The scaler to set the 1st or Y dimension to
121 *-----------------------------------------------------------------------------------------------**/
122 template<uint01 tdims = t_dims>
123 constexpr Vector(const t_type& x, typename std::enable_if<tdims == 2, const t_type&>::type y)
124 : m_values{x, y}
125 {
126 static_assert(t_dims == 2, "Unexpected Number of Dimensions. Vector Size Required: 2");
127 }
128
129 /**--------------------------------------------------------------------------------------------------
130 Fn: constexpr explicit Vector::Vector(const t_type& scaler)
131
132 Sets values in each dimension to the respective value in the passed in scaler. Note the Vector must
133 be 3 dimensions to use this function.
134
135 Author: Tyler Parke
136
137 Date: 2017-09-13
138
139 Parameters:
140 x - The scaler to set the 0th or X dimension to
141 y - The scaler to set the 1st or Y dimension to
142 z - The scaler to set the 2nd or Z dimension to
143 *-----------------------------------------------------------------------------------------------**/
144 template<uint01 tdims = t_dims>
145 constexpr Vector(const t_type& x, const t_type& y, const typename std::enable_if<tdims == 3, const t_type&>::type z)
146 : m_values{x, y, z}
147 {
148 static_assert(t_dims == 3, "Unexpected Number of Dimensions. Vector Size Required: 3");
149 }
150
151 /**--------------------------------------------------------------------------------------------------
152 Fn: constexpr explicit Vector::Vector(const t_type& scaler)
153
154 Sets values in each dimension to the respective value in the passed in scaler. Note the Vector must
155 be 4 dimensions to use this function.
156
157 Author: Tyler Parke
158
159 Date: 2017-09-13
160
161 Parameters:
162 x - The scaler to set the 0th or X dimension to
163 y - The scaler to set the 1st or Y dimension to
164 z - The scaler to set the 2nd or Z dimension to
165 w - The scaler to set the 3rd or W dimension to
166 *-----------------------------------------------------------------------------------------------**/
167 template<uint01 tdims = t_dims>
168 constexpr Vector(const t_type& x, const t_type& y, const t_type& z, typename std::enable_if<tdims == 4, const t_type&>::type w)
169 : m_values{ x, y, z, w }
170 {
171 static_assert(t_dims == 4, "Unexpected Number of Dimensions. Vector Size Required: 4");
172 }
173
174 template<uint01 tdims = t_dims>
175 constexpr Vector(const t_type& x, const t_type& y, const t_type& z, const t_type& w, typename std::enable_if<tdims == 5, const t_type&>::type v)
176 : m_values{ x, y, z, w, v }
177 {
178 static_assert(t_dims == 5, "Unexpected Number of Dimensions. Vector Size Required: 5");
179 }
180
181 template<uint01 tdims = t_dims>
182 constexpr Vector(const t_type& x, const t_type& y, const t_type& z, const t_type& w, const t_type& v, typename std::enable_if<tdims == 6, const t_type&>::type u)
183 : m_values{ x, y, z, w, v, u }
184 {
185 static_assert(t_dims == 6, "Unexpected Number of Dimensions. Vector Size Required: 6");
186 }
187 template<uint01 tdims = t_dims>
188 constexpr Vector(const t_type& x, const t_type& y, const t_type& z, const t_type& w, const t_type& v, const t_type& u, const t_type& t, const t_type& s, typename std::enable_if<tdims == 9, const t_type&>::type r)
189 : m_values{ x, y, z, w, v, u, t, s, r }
190 {
191 static_assert(t_dims == 9, "Unexpected Number of Dimensions. Vector Size Required: 9");
192 }
193 /**--------------------------------------------------------------------------------------------------
194 Fn: constexpr explicit Vector::Vector(const t_type(&vector)[t_dims])
195
196 Given a container of statically determined array, transforms it to a vector
197
198 Author: Tyler Parke
199
200 Date: 2017-11-13
201
202 Parameters:
203 vector - The vector container object.
204 *-----------------------------------------------------------------------------------------------**/
205 constexpr explicit Vector(const t_type(&vector)[t_dims])
206 : m_values{}
207 {
208 for (uint01 dim = 0; dim < t_dims; dim++)
209 m_values[dim] = vector[dim];
210 }
211
212 /**--------------------------------------------------------------------------------------------------
213 Fn: constexpr Vector::Vector(const Vector<t_dims - 1, t_type>& vector, const t_type postfix)
214
215 Vectors. Creates a vector where the prefix vector is combined with the suffix scalers.
216
217 Author: Tyler Parke
218
219 Date: 2017-11-13
220
221 Parameters:
222 vector - The vector.
223 postfix - The postfix.
224 *-----------------------------------------------------------------------------------------------**/
225 template<uint01 tdims = t_dims>
226 constexpr Vector(const Vector<tdims - 1, t_type>& vector, typename std::enable_if<tdims >= 2, const t_type&>::type suffix)
227 : m_values{}
228 {
229 static_assert(t_dims >= 2, "Unexpected Number of Dimensions. Vector Size Required: >= 2");
230 for(uint01 dim = 0; dim < t_dims - 1; ++dim)
231 m_values[dim] = vector[dim];
232 m_values[t_dims - 1] = suffix;
233 }
234
235 /**--------------------------------------------------------------------------------------------------
236 Fn: constexpr Vector::Vector(const Vector<t_dims - 2, t_type>& vector, const t_type postfix_a,
237 const t_type postfix_b)
238
239 Vectors. Creates a vector where the prefix vector is combined with the suffix scalers.
240
241 Author: Tyler Parke
242
243 Date: 2017-11-13
244
245 Parameters:
246 vector - The vector.
247 postfix_a - The postfix a.
248 postfix_b - The postfix b.
249 *-----------------------------------------------------------------------------------------------**/
250 template<uint01 tdims = t_dims>
251 constexpr Vector(const Vector<getMax(tdims - 2, 0), t_type>& vector, const t_type& suffix_a, typename std::enable_if<tdims >= 3, const t_type&>::type suffix_b)
252 : m_values{}
253 {
254 static_assert(t_dims >= 3, "Unexpected Number of Dimensions. Vector Size Required: >= 3");
255 for(uint01 dim = 0; dim < t_dims - 2; ++dim)
256 m_values[dim] = vector[dim];
257 m_values[t_dims - 2] = suffix_a;
258 m_values[t_dims - 1] = suffix_b;
259 }
260
261 /**--------------------------------------------------------------------------------------------------
262 Fn: constexpr Vector::Vector(const t_type prefix, const Vector<t_dims - 1, t_type>& vector)
263
264 Vectors. Creates a vector where the prefix scaler is combined with the suffix vector.
265
266 Author: Tyler Parke
267
268 Date: 2017-11-13
269
270 Parameters:
271 prefix - The prefix.
272 vector - The vector.
273 *-----------------------------------------------------------------------------------------------**/
274 template<uint01 tdims = t_dims>
275 constexpr Vector(const t_type& prefix, typename std::enable_if<tdims >= 2, const Vector<t_dims - 1, t_type>&>::type vector)
276 : m_values{}
277 {
278 static_assert(t_dims >= 2, "Unexpected Number of Dimensions. Vector Size Required: >= 2");
279 m_values[X] = prefix;
280 for(uint01 dim = Y; dim < t_dims; ++dim)
281 m_values[dim] = vector[dim - 1];
282 }
283 /**--------------------------------------------------------------------------------------------------
284 Fn: constexpr Vector::Vector(const t_type prefix, const Vector<t_dims - 1, t_type>& vector)
285
286 Vectors. Creates a vector where the prefix scaler values are combined with the suffix vector.
287
288 Author: Tyler Parke
289
290 Date: 2017-11-13
291
292 Parameters:
293 prefix_a - The first prefix.
294 prefix_b - The second prefix.
295 vector - The vector.
296 *-----------------------------------------------------------------------------------------------**/
297 template<uint01 tdims = t_dims>
298 constexpr Vector(const t_type& prefix_a, const t_type& prefix_b, typename std::enable_if<tdims >= 3, const Vector<tdims - 1, t_type>&>::type vector)
299 : m_values{}
300 {
301 static_assert(t_dims >= 3, "Unexpected Number of Dimensions. Vector Size Required: >= 3");
302 m_values[X] = prefix_a;
303 m_values[Y] = prefix_b;
304 for (uint01 dim = Z; dim < t_dims; ++dim)
305 m_values[dim] = vector[dim - 1];
306 }
307
308 /**--------------------------------------------------------------------------------------------------
309 Fn: constexpr Vector<t_new_dim, t_new_type> Vector::as(t_new_type extra_fill_value = 0) const
310
311 As the given extra fill value.
312
313 Author: Tyler Parke
314
315 Date: 2017-11-13
316
317 Parameters:
318 extra_fill_value - (Optional) The extra fill value, or value to set dimensions extra that may be
319 created when t_new_dim > t_dim.
320
321 Returns: A Vector&lt;t_new_dim,t_new_type&gt;
322 *-----------------------------------------------------------------------------------------------**/
323 template<class t_new_type>
325 {
327 for (uint01 dim = 0; dim < t_dims; ++dim)
328 vec[dim] = cast<t_new_type>(m_values[dim]);
329 return vec;
330 }
331 template<uint01 t_new_dim, class t_new_type>
333 {
335 constexpr uint01 min = getMin(t_new_dim, t_dims);
336 for (uint01 dim = 0; dim < min; ++dim)
337 vec[dim] = cast<t_new_type>(m_values[dim]);
338 return vec;
339 }
340 template<uint01 t_new_dim, class t_new_type>
341 constexpr Vector<t_new_dim, t_new_type> as(t_new_type extra_fill_value) const
342 {
344 uint01 dim = 0;
345 constexpr uint01 min = getMin(t_new_dim, t_dims);
346 for(; dim < min; dim++)
347 vec[dim] = cast<t_new_type>(m_values[dim]);
348 for(; dim < t_new_dim; dim++)
349 vec[dim] = extra_fill_value;
350 return vec;
351 }
352
353 /**--------------------------------------------------------------------------------------------------
354 Fn: constexpr t_type Vector::dimensionalValue() const
355
356 Used with template arguments MAX or MIN, Gets the dimensional value for the value that is either
357 max or min.
358
359 Author: Tyler Parke
360
361 Date: 2017-11-13
362
363 Returns: The value of the dimension that is either max or min depending on the template t_max_min.
364 *-----------------------------------------------------------------------------------------------**/
365 template<LocationValues t_max_min>
366 [[nodiscard]] constexpr t_type dimensionalValue() const
367 {
368 t_type value = m_values[0];
369 for(uint01 dim = 1; dim < t_dims; ++dim)
370 {
371 if constexpr(t_max_min == MAX)
372 {
373 if(m_values[dim] > value)
374 value = m_values[dim];
375 }
376 else
377 {
378 if(m_values[dim] < value)
379 value = m_values[dim];
380 }
381 }
382 return value;
383 }
384
385 /**--------------------------------------------------------------------------------------------------
386 Fn: constexpr uint01 Vector::dimensionalIndex() const
387
388 Used with template arguments MAX or MIN, Gets the dimensional index for the value that is either
389 max or min.
390
391 Author: Tyler Parke
392
393 Date: 2017-11-13
394
395 Returns: The index of the dimension that is either max or min depending on the template t_max_min.
396 *-----------------------------------------------------------------------------------------------**/
397 template<LocationValues t_max_min>
398 [[nodiscard]] constexpr uint01 dimensionalIndex() const
399 {
400 uint01 dimension = 0;
401 for(uint01 dim = 1; dim < t_dims; ++dim)
402 {
403 if constexpr (t_max_min == MAX)
404 {
405 if (m_values[dim] > m_values[dimension])
406 dimension = dim;
407 }
408 else
409 {
410 if(m_values[dim] < m_values[dimension])
411 dimension = dim;
412 }
413 }
414 return dimension;
415 }
416
417 /**--------------------------------------------------------------------------------------------------
418 Fn: constexpr operator Vector::t_type() const
419
420 For Single dimensional objects, they may also be considered a scaler, thus allow implicit conversion
421 from a vector to a scaler when the dimension of the vector is 1.
422
423 Author: Tyler Parke
424
425 Date: 2017-11-13
426
427 Returns: The result of the operation.
428 *-----------------------------------------------------------------------------------------------**/
429 template<uint01 tdims = t_dims
430 , typename = typename std::enable_if<tdims == 1>::type>
431 constexpr operator t_type&()
432 {
433 return m_values[0];
434 }
435
436 template<uint01 tdims = t_dims
437 , typename = typename std::enable_if<tdims == 1>::type>
438 constexpr operator const t_type &() const
439 {
440 return m_values[0];
441 }
442
443 /**--------------------------------------------------------------------------------------------------
444 Fn: constexpr t_type Vector::magnitudeSquared() const
445
446 Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
447 Calculating the magnitude of vectors is essential for all sorts of problems where forces collide.
448
449 Magnitude is defined as the length of a vector. The notation for absolute value. Thus magnitude
450 is the same as length of vector.
451
452 Author: Tyler Parke
453
454 Date: 2017-11-13
455
456 Returns: The magnitude, or length, of the vector squared.
457 *-----------------------------------------------------------------------------------------------**/
458 [[nodiscard]] constexpr t_type magnitudeSquared() const
459 {
460 t_type magnitude(0);
461 for(uint01 dim = 0; dim < t_dims; ++dim)
462 magnitude += m_values[dim] * m_values[dim];
463 return magnitude;
464 }
465
466 /**--------------------------------------------------------------------------------------------------
467 Fn: constexpr t_type Vector::magnitude() const
468
469 Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
470 Calculating the magnitude of vectors is essential for all sorts of problems where forces collide.
471
472 Magnitude is defined as the length of a vector. The notation for absolute value. Thus magnitude
473 is the same as length of vector.
474
475 Author: Tyler Parke
476
477 Date: 2017-11-13
478
479 Returns: The magnitude, or length, of the vector.
480 *-----------------------------------------------------------------------------------------------**/
481 template<class t_magnitude_type = t_type>
482 constexpr t_magnitude_type magnitude() const
483 {
485 }
486
487
488 /**--------------------------------------------------------------------------------------------------
489 Fn: constexpr Vector<t_dims, t_norm_type> Vector::normalized() const
490
491 Gets the normalized, or unit length representation of this vector.
492
493 Author: Tyler Parke
494
495 Date: 2017-11-13
496
497 Returns: A Vector&lt;t_dims,t_norm_type&gt representing the normalized form of this vector;
498 *-----------------------------------------------------------------------------------------------**/
499 template<class t_norm_type = t_type>
501 {
503 if(magnitude == 0)
504 return value_if_nan;
507 for (uint01 dim = 0; dim < t_dims; dim++)
508 {
510 }
511 return normalized;
512 }
513
514
515 /**--------------------------------------------------------------------------------------------------
516 Fn: constexpr t_type Vector::product() const
517
518 Returns the product, or value of each dimension multiplied together.
519
520 Author: Tyler Parke
521
522 Date: 2017-11-13
523
524 Returns: The value of each dimension multiplied together.
525 *-----------------------------------------------------------------------------------------------**/
526 [[nodiscard]] constexpr t_type product() const
527 {
528 t_type value = m_values[0];
529 for(uint01 dim = 1; dim < t_dims; ++dim)
530 value *= m_values[dim];
531 return value;
532 }
533
534 /**--------------------------------------------------------------------------------------------------
535 Fn: constexpr t_type Vector::sum() const
536
537 Returns the sum, or value of each dimension added together.
538
539 Author: Tyler Parke
540
541 Date: 2017-11-13
542
543 Returns: The value of each dimension added together.
544 *-----------------------------------------------------------------------------------------------**/
545 [[nodiscard]] constexpr t_type sum() const
546 {
547 t_type value = m_values[0];
548 for (uint01 dim = 1; dim < t_dims; ++dim)
549 value += m_values[dim];
550 return value;
551 }
552
553 /**--------------------------------------------------------------------------------------------------
554 Fn: constexpr t_type& Vector::operator[](const uint01 value)
555
556 Accesses the value of a certain dimension.
557
558 Author: Tyler Parke
559
560 Date: 2017-11-13
561
562 Parameters:
563 dimension_index - The dimensional index of the the value we wish to retrieve.
564
565 Returns: The value at the given dimension_index.
566 *-----------------------------------------------------------------------------------------------**/
567
568 constexpr t_type& operator[](uint01 dimension_index)
569 {
570 lib_assert(dimension_index < t_dims, "Dimension requested Exceeded maximum vector dimension");
571 return m_values[dimension_index];
572 }
573
574
575
576 constexpr const t_type& operator[](const uint01 dimension_index) const
577 {
578 lib_assert(dimension_index < t_dims, "Dimension requested Exceeded maximum vector dimension");
579 return m_values[dimension_index];
580 }
581
582 /**--------------------------------------------------------------------------------------------------
583 Fn: constexpr Vector<t_dims, t_type> Vector::operator-() const
584
585 Negation operator.
586
587 Author: Tyler Parke
588
589 Date: 2017-11-13
590
591 Returns: A vector where each dimension is the opposite(-) of the original dimension
592 *-----------------------------------------------------------------------------------------------**/
594 {
596 for(uint01 dim = 0; dim < t_dims; ++dim)
597 value[dim] = -m_values[dim];
598 return value;
599 }
600
601 /**--------------------------------------------------------------------------------------------------
602 Fn: constexpr Vector<t_dims, t_type>& Vector::operator=(const Vector<t_dims, t_type>& vector)
603
604 Assignment operator.
605
606 Author: Tyler Parke
607
608 Date: 2017-11-13
609
610 Parameters:
611 vector - The vector to set this vector to.
612
613 Returns: A reference of this object (Useful for chaining '=' together).
614 *-----------------------------------------------------------------------------------------------**/
615
616 /*constexpr Vector<t_dims, t_type>& operator=(const Vector<t_dims, t_type>& vector)
617 {
618 for (uint01 dim = 0; dim < t_dims; ++dim)
619 m_values[dim] = vector[dim];
620 return *this;
621 }*/
622
623 /**--------------------------------------------------------------------------------------------------
624 Fn: constexpr Vector<t_dims, t_type>& Vector::operator=(const t_type& scaler)
625
626 Assignment operator. Sets all values to the value provided in scaler argument.
627
628 Author: Tyler Parke
629
630 Date: 2017-11-13
631
632 Parameters:
633 scaler - The scaler to set each dimension to.
634
635 Returns: A reference of this object (Useful for chaining '=' together).
636 *-----------------------------------------------------------------------------------------------**/
637
638 constexpr Vector<t_dims, t_type>& operator=(const t_type& scaler)
639 {
640 for (uint01 dim = 0; dim < t_dims; ++dim)
641 m_values[dim] = scaler;
642 return *this;
643 }
644
645 /**--------------------------------------------------------------------------------------------------
646 Fn: static uint01 Vector::NumberOfDimensions()
647
648 Number of dimensions in this vector class.
649
650 Author: Tyler Parke
651
652 Date: 2017-11-13
653
654 Returns: The total number of dimensions in this vector space.
655 *-----------------------------------------------------------------------------------------------**/
656
657 constexpr static uint01 NumberOfDimensions() { return t_dims; }
658
659 /**--------------------------------------------------------------------------------------------------
660 Fn: static t_type Vector::Type()
661
662 Returns the type of this class. Useful for using decltype to instantiate a member of this class in a
663 static environment.
664
665 Author: Tyler Parke
666
667 Date: 2017-11-13
668
669 Returns: The type of this class. Object is inavlid outside of decl.
670 *-----------------------------------------------------------------------------------------------**/
671 constexpr static t_type Type() { return t_type(); }
672
673 protected:
674 /** The values[t dims]. */
675 t_type m_values[t_dims];
676 };
677
678 static_assert(sizeof(Vector<3, fltp08>) == 24, "Bad Vector<3, fltp08> size");
679 static_assert(sizeof(Vector<4, Vector<4, fltp08>>) == 128, "Bad Vector<4, Vector<4, fltp08>> size");
680 /**--------------------------------------------------------------------------------------------------
681 Fn: constexpr bool operator==(const Vector<t_dims, t_type>& vec_a,
682 const Vector<t_dims, t_type>& vec_b)
683
684 Equality operator. Performs the '==' operation on the value in each dimension.
685
686 Author: Tyler Parke
687
688 Date: 2017-11-13
689
690 Parameters:
691 vec_a - The first instance to compare.
692 vec_b - The second instance to compare.
693
694 Returns: True if the value in each vector dimension is considered equivalent.
695 *-----------------------------------------------------------------------------------------------**/
696 template<uint01 t_dims, class t_type>
697 constexpr bool operator==(const Vector<t_dims, t_type>& vec_a, const Vector<t_dims, t_type>& vec_b)
698 {
699 for (uint01 dim = 0; dim < t_dims; ++dim)
700 {
701 if (vec_a[dim] != vec_b[dim])
702 return false;
703 }
704 return true;
705 }
706
707 /**--------------------------------------------------------------------------------------------------
708 Fn: constexpr bool operator!=(const Vector<t_dims, t_type>& vec_a,
709 const Vector<t_dims, t_type>& vec_b)
710
711 Inequality operator. Performs the '!=' operation on the value in each dimension.
712
713 Author: Tyler Parke
714
715 Date: 2017-11-13
716
717 Parameters:
718 vec_a - The first instance to compare.
719 vec_b - The second instance to compare.
720
721 Returns: True if any of the values in each vector dimension is not considered equivalent.
722 *-----------------------------------------------------------------------------------------------**/
723 template<uint01 t_dims, class t_type>
724 constexpr bool operator!=(const Vector<t_dims, t_type>& vec_a, const Vector<t_dims, t_type>& vec_b)
725 {
726 for (uint01 dim = 0; dim < t_dims; ++dim)
727 {
728 if (vec_a[dim] != vec_b[dim])
729 return true;
730 }
731 return false;
732 }
733
734
735 /**--------------------------------------------------------------------------------------------------
736 Fn: constexpr Vector<t_dims, t_type> quantize(const Vector<t_dims, t_type>& a,
737 t_type d = cast<t_type>(1))
738
739 Quantizes.
740
741 Author: Tyler Parke
742
743 Date: 2017-11-13
744
745 Parameters:
746 a - A Vector&lt;t_dims,t_type&gt; to process.
747 d - (Optional) A t_type to process.
748
749 Returns: A Vector&lt;t_dims,t_type&gt;
750 *-----------------------------------------------------------------------------------------------**/
751 template<uint01 t_dims, class t_type>
753 {
754 return (((value.template as<t_dims, fltp08>() / cast<fltp08>(d) + 0.5).template as<t_dims, sint08>()).template as<t_dims, fltp08>() * cast<fltp08>(d)).template as<t_dims, t_type>();
755 }
756
757 /**--------------------------------------------------------------------------------------------------
758 Fn: constexpr Vector<t_dims, t_type> quantize(const Vector<t_dims, t_type>& a,
759 Vector<t_dims, t_type> d = Vector<t_dims, t_type>(1))
760
761 Quantizes.
762
763 Author: Tyler Parke
764
765 Date: 2017-11-13
766
767 Parameters:
768 a - A Vector&lt;t_dims,t_type&gt; to process.
769 d - (Optional) A Vector&lt;t_dims,t_type&gt; to process.
770 parameter3 - The third parameter.
771
772 Returns: A Vector&lt;t_dims,t_type&gt;
773 *-----------------------------------------------------------------------------------------------**/
774 template<uint01 t_dims, class t_type>
776 {
777 return (((value.template as<t_dims, fltp08>()
778 / d.template as<t_dims, fltp08>() + 0.5).template as<t_dims, uint08>()).template as<t_dims, fltp08>()
779 * d.template as<t_dims, fltp08>()).template as<t_dims, t_type>();
780 }
781
782
783 /**--------------------------------------------------------------------------------------------------
784 Struct: Constant<Vector<t_dims,t_type>>
785
786 A constant.
787
788 Author: Tyler Parke
789
790 Date: 2017-11-13
791 *-----------------------------------------------------------------------------------------------**/
792 template<uint01 t_dims, class t_type>
793 struct Constant<Vector<t_dims, t_type>>
794 {
795 /** The NaN value. This is the value that means the vector is 'not valid' or has an unset dimension. */
797 /** The minimum. For each dimension, the value will be the minimum value*/
799 /** The maximum. For each dimension, the value will be the maximum value */
801 };
802
803 template<uint01 t_dims, class t_type>
804 static constexpr bool isNaN(const Vector<t_dims, t_type>& value)
805 {
806 for (uint01 dim = 0; dim < t_dims; ++dim)
807 {
808 if (isNaN(value[dim]))
809 return true;
810 }
811 return false;
812 }
813
814 template < template <uint01 t_dims, class t_type> class base, typename derived>
816 {
817 template<uint01 t_dims, class t_type>
818 static constexpr std::true_type test(const base<t_dims, t_type>*);
819 static constexpr std::false_type test(...);
820 using type = decltype(test(std::declval<derived*>()));
821 };
822
823 template < template <uint01 t_dims, class t_type> class base, typename derived>
825
826 template<class t_type>
827 struct IsVec
828 {
830 };
831 template<class t_type_a, class t_type_b>
833 {
834 static constexpr bool value = false;
835 };
836 template<class t_type_a>
837 struct IsSameType<t_type_a, t_type_a>
838 {
839 static constexpr bool value = true;
840 };
841 template<class t_type_a, class t_type_b>
843 {
844 template<class t = t_type_a, std::enable_if_t<!IsVec<t>::value, int> = 0>
845 static constexpr bool _value()
846 {
847 return false;
848 }
849 template<class t = t_type_a, std::enable_if_t<IsVec<t>::value, int> = 0>
850 static constexpr bool _value()
851 {
852 return IsSameType<decltype(t::Type()), t_type_b>::value;
853 }
854
855 static constexpr bool value = _value();
856 };
857};
858namespace std//Define things to allow use within std libs
859{
860 template <>
861 struct hash<NDEVR::Vector<2, NDEVR::uint04>>
862 {
863 std::size_t operator()(const NDEVR::Vector<2, NDEVR::uint04>& s) const noexcept
864 {
865 std::size_t h = 0, g = 0;
866 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
867 for (size_t i = 0; i < 2 * sizeof(NDEVR::uint04); i++)
868 {
869 h = (h << 4) + bytes[i];
870 g = h & 0xF0000000L;
871 if (g)
872 h ^= g >> 24;
873 h &= ~g;
874 }
875 return h;
876 }
877 };
878 template <>
879 struct hash<NDEVR::Vector<3, NDEVR::uint04>>
880 {
881 std::size_t operator()(const NDEVR::Vector<3, NDEVR::uint04>& s) const noexcept
882 {
883 std::size_t h = 0, g = 0;
884 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
885 for (size_t i = 0; i < 3 * sizeof(NDEVR::uint04); i++)
886 {
887 h = (h << 4) + bytes[i];
888 g = h & 0xF0000000L;
889 if (g)
890 h ^= g >> 24;
891 h &= ~g;
892 }
893 return h;
894 }
895 };
896 template <>
897 struct hash<NDEVR::Vector<3, NDEVR::fltp08>>
898 {
899 std::size_t operator()(const NDEVR::Vector<3, NDEVR::fltp08>& s) const noexcept
900 {
901 std::size_t h = 0, g = 0;
902 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
903 for (size_t i = 0; i < 3 * sizeof(NDEVR::fltp08); i++)
904 {
905 h = (h << 4) + bytes[i];
906 g = h & 0xF0000000L;
907 if (g)
908 h ^= g >> 24;
909 h &= ~g;
910 }
911 return h;
912 }
913 };
914 template <>
915 struct hash<NDEVR::Vector<3, NDEVR::fltp04>>
916 {
917 std::size_t operator()(const NDEVR::Vector<3, NDEVR::fltp04>& s) const noexcept
918 {
919 std::size_t h = 0, g = 0;
920 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
921 for (NDEVR::uint04 i = 0; i < 3 * sizeof(NDEVR::fltp04); i++)
922 {
923 h = (h << 4) + bytes[i];
924 g = h & 0xF0000000L;
925 if (g)
926 h ^= g >> 24;
927 h &= ~g;
928 }
929 return h;
930 }
931 };
932};
933#include "BoolVector.hpp"
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_magnitude_type magnitude() const
Definition Vector.hpp:482
constexpr Vector() noexcept
Definition Vector.hpp:64
constexpr Vector< t_dims, t_type > operator-() const
Definition Vector.hpp:593
constexpr Vector(const Vector< tdims - 1, t_type > &vector, typename std::enable_if< tdims >=2, const t_type & >::type suffix)
Definition Vector.hpp:226
constexpr uint01 dimensionalIndex() const
Definition Vector.hpp:398
constexpr Vector(const t_type &x, const t_type &y, const typename std::enable_if< tdims==3, const t_type & >::type z)
Definition Vector.hpp:145
constexpr Vector(const t_type &prefix_a, const t_type &prefix_b, typename std::enable_if< tdims >=3, const Vector< tdims - 1, t_type > & >::type vector)
Definition Vector.hpp:298
constexpr t_type sum() const
Definition Vector.hpp:545
constexpr t_type product() const
Definition Vector.hpp:526
constexpr Vector(const t_type &x, const t_type &y, const t_type &z, const t_type &w, const t_type &v, const t_type &u, const t_type &t, const t_type &s, typename std::enable_if< tdims==9, const t_type & >::type r)
Definition Vector.hpp:188
constexpr const t_type & operator[](const uint01 dimension_index) const
Definition Vector.hpp:576
static constexpr t_type Type()
Definition Vector.hpp:671
constexpr Vector(const t_type(&vector)[t_dims])
Definition Vector.hpp:205
constexpr Vector(const t_type &x, const t_type &y, const t_type &z, typename std::enable_if< tdims==4, const t_type & >::type w)
Definition Vector.hpp:168
constexpr t_type dimensionalValue() const
Definition Vector.hpp:366
constexpr Vector(const t_type &x, const t_type &y, const t_type &z, const t_type &w, typename std::enable_if< tdims==5, const t_type & >::type v)
Definition Vector.hpp:175
constexpr Vector(const t_type &x, typename std::enable_if< tdims==2, const t_type & >::type y)
Definition Vector.hpp:123
constexpr Vector(const Vector< getMax(tdims - 2, 0), t_type > &vector, const t_type &suffix_a, typename std::enable_if< tdims >=3, const t_type & >::type suffix_b)
Definition Vector.hpp:251
static constexpr uint01 NumberOfDimensions()
Definition Vector.hpp:657
constexpr t_type & operator[](uint01 dimension_index)
Definition Vector.hpp:568
constexpr Vector(const t_type &scaler) noexcept
Definition Vector.hpp:101
constexpr Vector< t_new_dim, t_new_type > as(t_new_type extra_fill_value) const
Definition Vector.hpp:341
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:458
constexpr Vector(const t_type &x, const t_type &y, const t_type &z, const t_type &w, const t_type &v, typename std::enable_if< tdims==6, const t_type & >::type u)
Definition Vector.hpp:182
constexpr Vector(const Vector< t_dims, t_vec_type > &vector) noexcept
Definition Vector.hpp:81
constexpr Vector< t_dims, t_type > & operator=(const t_type &scaler)
Definition Vector.hpp:638
constexpr Vector< t_new_dim, t_new_type > as() const
Definition Vector.hpp:332
t_type m_values[t_dims]
Definition Vector.hpp:675
constexpr Vector< t_dims, t_norm_type > normalized(Vector< t_dims, t_norm_type > value_if_nan=Constant< Vector< t_dims, t_norm_type > >::NaN) const
Definition Vector.hpp:500
constexpr Vector(const t_type &prefix, typename std::enable_if< tdims >=2, const Vector< t_dims - 1, t_type > & >::type vector)
Definition Vector.hpp:275
constexpr Vector< t_dims, t_new_type > as() const
Definition Vector.hpp:324
Definition ACIColor.h:37
bool operator==(const char(&v1)[t_size], const String &v2)
Definition String.h:437
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator.
Definition BaseFunctions.hpp:116
@ MAX
Definition BaseValues.hpp:227
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Definition Vector.hpp:724
constexpr Vector< t_dims, Angle< t_angle_type > > quantize(const Vector< t_dims, Angle< t_angle_type > > &value, Angle< t_angle_type > d=Angle< t_angle_type >(DEGREES, 1.0))
Definition AngleFunctions.h:955
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1309
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
typename is_base_of_template_impl< base, derived >::type is_base_of_template
Definition Vector.hpp:824
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ Z
Definition BaseValues.hpp:204
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67
Definition File.h:213
Definition BaseValues.hpp:272
static const t_type Min
Definition BaseValues.hpp:276
static const t_type Max
Definition BaseValues.hpp:278
static const t_type NaN
Definition BaseValues.hpp:274
Definition Vector.hpp:833
static constexpr bool value
Definition Vector.hpp:834
Definition Vector.hpp:828
static constexpr bool value
Definition Vector.hpp:829
Definition Vector.hpp:843
static constexpr bool value
Definition Vector.hpp:855
static constexpr bool _value()
Definition Vector.hpp:845
Definition Vector.hpp:816
decltype(test(std::declval< derived * >())) type
Definition Vector.hpp:820
static constexpr std::true_type test(const base< t_dims, t_type > *)
static constexpr std::false_type test(...)
std::size_t operator()(const NDEVR::Vector< 2, NDEVR::uint04 > &s) const noexcept
Definition Vector.hpp:863
std::size_t operator()(const NDEVR::Vector< 3, NDEVR::fltp04 > &s) const noexcept
Definition Vector.hpp:917
std::size_t operator()(const NDEVR::Vector< 3, NDEVR::fltp08 > &s) const noexcept
Definition Vector.hpp:899
std::size_t operator()(const NDEVR::Vector< 3, NDEVR::uint04 > &s) const noexcept
Definition Vector.hpp:881