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