API Documentation
Loading...
Searching...
No Matches
Vertex.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: Vertex
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Vector.h>
34
35namespace NDEVR
36{
37 /**--------------------------------------------------------------------------------------------------
38 Class: Vertex
39
40 \brief A vertex or point. A specific type of Vector used primarily for spacial location information.
41
42 Author: Tyler Parke
43
44 Date: 2017-11-19
45 **/
46 template<uint01 t_dims, class t_type, class t_vector_type = Vector<t_dims, t_type>>
47 class Vertex : public t_vector_type
48 {
49 public:
50 constexpr Vertex()
51 : t_vector_type()
52 {}
53 constexpr explicit Vertex(const t_type& scaler)
54 : t_vector_type(scaler)
55 {}
56 constexpr Vertex(const t_vector_type& vector)
57 : t_vector_type(vector)
58 {}
60 : t_vector_type(vector)
61 {}
62 constexpr Vertex(const t_type x, const t_type y)
63 : t_vector_type(x, y)
64 {}
65 constexpr Vertex(t_type x, t_type y, t_type z)
66 : t_vector_type(x, y, z)
67 {}
68 constexpr Vertex(const t_type x, const t_type y, const t_type z, const t_type w)
69 : t_vector_type(x, y, z, w)
70 {}
71 constexpr explicit Vertex(const t_type(&vector)[t_dims])
72 : t_vector_type(vector)
73 {}
74 constexpr Vertex(const Vector<getMax(t_dims - 1, 0), t_type>& vector, const t_type postfix)
75 : t_vector_type(vector, postfix)
76 {}
77 constexpr Vertex(const Vector<getMax(t_dims - 2, 0), t_type>& vector, const t_type postfix_a, const t_type postfix_b)
78 : t_vector_type(vector, postfix_a, postfix_b)
79 {}
80 constexpr Vertex(const t_type prefix, const Vector<t_dims - 1, t_type>& vector)
81 : t_vector_type(prefix, vector)
82 {}
83
84
85 /**--------------------------------------------------------------------------------------------------
86 As the given extra fill value.
87
88 Author: Tyler Parke
89
90 Date: 2017-11-19
91
92 Parameters:
93 extra_fill_value - (Optional) The extra fill value.
94
95 \returns A Vertex&lt;t_new_dim,t_new_type,t_new_vector&gt;
96 **/
97 template<uint01 t_new_dim, class t_new_type, class t_new_vector = Vector<t_new_dim, t_new_type>>
102 template<class t_new_type, class t_new_vector = Vector<t_dims, t_new_type>>
104 {
106 }
107 template<uint01 t_new_dim, class t_new_type, class t_new_vector = Vector<t_new_dim, t_new_type>>
108 constexpr Vertex<t_new_dim, t_new_type, t_new_vector> as(t_new_type extra_fill_value) const
109 {
110 return Vertex<t_new_dim, t_new_type, t_new_vector>(t_vector_type::template as<t_new_dim, t_new_type>(extra_fill_value));
111 }
112
113 /**--------------------------------------------------------------------------------------------------
114
115 Scales.
116
117 Author: Tyler Parke
118
119 Date: 2017-11-19
120
121 Parameters:
122 scale - The scale.
123 center - The center.
124
125 \returns A Vertex.
126 **/
127
128 constexpr Vertex scale(const t_vector_type& scale, const Vertex<t_dims, t_type>& center) const
129 {
130 return ((*this - center) * scale) + center;
131 }
132
133 /**--------------------------------------------------------------------------------------------------
134 Scales.
135
136 Author: Tyler Parke
137
138 Date: 2017-11-19
139
140 Parameters:
141 scale - The scale.
142 center - The center.
143
144 \returns A Vertex.
145 **/
146
147 constexpr Vertex scale(const t_type scale, const Vertex<t_dims, t_type>& center) const
148 {
149 return ((*this - center) * scale) + center;
150 }
151
152 /**--------------------------------------------------------------------------------------------------
153 Gets the center.
154
155 Author: Tyler Parke
156
157 Date: 2017-11-19
158
159 \returns A reference to a const Vertex.
160 **/
161
162 constexpr const Vertex& center() const
163 {
164 return *this;
165 }
166
167 /**--------------------------------------------------------------------------------------------------
168 Assignment operator.
169
170 Author: Tyler Parke
171
172 Date: 2017-11-19
173
174 Parameters:
175 scaler - The scaler.
176
177 \returns A shallow copy of this object.
178 **/
179
180 constexpr Vertex<t_dims, t_type, t_vector_type>& operator=(const t_type& scaler)
181 {
182 t_vector_type::operator=(scaler);
183 return *this;
184 }
185
186 /**--------------------------------------------------------------------------------------------------
187 Assignment operator.
188
189 Author: Tyler Parke
190
191 Date: 2017-11-19
192
193 Parameters:
194 vector - The vector.
195
196 \returns A shallow copy of this object.
197 **/
198
199 constexpr Vertex<t_dims, t_type, t_vector_type>& operator=(const t_vector_type& vector)
200 {
201 t_vector_type::operator=(vector);
202 return *this;
203 }
205 {
206 t_vector_type::operator=(vector);
207 return *this;
208 }
209 };
210
211 /**--------------------------------------------------------------------------------------------------
212
213 Finds the max of the given arguments.
214
215 Author: Tyler Parke
216
217 Date: 2017-11-13
218
219 Parameters:
220 v1 - The first Vector&lt;t_dims,t_type&gt;
221 v2 - The second Vector&lt;t_dims,t_type&gt;
222
223 \returns The calculated maximum.
224 **/
225 template<uint01 t_dims, class t_type, class t_base>
227 {
229 for (uint01 dim = 0; dim < t_dims; dim++)
230 {
231 vec[dim] = getMax(v1[dim], v2[dim]);
232 }
233 return vec;
234 }
235
236 /**--------------------------------------------------------------------------------------------------
237
238 Finds the min of the given arguments.
239
240 Author: Tyler Parke
241
242 Date: 2017-11-13
243
244 Parameters:
245 v1 - The first Vector&lt;t_dims,t_type&gt;
246 v2 - The second Vector&lt;t_dims,t_type&gt;
247
248 \returns The calculated minimum.
249 **/
250 template<uint01 t_dims, class t_type, class t_base>
252 {
254 for (uint01 dim = 0; dim < t_dims; dim++)
255 {
256 vec[dim] = getMin(v1[dim], v2[dim]);
257 }
258 return vec;
259 }
260
261 /**--------------------------------------------------------------------------------------------------
262 Struct: Constant<Vertex<t_dims,t_type,t_vector_type>>
263
264 A constant.
265
266 Author: Tyler Parke
267
268 Date: 2017-11-19
269 **/
270 template<uint01 t_dims, class t_type, class t_vector_type>
271 struct Constant<Vertex<t_dims, t_type, t_vector_type>>
272 {
273 constexpr const static Vertex<t_dims, t_type, t_vector_type> Invalid{ Constant<t_type>::Invalid };
274 constexpr const static Vertex<t_dims, t_type, t_vector_type> Min{ Constant<t_type>::Min };
275 constexpr const static Vertex<t_dims, t_type, t_vector_type> Max{ Constant<t_type>::Max };
276 };
277
278 /**--------------------------------------------------------------------------------------------------
279 Query if 'value' is Invalid.
280
281 Author: Tyler Parke
282
283 Date: 2017-11-19
284
285 Typeparams:
286 t_dims - Type of the dims.
287 t_type - Type of the type.
288 t_vector_type - Type of the vector type.
289 Parameters:
290 value - The value.
291
292 \returns True if nan, false if not.
293 **/
294
295 template<uint01 t_dims, class t_type, class t_vector_type>
296 static constexpr bool IsInvalid(const Vertex<t_dims, t_type, t_vector_type>& value)
297 {
298 for (uint01 dim = 0; dim < t_dims; ++dim)
299 {
300 if (IsInvalid(value[dim]))
301 return true;
302 }
303 return false;
304 }
305
306 /**--------------------------------------------------------------------------------------------------
307 Class: Normal
308
309 A vertex.
310
311 Author: Tyler Parke
312
313 Date: 2017-11-19
314 **/
315 template<uint01 t_dims, class t_type, class t_vector_type = Vector<t_dims, t_type>>
316 class Ray : public t_vector_type
317 {
318 public:
319 constexpr Ray()
320 : t_vector_type()
321 {}
322 constexpr explicit Ray(const t_type& scaler)
323 : t_vector_type(scaler)
324 {}
325 constexpr Ray(const t_vector_type& vector)
326 : t_vector_type(vector)
327 {}
329 : t_vector_type(vector)
330 {}
331 constexpr Ray(const t_type x, const t_type y)
332 : t_vector_type(x, y)
333 {}
334 constexpr Ray(t_type x, t_type y, t_type z)
335 : t_vector_type(x, y, z)
336 {}
337 constexpr Ray(const t_type x, const t_type y, const t_type z, const t_type w)
338 : t_vector_type(x, y, z, w)
339 {}
340 constexpr explicit Ray(const t_type(&vector)[t_dims])
341 : t_vector_type(vector)
342 {}
343 constexpr Ray(const Vector<getMax(t_dims - 1, 0), t_type>& vector, const t_type postfix)
344 : t_vector_type(vector, postfix)
345 {}
346 constexpr Ray(const Vector<getMax(t_dims - 2, 0), t_type>& vector, const t_type postfix_a, const t_type postfix_b)
347 : t_vector_type(vector, postfix_a, postfix_b)
348 {}
349 constexpr Ray(const t_type prefix, const Vector<t_dims - 1, t_type>& vector)
350 : t_vector_type(prefix, vector)
351 {}
352
353
354 /**--------------------------------------------------------------------------------------------------
355 As the given extra fill value.
356
357 Author: Tyler Parke
358
359 Date: 2017-11-19
360
361 Parameters:
362 extra_fill_value - (Optional) The extra fill value.
363
364 \returns A Vertex&lt;t_new_dim,t_new_type,t_new_vector&gt;
365 **/
366 template<uint01 t_new_dim, class t_new_type, class t_new_vector = Vector<t_new_dim, t_new_type>>
367 constexpr Ray<t_new_dim, t_new_type, t_new_vector> as(t_new_type extra_fill_value = 0) const
368 {
369 return Ray<t_new_dim, t_new_type, t_new_vector>(t_vector_type::template as<t_new_dim, t_new_type>(extra_fill_value));
370 }
371 template<class t_new_type, class t_new_vector = Vector<t_dims, t_new_type>>
373 {
374 return Ray<t_dims, t_new_type, t_new_vector>(t_vector_type::template as<t_new_type>());
375 }
376
377 /**--------------------------------------------------------------------------------------------------
378
379 Scales.
380
381 Author: Tyler Parke
382
383 Date: 2017-11-19
384
385 Parameters:
386 scale - The scale.
387 center - The center.
388
389 \returns A Vertex.
390 **/
391
392 constexpr Ray scale(const t_vector_type& scale) const
393 {
394 return (*this * scale);
395 }
396
397 /**--------------------------------------------------------------------------------------------------
398 Scales.
399
400 Author: Tyler Parke
401
402 Date: 2017-11-19
403
404 Parameters:
405 scale - The scale.
406 center - The center.
407
408 \returns A Vertex.
409 **/
410
411 constexpr Ray scale(const t_type scale) const
412 {
413 return (*this * scale);
414 }
415
416
417 /**--------------------------------------------------------------------------------------------------
418 Assignment operator.
419
420 Author: Tyler Parke
421
422 Date: 2017-11-19
423
424 Parameters:
425 scaler - The scaler.
426
427 \returns A copy of this object.
428 **/
429
430 constexpr Ray<t_dims, t_type, t_vector_type>& operator=(const t_type& scaler)
431 {
432 t_vector_type::operator=(scaler);
433 return *this;
434 }
435
436 /**--------------------------------------------------------------------------------------------------
437 Assignment operator.
438
439 Author: Tyler Parke
440
441 Date: 2017-11-19
442
443 Parameters:
444 vector - The vector.
445
446 \returns A copy of this object.
447 **/
448
449 constexpr Ray<t_dims, t_type, t_vector_type>& operator=(const t_vector_type& vector)
450 {
451 t_vector_type::operator=(vector);
452 return *this;
453 }
455 {
456 t_vector_type::operator=(vector);
457 return *this;
458 }
459 };
460
461 /**--------------------------------------------------------------------------------------------------
462
463 Finds the max of the given arguments.
464
465 Author: Tyler Parke
466
467 Date: 2017-11-13
468
469 Parameters:
470 v1 - The first Vector&lt;t_dims,t_type&gt;
471 v2 - The second Vector&lt;t_dims,t_type&gt;
472
473 \returns The calculated maximum.
474 **/
475 template<uint01 t_dims, class t_type, class t_base>
477 {
479 for (uint01 dim = 0; dim < t_dims; dim++)
480 {
481 vec[dim] = getMax(abs(v1[dim]), abs(v2[dim]));
482 }
483 return vec;
484 }
485
486 /**--------------------------------------------------------------------------------------------------
487
488 Finds the min of the given arguments.
489
490 Author: Tyler Parke
491
492 Date: 2017-11-13
493
494 Parameters:
495 v1 - The first Vector&lt;t_dims,t_type&gt;
496 v2 - The second Vector&lt;t_dims,t_type&gt;
497
498 \returns The calculated minimum.
499 **/
500 template<uint01 t_dims, class t_type, class t_base>
502 {
504 for (uint01 dim = 0; dim < t_dims; dim++)
505 {
506 vec[dim] = getMin(abs(v1[dim]), abs(v2[dim]));
507 }
508 return vec;
509 }
510
511 /**--------------------------------------------------------------------------------------------------
512 Struct: Constant<Vertex<t_dims,t_type,t_vector_type>>
513
514 A constant.
515
516 Author: Tyler Parke
517
518 Date: 2017-11-19
519 **/
520 template<uint01 t_dims, class t_type, class t_vector_type>
521 struct Constant<Ray<t_dims, t_type, t_vector_type>>
522 {
523 constexpr const static Ray<t_dims, t_type, t_vector_type> Invalid{ Constant<t_vector_type>::Invalid };
524 constexpr const static Ray<t_dims, t_type, t_vector_type> Min{ 0 };
525 constexpr const static Ray<t_dims, t_type, t_vector_type> Max{ Constant<t_vector_type>::Max };
526 };
527
528 /**--------------------------------------------------------------------------------------------------
529 Query if 'value' is Invalid.
530
531 Author: Tyler Parke
532
533 Date: 2017-11-19
534
535 Typeparams:
536 t_dims - Type of the dims.
537 t_type - Type of the type.
538 t_vector_type - Type of the vector type.
539 Parameters:
540 value - The value.
541
542 \returns True if nan, false if not.
543 **/
544
545 template<uint01 t_dims, class t_type, class t_vector_type>
546 static constexpr bool IsInvalid(const Ray<t_dims, t_type, t_vector_type>& value)
547 {
548 for (uint01 dim = 0; dim < t_dims; ++dim)
549 {
550 if (IsInvalid(value[dim]))
551 return true;
552 }
553 return false;
554 }
555}
556namespace std//Define things to allow use within std libs
557{
558 template <>
559 struct hash<NDEVR::Vertex<3, NDEVR::fltp08>>
560 {
561 std::size_t operator()(const NDEVR::Vertex<3, NDEVR::fltp08>& s) const noexcept
562 {
563 std::size_t h = 0, g = 0;
564 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
565 for (size_t i = 0; i < 3 * sizeof(NDEVR::fltp08); i++)
566 {
567 h = (h << 4) + bytes[i];
568 g = h & 0xF0000000L;
569 if (g)
570 h ^= g >> 24;
571 h &= ~g;
572 }
573 return h;
574 }
575 };
576 template <>
577 struct hash<NDEVR::Vertex<3, NDEVR::fltp04>>
578 {
579 std::size_t operator()(const NDEVR::Vertex<3, NDEVR::fltp04>& s) const noexcept
580 {
581 std::size_t h = 0, g = 0;
582 const NDEVR::uint01* bytes = reinterpret_cast<const NDEVR::uint01*>(&s[0]);
583 for (size_t i = 0; i < 3 * sizeof(NDEVR::fltp04); i++)
584 {
585 h = (h << 4) + bytes[i];
586 g = h & 0xF0000000L;
587 if (g)
588 h ^= g >> 24;
589 h &= ~g;
590 }
591 return h;
592 }
593 };
594};
Definition Vertex.hpp:317
constexpr Ray(const t_type(&vector)[t_dims])
Definition Vertex.hpp:340
constexpr Ray(t_type x, t_type y, t_type z)
Definition Vertex.hpp:334
constexpr Ray(const Vector< getMax(t_dims - 1, 0), t_type > &vector, const t_type postfix)
Definition Vertex.hpp:343
constexpr Ray< t_dims, t_type, t_vector_type > & operator=(const t_vector_type &vector)
Definition Vertex.hpp:449
constexpr Ray(const t_type &scaler)
Definition Vertex.hpp:322
constexpr Ray(const Ray< t_dims, t_type, t_vector_type > &vector)
Definition Vertex.hpp:328
constexpr Ray(const t_type x, const t_type y, const t_type z, const t_type w)
Definition Vertex.hpp:337
constexpr Ray(const t_vector_type &vector)
Definition Vertex.hpp:325
constexpr Ray scale(const t_vector_type &scale) const
Definition Vertex.hpp:392
constexpr Ray< t_dims, t_type, t_vector_type > & operator=(const Ray< t_dims, t_type, t_vector_type > &vector)
Definition Vertex.hpp:454
constexpr Ray scale(const t_type scale) const
Definition Vertex.hpp:411
constexpr Ray< t_new_dim, t_new_type, t_new_vector > as(t_new_type extra_fill_value=0) const
Definition Vertex.hpp:367
constexpr Ray(const Vector< getMax(t_dims - 2, 0), t_type > &vector, const t_type postfix_a, const t_type postfix_b)
Definition Vertex.hpp:346
constexpr Ray(const t_type x, const t_type y)
Definition Vertex.hpp:331
constexpr Ray< t_dims, t_new_type, t_new_vector > as() const
Definition Vertex.hpp:372
constexpr Ray< t_dims, t_type, t_vector_type > & operator=(const t_type &scaler)
Definition Vertex.hpp:430
constexpr Ray()
Definition Vertex.hpp:319
constexpr Ray(const t_type prefix, const Vector< t_dims - 1, t_type > &vector)
Definition Vertex.hpp:349
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
constexpr Vertex(const t_type(&vector)[t_dims])
Definition Vertex.hpp:71
constexpr Vertex< t_new_dim, t_new_type, t_new_vector > as() const
Definition Vertex.hpp:98
constexpr Vertex scale(const t_vector_type &scale, const Vertex< t_dims, t_type > &center) const
Definition Vertex.hpp:128
constexpr Vertex(const t_type &scaler)
Definition Vertex.hpp:53
constexpr Vertex(const t_type x, const t_type y)
Definition Vertex.hpp:62
constexpr Vertex< t_new_dim, t_new_type, t_new_vector > as(t_new_type extra_fill_value) const
Definition Vertex.hpp:108
constexpr Vertex scale(const t_type scale, const Vertex< t_dims, t_type > &center) const
Definition Vertex.hpp:147
constexpr const Vertex & center() const
Definition Vertex.hpp:162
constexpr Vertex< t_dims, t_new_type, t_new_vector > as() const
Definition Vertex.hpp:103
constexpr Vertex(const Vector< getMax(t_dims - 1, 0), t_type > &vector, const t_type postfix)
Definition Vertex.hpp:74
constexpr Vertex(const t_type prefix, const Vector< t_dims - 1, t_type > &vector)
Definition Vertex.hpp:80
constexpr Vertex< t_dims, t_type, t_vector_type > & operator=(const t_vector_type &vector)
Definition Vertex.hpp:199
constexpr Vertex< t_dims, t_type, t_vector_type > & operator=(const Vertex< t_dims, t_type, t_vector_type > &vector)
Definition Vertex.hpp:204
constexpr Vertex()
Definition Vertex.hpp:50
constexpr Vertex< t_dims, t_type, t_vector_type > & operator=(const t_type &scaler)
Definition Vertex.hpp:180
constexpr Vertex(t_type x, t_type y, t_type z)
Definition Vertex.hpp:65
constexpr Vertex(const Vertex< t_dims, t_type, t_vector_type > &vector)
Definition Vertex.hpp:59
constexpr Vertex(const t_vector_type &vector)
Definition Vertex.hpp:56
constexpr Vertex(const Vector< getMax(t_dims - 2, 0), t_type > &vector, const t_type postfix_a, const t_type postfix_b)
Definition Vertex.hpp:77
constexpr Vertex(const t_type x, const t_type y, const t_type z, const t_type w)
Definition Vertex.hpp:68
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
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
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
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
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
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