API Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Bounds.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: Bounds
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
35#include <NDEVR/LineSegment.h>
36#include <NDEVR/Triangle.h>
37#include <NDEVR/RadialObject.h>
38namespace NDEVR
39{
40
41 /**--------------------------------------------------------------------------------------------------
42 Class: Bounds
43
44 \brief A specification of upper and lower bounds in N-dimensions.
45
46 Author: Tyler Parke
47
48 Date: 2017-11-17
49 --------------------------------------------------------------------------------------------------**/
50 template<uint01 t_dims, class t_type, class t_vertex = Vertex<t_dims, t_type>>
51 class Bounds : public Vector<2, t_vertex>
52 {
53 public:
54 constexpr Bounds()
55 {}
56
57 /**
58 \brief Given the vector, creates bounds of size 0 where max and min are both equal to the vertex
59 \param[in] vertex The vertex around which a bounds of size 0 will be made.
60 **/
61 constexpr Bounds(const t_vertex& vertex)
62 : Vector<2, t_vertex>(vertex, vertex)
63 {}
64
65 /**
66
67 \brief Given the center, creates bounds of size where max and min are both equal to the vertex + size and
68 - size respectively.
69 \param[in] center - The center of the bounds.
70 \param[in] size - The size of the bounds.
71 **/
72 constexpr Bounds(const t_vertex& center, t_type size)
73 : Vector<2, t_vertex>(center - size, center + size)
74 {}
75 constexpr Bounds(const t_vertex& min, const t_vertex& max)
76 : Vector<2, t_vertex>(min, max)
77 {}
78 constexpr Bounds(const t_type& min_scaler, const t_type& max_scaler)
79 : Vector<2, t_vertex>(t_vertex(min_scaler), t_vertex(max_scaler))
80 {}
81
82 constexpr Bounds(const Vector<2, t_vertex>& bounds)
83 : Vector<2, t_vertex>(bounds)
84 {}
85
86 constexpr Bounds(const Bounds& bounds_a, const Bounds& bounds_b)
87 : Vector<2, t_vertex>(getMin(bounds_a[MIN], bounds_b[MIN]), getMax(bounds_a[MAX], bounds_b[MAX]))
88 {}
89
90 constexpr Bounds(const Bounds& bounds, const t_vertex& vector)
91 : Vector<2, t_vertex>(getMin(bounds[MIN], vector), getMax(bounds[MAX], vector))
92 {}
94 : Vector<2, t_vertex>(getMin(line.vertex(A), line.vertex(B)), getMax(line.vertex(A), line.vertex(B)))
95 {}
96
98 : Vector<2, t_vertex>(
99 getMin(tri.vertex(A), tri.vertex(B), tri.vertex(C))
100 , getMax(tri.vertex(A), tri.vertex(B), tri.vertex(C)))
101 {}
102
104 : Vector<2, t_vertex>(radial.center() - radial.radius(), radial.center() + radial.radius())
105 {}
106
107 /**
108 \brief The side lengths of these bounds. For each dimension, the span is max - min.
109 \returns A t_vertex defining the span of the range in each dimension.
110 **/
115
116 /**
117 \brief Returns the center of the bounds.
118 \returns A t_vertex representing the center.
119 **/
120 constexpr t_vertex center() const
121 {
123 }
124
125 /**
126 \brief Returns the volume of the bounds. This is defined as length in 1 dimension, area in 2 dimensions.
127 \returns A t_type giving the volume of the bounds.
128 **/
129
130 constexpr t_type volume() const
131 {
132 return span().product();
133 }
134 /**
135 \brief The surface area of the shape. This is defined as the area between internal space and non-internal space.
136 \returns A t_type representing the area of the surface created by the bounds.
137 **/
138 constexpr t_type surfaceArea() const
139 {
140 t_type area = 0;
141 t_vertex side_lengths = span();
142 for (uint01 dim_a = 0; dim_a < t_dims; dim_a++)
143 {
144 for (uint01 dim_b = 0; dim_b < t_dims; dim_b++)
145 {
146 if (dim_b != dim_a)
147 {
148 area += side_lengths[dim_a] * side_lengths[dim_b];
149 }
150 }
151 }
152 return area;
153 }
154
155 /**
156 \brief Expands the given expansion scaler. such that max and min are both expanded outward from the center by
157 the given expansion scaler
158 \param[in] expansion_scaler - The expansion scaler.
159 **/
160
161 constexpr void expand(const t_type& expansion_scaler)
162 {
163 (*this)[MIN] -= expansion_scaler;
164 (*this)[MAX] += expansion_scaler;
165 }
166
167 /**
168 \brief Expands the given expansion scaler. such that max and min are both expanded outward from the center by
169 the given expansion vector. That is that each dimension may be scaled out differently.
170 \param[in] expansion_vector - The expansion vector.
171 **/
172
173 constexpr void expand(const t_vertex& expansion_vector)
174 {
175 Vector<2, t_vertex>::m_values[MIN] -= expansion_vector;
176 Vector<2, t_vertex>::m_values[MAX] += expansion_vector;
177 }
178
179 /**
180 \brief Scales this geometry about a center point
181 \param[in] scale - The scale.
182 \param[in] center - The center.
183 \returns A Bounds&lt;t_dims,t_type&gt;
184 **/
186 {
187 t_vertex scale_a = Vector<2, t_vertex>::m_values[MIN].scale(scale, center);
188 t_vertex scale_b = Vector<2, t_vertex>::m_values[MAX].scale(scale, center);
189 return Bounds<t_dims, t_type>(getMin(scale_a, scale_b), getMax(scale_a, scale_b));
190 }
191 constexpr Bounds<t_dims, t_type> scale(const Vector<t_dims, t_type>& center_scale) const
192 {
193 return scale(center_scale, center());
194 }
195
196 constexpr Bounds<t_dims, t_type> scale(const t_type& scale, const Vector<t_dims, t_type>& center) const
197 {
198 t_vertex scale_a = Vector<2, t_vertex>::m_values[MIN].scale(scale, center);
199 t_vertex scale_b = Vector<2, t_vertex>::m_values[MAX].scale(scale, center);
200 return Bounds<t_dims, t_type>(getMin(scale_a, scale_b), getMax(scale_a, scale_b));
201 }
202
203 constexpr Bounds<t_dims, t_type> scale(const t_type& center_scale) const
204 {
205 auto point = center();
206 t_vertex scale_a = Vector<2, t_vertex>::m_values[MIN].scale(center_scale, point);
207 t_vertex scale_b = Vector<2, t_vertex>::m_values[MAX].scale(center_scale, point);
208 if(center_scale > 0)
209 return Bounds<t_dims, t_type>(scale_a, scale_b);
210 else
211 return Bounds<t_dims, t_type>(scale_b, scale_a);
212 }
213
214 /**
215 \brief Casts this object into an object of different dimension or precision.
216 \param[in] extra_fill_value (Optional) The extra fill value, or value to set dimensions extra that may be
217 created when t_new_dim > t_dim.
218 **/
219 template<uint01 t_new_dims, class t_new_type, class t_new_vertex = Vertex<t_new_dims, t_new_type>>
220 constexpr Bounds<t_new_dims, t_new_type, t_new_vertex> as(t_new_type extra_fill_value = t_new_type(0)) const
221 {
223 t_new_vertex((*this)[MIN].template as<t_new_dims, t_new_type>(extra_fill_value))
224 , t_new_vertex((*this)[MAX].template as<t_new_dims, t_new_type>(extra_fill_value)));
225 }
226
227 /**
228 \brief Query if this object contains the given value.
229 t_allow_bounds - whether or not to allow boundary cases to be considered valid.
230
231 \param[in] value The const t_vertex&amp; to test for containment.
232
233 \returns True if the object is in the bounds, false if not.
234 **/
235 template<bool t_allow_bounds = true, uint01 tdims = t_dims
236 , typename = typename std::enable_if<tdims == 1>::type>
237 constexpr bool contains(const t_type & value) const
238 {
239 if (t_allow_bounds)
240 {
241 return !(!(value >= (*this)[MIN][0]) || !(value <= (*this)[MAX][0]));
242 }
243 else
244 {
245 return !(!(value > (*this)[MIN][0]) || !(value < (*this)[MAX][0]));
246 }
247 }
248
249 /**
250 \brief Query if this object contains the given vector.
251 t_allow_bounds - whether or not to allow boundary cases to be considered valid.
252
253 \param[in] vector - The const t_vertex&amp; to test for containment.
254
255 \returns True if the object is in the bounds, false if not.
256 **/
257 template<bool t_allow_bounds = true>
258 constexpr bool contains(const t_vertex& vector) const
259 {
260 if (t_allow_bounds)
261 {
262 for (uint01 dim = 0; dim < t_dims; ++dim)
263 {
264 if (!(vector[dim] >= (*this)[MIN][dim]) || !(vector[dim] <= (*this)[MAX][dim]))
265 return false;
266 }
267 }
268 else
269 {
270 for (uint01 dim = 0; dim < t_dims; ++dim)
271 {
272 if (!(vector[dim] > (*this)[MIN][dim]) || !(vector[dim] < (*this)[MAX][dim]))
273 return false;
274 }
275 }
276 return true;
277 }
278
279 /**
280 \brief Query if this object contains the given bounds.
281
282 Author: Tyler Parke
283
284 Date: 2017-11-17
285
286 Parameters:
287 t_allow_bounds - whether or not to allow boundary cases to be considered valid.
288
289 \param[in] bounds - The bounds to check if it is inside object.
290
291 \returns True if it succeeds, false if it fails.
292 **/
293 template<bool t_allow_bounds = true>
294 constexpr bool contains(const Bounds& bounds) const
295 {
296 if (t_allow_bounds)
297 {
298 for (uint01 dim = 0; dim < t_dims; ++dim)
299 {
300 if (!(bounds[MIN][dim] >= (*this)[MIN][dim]))
301 return false;
302 if (!(bounds[MAX][dim] <= (*this)[MAX][dim]))
303 return false;
304 }
305 }
306 else
307 {
308 for (uint01 dim = 0; dim < t_dims; ++dim)
309 {
310 if (!(bounds[MIN][dim] >(*this)[MIN][dim]))
311 return false;
312 if (!(bounds[MAX][dim] < (*this)[MAX][dim]))
313 return false;
314 }
315 }
316 return true;
317 }
318
319 /**
320 Fully contains.
321
322 \brief Author: Tyler Parke
323
324 Date: 2017-11-17
325
326 Parameters:
327 \param[in] line - The vector.
328
329 \returns True if it succeeds, false if it fails.
330 **/
331 template<bool t_allow_bounds = true>
332 constexpr bool contains(const LineSegment<t_dims, t_type, t_vertex>& line) const
333 {
334 if (t_allow_bounds)
335 {
336 for (uint01 dim = 0; dim < t_dims; ++dim)
337 {
338 if (!(line.vertex(A)[dim] >= (*this)[MIN][dim] && line.vertex(B)[dim] >= (*this)[MIN][dim]))
339 return false;
340 if (!(line.vertex(A)[dim] <= (*this)[MAX][dim] && line.vertex(B)[dim] <= (*this)[MAX][dim]))
341 return false;
342 }
343 }
344 else
345 {
346 for (uint01 dim = 0; dim < t_dims; ++dim)
347 {
348 if (!(line.vertex(A)[dim] > (*this)[MIN][dim] && line.vertex(B)[dim] > (*this)[MIN][dim]))
349 return false;
350 if (!(line.vertex(A)[dim] < (*this)[MAX][dim] && line.vertex(B)[dim] < (*this)[MAX][dim]))
351 return false;
352 }
353 }
354 return true;
355 }
356
357
358 /**
359 \brief Fully contains.
360
361 Author: Tyler Parke
362
363 Date: 2017-11-17
364
365 Parameters:
366 \param[in] tri - The triangle.
367
368 \returns True if it succeeds, false if it fails.
369 **/
370 template<bool t_allow_bounds = true>
371 constexpr bool contains(const Triangle<t_dims, t_type, t_vertex>& tri) const
372 {
373 for (uint01 tri_index = A; tri_index <= C; tri_index++)
374 if (!contains<t_allow_bounds>(tri.vertex(tri_index)))
375 return false;
376 return true;
377 }
378 /**
379 \brief Adds to the bounds such that the new bounds fully encompasses the argument.
380
381 Author: Tyler Parke.
382
383 Date:
384 2017 - 11-17.
385
386 Parameters:
387 \param[in] vector - The vector.
388 **/
389
390 constexpr void addToBounds(const t_vertex& vector)
391 {
392 for (uint01 dim = 0; dim < t_dims; ++dim)
393 {
394 if ((*this)[MAX][dim] < vector[dim])
395 (*this)[MAX][dim] = vector[dim];
396 if ((*this)[MIN][dim] > vector[dim])
397 (*this)[MIN][dim] = vector[dim];
398 }
399 }
400 template<uint01 tdims = t_dims>
401 constexpr void addToBounds(typename std::enable_if<tdims == 1, const t_type&>::type scaler)
402 {
403 for (uint01 dim = 0; dim < tdims; ++dim)
404 {
405 if ((*this)[MAX][dim] < scaler)
406 (*this)[MAX][dim] = scaler;
407 if ((*this)[MIN][dim] > scaler)
408 (*this)[MIN][dim] = scaler;
409 }
410 }
411
412 /**
413 \brief Adds to the bounds such that the new bounds fully encompasses the argument.
414
415 Author: Tyler Parke.
416
417 Date:
418 2017-11-17.
419
420 Parameters:
421 \param[in] bounds - The bounds to add to this bounds.
422 **/
423
424 constexpr void addToBounds(const Bounds& bounds)
425 {
426 for (uint01 dim = 0; dim < t_dims; ++dim)
427 {
428 if ((*this)[MAX][dim] < bounds[MAX][dim])
429 (*this)[MAX][dim] = bounds[MAX][dim];
430 if ((*this)[MIN][dim] > bounds[MIN][dim])
431 (*this)[MIN][dim] = bounds[MIN][dim];
432 }
433 }
434
435 /**
436 \brief Adds to the bounds such that the new bounds fully encompasses the argument.
437
438 Author: Tyler Parke.
439
440 Date:
441 2017-11-17.
442
443 Parameters:
444 \param[in] line_segment - The line segment.
445 **/
446
447 constexpr void addToBounds(const LineSegment<t_dims, t_type, t_vertex>& line_segment)
448 {
449 addToBounds(line_segment.vertex(A));
450 addToBounds(line_segment.vertex(B));
451 }
452
453 /**
454 \brief Adds to the bounds such that the new bounds fully encompesses the argument.
455
456 Author: Tyler Parke.
457
458 Date:
459 2017-11-17.
460
461 Parameters:
462 \param[in] triangle - The triangle.
463 **/
464
465 constexpr void addToBounds(const Triangle<t_dims, t_type, t_vertex>& triangle)
466 {
467 addToBounds(triangle.vertex(A));
468 addToBounds(triangle.vertex(B));
469 addToBounds(triangle.vertex(C));
470 }
471
472 /**
473 \brief Query if this object contains the given radial_object.
474
475 Author: Tyler Parke
476
477 Date: 2017-11-18
478
479 Parameters:
480 \param[in] radial_object - The const RadialObject&lt;t_dims,t_type&gt;&amp; to test for containment.
481
482 \returns True if the object is in this collection, false if not.
483 **/
484 template<bool t_allow_bounds = true>
485 constexpr bool contains(const RadialObject<t_dims, t_type>& radial_object) const
486 {
487 if (t_allow_bounds)
488 return distanceSquared(closestEdge(radial_object.center()), radial_object.center()) <= radial_object.radius() * radial_object.radius();
489 else
490 return distanceSquared(closestEdge(radial_object.center()), radial_object.center()) < radial_object.radius() * radial_object.radius();
491 }
492
493 /**
494 \brief Closest edge.
495
496 Author: Tyler Parke.
497
498 Date:
499 2017 - 11-17.
500
501 Parameters:
502 \param[in] vertex - The first t_vertex.
503
504 \returns The closest edge.
505 **/
506
507 constexpr t_vertex closestEdge(const t_vertex& vertex) const
508 {
509 t_vertex closest_edge;
510 for(uint01 dim = 0; dim < t_dims; ++dim)
511 closest_edge[dim] = abs(vertex[dim] - (*this)[MIN][dim]) > abs(vertex[dim] - (*this)[MAX][dim]) ? (*this)[MAX][dim] : (*this)[MIN][dim];
512 return closest_edge;
513 }
514
515 /**
516 \brief Closest value.
517
518 Author: Tyler Parke.
519
520 Date:
521 2017 - 11-17.
522
523 Parameters:
524 \param[in] vertex - The first t_vertex.
525
526 \returns The closest element.
527 **/
528
529 constexpr t_vertex closestValue(const t_vertex& vertex) const
530 {
531 t_vertex closest_vertex;
532 for(uint01 dim = 0; dim < t_dims; ++dim)
533 closest_vertex[dim] = (vertex[dim] < (*this)[MIN][dim]) ? (*this)[MIN][dim] : (vertex[dim] > (*this)[MAX][dim]) ? (*this)[MAX][dim] : vertex[dim];
534 return closest_vertex;
535 }
536
537 /**
538 \brief Furthest value.
539
540 Author: Tyler Parke.
541
542 Date:
543 2017 - 11-17.
544
545 Parameters:
546 \param[in] vertex - The first t_vertex.
547
548 \returns The furthest point.
549 **/
550
551 constexpr t_vertex furthestValue(const t_vertex& vertex) const
552 {
553 t_vertex furthest_vertex;
554 for(uint01 dim = 0; dim < t_dims; ++dim)
555 furthest_vertex[dim] = abs(vertex[dim] - (*this)[MIN][dim]) > abs(vertex[dim] - (*this)[MAX][dim]) ? (*this)[MIN][dim] : (*this)[MAX][dim];
556 return furthest_vertex;
557 }
558
559 /**
560
561 \brief Checks for intersection of the ray from a given distance, excluding one axis.
562
563 Author: Tyler Parke
564
565 Date: 2017-11-18
566
567 Parameters:
568 \param[in] distance_a - The distance a.
569 \param[in] distance_b - The distance b.
570 \param[in] origin - The origin.
571 \param[in] ray - The ray.
572 \param[in] exclusion_axis - The exclusion axis.
573
574 \returns True if it succeeds, false if it fails.
575 **/
576
577 constexpr bool doesIntersect(t_type distance_a, t_type distance_b, const t_vertex& origin, const Vector<t_dims, t_type>& ray, uint01 exclusion_axis) const
578 {
579 if(!((distance_a * distance_b) < cast<t_type>(0))) //!< for Invalid
580 return false;
581
582 t_type unit_value = (-distance_a / (distance_b - distance_a));
583 for (uint01 dim = 0; dim < exclusion_axis; ++dim)
584 {
585 t_type hit_location = origin[dim] + ray[dim] * unit_value;
586 if (hit_location < (*this)[MIN][dim] || hit_location > (*this)[MAX][dim])
587 return false;
588 }
589 for (uint01 dim = exclusion_axis + 1; dim < t_dims; ++dim)
590 {
591 t_type hit_location = origin[dim] + ray[dim] * unit_value;
592 if (hit_location < (*this)[MIN][dim] || hit_location > (*this)[MAX][dim])
593 return false;
594 }
595 return true;
596 }
597
598 /**
599 \brief Query if this object intersects the given pair.
600
601 Author: Tyler Parke
602
603 Date: 2017-11-17
604
605 Parameters:
606 \param[in] bounds - The pair.
607
608 \returns True if it succeeds, false if it fails.
609 **/
610 template<class t_other_vertex_type>
611 constexpr bool intersects(const Bounds<t_dims, t_type, t_other_vertex_type>& bounds) const
612 {
613 for (uint01 dim = 0; dim < t_dims; ++dim)
614 {
615 if (!((*this)[MAX][dim] > bounds[MIN][dim] && (*this)[MIN][dim] < bounds[MAX][dim]))
616 return false;
617 }
618 return true;
619 }
620
621
622 template<class t_other_vertex_type>
624 {
625 if (contains(seg))
626 {
627 return true;
628 }
629 const Vector<t_dims, t_type> ray = seg.ray();
630 for (uint01 i = 0; i < t_dims; ++i)
631 {
632 if ( doesIntersect(seg.vertex(A)[i] - (*this)[MIN][i], seg.vertex(B)[i] - (*this)[MIN][i], seg.vertex(A), ray, i)
633 || doesIntersect(seg.vertex(A)[i] - (*this)[MAX][i], seg.vertex(B)[i] - (*this)[MAX][i], seg.vertex(A), ray, i))
634 return true;
635 }
636 return false;
637 }
638
639 /**
640 \brief Query if this object contains the given circle.
641 \param[in] circle - The const RadialObject&lt;t_rad_dims,t_rad_type&gt;&amp; to test for containment.
642 \returns True if the object is in this collection, false if not.
643 **/
644 template<bool t_allow_bounds = true>
645 constexpr bool intersects(const RadialObject<t_dims, t_type>& circle) const
646 {
647 t_type dist_squared = circle.radius() * circle.radius();
648 for (uint01 dim = 0; dim < t_dims; ++dim)
649 {
650 if (circle.getCenter()[dim] < (*this)[MIN][dim])
651 {
652 t_type value = circle.center()[dim] - (*this)[MIN][dim];
653 dist_squared -= (value * value);
654 }
655 else if (circle.getCenter()[dim] > (*this)[MAX][dim])
656 {
657 t_type value = circle.center()[dim] - (*this)[MAX][dim];
658 dist_squared -= (value * value);
659 }
660 if (t_allow_bounds)
661 {
662 if (dist_squared < 0)
663 return false;
664 }
665 else
666 {
667 if (dist_squared <= 0)
668 return false;
669 }
670 }
671 return true;
672 }
673
674 /**
675 \brief Validates this object. Returns true if the value at MIN is less than or equal the value at MAX in all
676 dimensions.
677 \returns True if it succeeds, false if it fails.
678 **/
679 [[nodiscard]] constexpr bool validate() const
680 {
681 if (getMin((*this)[MIN], (*this)[MAX]) != (*this)[MIN])
682 return false;
683 if (getMax((*this)[MIN], (*this)[MAX]) != (*this)[MAX])
684 return false;
685 return true;
686 }
687
688 /**
689 \brief Ensures that this is a valid bounds object. Values are swapped within the structure to ensure that
690 MAX >= MIN
691 **/
693 {
694 t_vertex min = (*this)[MIN];
695 t_vertex max = (*this)[MAX];
696 (*this)[MIN] = getMin(min, max);
697 (*this)[MAX] = getMax(min, max);
698 }
699 Bounds<t_dims, t_type>& operator-=(const t_type& center_scale)
700 {
701 (*this)[MAX] -= center_scale;
702 (*this)[MIN] -= center_scale;
703 return *this;
704 }
705 };
706
707
708
709 template<uint01 t_dims, class t_type, class t_vertex>
710 struct Constant<Bounds<t_dims, t_type, t_vertex>>
711 {
712 constexpr static Bounds<t_dims, t_type, t_vertex> Invalid{ Constant<t_type>::Invalid, Constant<t_type>::Invalid };
713 constexpr static Bounds<t_dims, t_type, t_vertex> Min{ Constant<t_type>::Max, Constant<t_type>::Min };
714 constexpr static Bounds<t_dims, t_type, t_vertex> Max{ Constant<t_type>::Min, Constant<t_type>::Max };
715 };
716
717 template<uint01 t_dims, class t_type, class t_vertex>
718 static constexpr bool IsInvalid(const Bounds<t_dims, t_type, t_vertex>& value)
719 {
720 for (uint01 dim = 0; dim < 2; ++dim)
721 {
722 if (IsInvalid(value[dim]))
723 return true;
724 }
725 return false;
726 }
727
728};
729
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
constexpr bool validate() const
Validates this object. Returns true if the value at MIN is less than or equal the value at MAX in all...
Definition Bounds.hpp:679
constexpr Bounds()
Definition Bounds.hpp:54
constexpr Bounds(const t_vertex &min, const t_vertex &max)
Definition Bounds.hpp:75
constexpr t_type surfaceArea() const
The surface area of the shape. This is defined as the area between internal space and non-internal sp...
Definition Bounds.hpp:138
constexpr t_type volume() const
Returns the volume of the bounds. This is defined as length in 1 dimension, area in 2 dimensions.
Definition Bounds.hpp:130
constexpr Bounds< t_new_dims, t_new_type, t_new_vertex > as(t_new_type extra_fill_value=t_new_type(0)) const
Casts this object into an object of different dimension or precision.
Definition Bounds.hpp:220
constexpr void addToBounds(const LineSegment< t_dims, t_type, t_vertex > &line_segment)
Definition Bounds.hpp:447
constexpr void addToBounds(const t_vertex &vector)
Definition Bounds.hpp:390
constexpr Ray< t_dims, t_type > span() const
The side lengths of these bounds. For each dimension, the span is max - min.
Definition Bounds.hpp:111
constexpr void expand(const t_vertex &expansion_vector)
Expands the given expansion scaler. such that max and min are both expanded outward from the center b...
Definition Bounds.hpp:173
constexpr t_vertex closestValue(const t_vertex &vertex) const
Definition Bounds.hpp:529
constexpr bool contains(const Bounds &bounds) const
Definition Bounds.hpp:294
constexpr Bounds(const RadialObject< t_dims, t_type, t_vertex > &radial)
Definition Bounds.hpp:103
constexpr void addToBounds(const Bounds &bounds)
Definition Bounds.hpp:424
constexpr bool contains(const Triangle< t_dims, t_type, t_vertex > &tri) const
Definition Bounds.hpp:371
constexpr Bounds(const Vector< 2, t_vertex > &bounds)
Definition Bounds.hpp:82
constexpr Bounds(const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Bounds.hpp:93
constexpr bool contains(const RadialObject< t_dims, t_type > &radial_object) const
Definition Bounds.hpp:485
constexpr bool intersects(const RadialObject< t_dims, t_type > &circle) const
Query if this object contains the given circle.
Definition Bounds.hpp:645
constexpr Bounds(const t_vertex &center, t_type size)
Given the center, creates bounds of size where max and min are both equal to the vertex + size and.
Definition Bounds.hpp:72
constexpr Bounds(const Bounds &bounds_a, const Bounds &bounds_b)
Definition Bounds.hpp:86
constexpr void addToBounds(const Triangle< t_dims, t_type, t_vertex > &triangle)
Definition Bounds.hpp:465
constexpr Bounds< t_dims, t_type > scale(const t_type &scale, const Vector< t_dims, t_type > &center) const
Definition Bounds.hpp:196
constexpr void addToBounds(typename std::enable_if< tdims==1, const t_type & >::type scaler)
Definition Bounds.hpp:401
constexpr Bounds< t_dims, t_type > scale(const t_type &center_scale) const
Definition Bounds.hpp:203
constexpr Bounds< t_dims, t_type > scale(const Vector< t_dims, t_type > &scale, const Vector< t_dims, t_type > &center) const
Scales this geometry about a center point.
Definition Bounds.hpp:185
Bounds< t_dims, t_type > & operator-=(const t_type &center_scale)
Definition Bounds.hpp:699
constexpr bool contains(const t_type &value) const
Query if this object contains the given value. t_allow_bounds - whether or not to allow boundary case...
Definition Bounds.hpp:237
constexpr Bounds< t_dims, t_type > scale(const Vector< t_dims, t_type > &center_scale) const
Definition Bounds.hpp:191
constexpr t_vertex center() const
Returns the center of the bounds.
Definition Bounds.hpp:120
constexpr bool contains(const LineSegment< t_dims, t_type, t_vertex > &line) const
Author: Tyler Parke.
Definition Bounds.hpp:332
constexpr Bounds(const t_type &min_scaler, const t_type &max_scaler)
Definition Bounds.hpp:78
constexpr bool doesIntersect(t_type distance_a, t_type distance_b, const t_vertex &origin, const Vector< t_dims, t_type > &ray, uint01 exclusion_axis) const
Checks for intersection of the ray from a given distance, excluding one axis.
Definition Bounds.hpp:577
constexpr Bounds(const Triangle< t_dims, t_type, t_vertex > &tri)
Definition Bounds.hpp:97
constexpr t_vertex furthestValue(const t_vertex &vertex) const
Definition Bounds.hpp:551
constexpr void expand(const t_type &expansion_scaler)
Expands the given expansion scaler. such that max and min are both expanded outward from the center b...
Definition Bounds.hpp:161
constexpr bool intersects(const LineSegment< t_dims, t_type, t_other_vertex_type > &seg) const
Definition Bounds.hpp:623
void ensureValid()
Ensures that this is a valid bounds object. Values are swapped within the structure to ensure that MA...
Definition Bounds.hpp:692
constexpr Bounds(const t_vertex &vertex)
Given the vector, creates bounds of size 0 where max and min are both equal to the vertex.
Definition Bounds.hpp:61
constexpr Bounds(const Bounds &bounds, const t_vertex &vector)
Definition Bounds.hpp:90
constexpr bool contains(const t_vertex &vector) const
Query if this object contains the given vector. t_allow_bounds - whether or not to allow boundary cas...
Definition Bounds.hpp:258
constexpr bool intersects(const Bounds< t_dims, t_type, t_other_vertex_type > &bounds) const
Definition Bounds.hpp:611
constexpr t_vertex closestEdge(const t_vertex &vertex) const
Definition Bounds.hpp:507
A line segment represented by two vertices, a start and end.
Definition Line.hpp:49
constexpr t_vertex ray() const
Definition Line.hpp:120
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:152
A radial object.
Definition RadialObject.hpp:52
constexpr t_type radius() const
Definition RadialObject.hpp:123
constexpr const t_vertex & center() const
Definition RadialObject.hpp:152
Definition Vertex.hpp:317
A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometr...
Definition Triangle.hpp:138
constexpr t_vertex & vertex(TriangleLocation triangle_node)
Vertices the given triangle node.
Definition Triangle.hpp:168
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
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
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
@ MIN
Definition BaseValues.hpp:196
@ MAX
Definition BaseValues.hpp:197
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:46
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
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
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ C
Definition BaseValues.hpp:172
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
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