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>
50 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
67 constexpr Bounds(
const t_vertex& vertex)
68 :
Vector<2, t_vertex>(vertex, vertex)
87 constexpr Bounds(
const t_vertex& min,
const t_vertex& max)
88 :
Vector<2, t_vertex>(min, max)
90 constexpr Bounds(
const t_type& min_scaler,
const t_type& max_scaler)
91 :
Vector<2, t_vertex>(t_vertex(min_scaler), t_vertex(max_scaler))
95 :
Vector<2, t_vertex>(bounds)
111 getMin(tri.vertex(
A), tri.vertex(
B), tri.vertex(
C))
112 ,
getMax(tri.vertex(
A), tri.vertex(
B), tri.vertex(
C)))
116 :
Vector<2, t_vertex>(radial.
center() - radial.radius(), radial.
center() + radial.radius())
160 return span().product();
174 t_vertex side_lengths =
span();
175 for (
uint01 dim_a = 0; dim_a < t_dims; dim_a++)
177 for (
uint01 dim_b = 0; dim_b < t_dims; dim_b++)
181 area += side_lengths[dim_a] * side_lengths[dim_b];
200 constexpr void expand(
const t_type& expansion_scaler)
202 (*this)[
MIN] -= expansion_scaler;
203 (*this)[
MAX] += expansion_scaler;
218 constexpr void expand(
const t_vertex& expansion_vector)
278 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex = Vertex<t_new_dims, t_new_type>>
300 template<
bool t_allow_bounds =
true,
uint01 tdims = t_dims
301 ,
typename =
typename std::enable_if<tdims == 1>::type>
302 constexpr bool contains(
const t_type & value)
const
306 return !(!(value >= (*this)[
MIN][0]) || !(value <= (*this)[
MAX][0]));
310 return !(!(value > (*this)[
MIN][0]) || !(value < (*this)[
MAX][0]));
328 template<
bool t_allow_bounds = true>
329 constexpr bool contains(
const t_vertex& vector)
const
333 for (
uint01 dim = 0; dim < t_dims; ++dim)
335 if (!(vector[dim] >= (*
this)[
MIN][dim]) || !(vector[dim] <= (*
this)[
MAX][dim]))
341 for (
uint01 dim = 0; dim < t_dims; ++dim)
343 if (!(vector[dim] > (*
this)[
MIN][dim]) || !(vector[dim] < (*
this)[
MAX][dim]))
364 template<
bool t_allow_bounds = true>
369 for (
uint01 dim = 0; dim < t_dims; ++dim)
371 if (!(bounds[
MIN][dim] >= (*
this)[
MIN][dim]))
373 if (!(bounds[
MAX][dim] <= (*
this)[
MAX][dim]))
379 for (
uint01 dim = 0; dim < t_dims; ++dim)
381 if (!(bounds[
MIN][dim] >(*
this)[
MIN][dim]))
383 if (!(bounds[
MAX][dim] < (*
this)[
MAX][dim]))
402 template<
bool t_allow_bounds = true>
407 for (
uint01 dim = 0; dim < t_dims; ++dim)
417 for (
uint01 dim = 0; dim < t_dims; ++dim)
441 template<
bool t_allow_bounds = true>
444 for (
uint01 tri_index =
A; tri_index <=
C; tri_index++)
463 for (
uint01 dim = 0; dim < t_dims; ++dim)
465 if ((*
this)[
MAX][dim] < vector[dim])
466 (*this)[
MAX][dim] = vector[dim];
467 if ((*
this)[
MIN][dim] > vector[dim])
468 (*this)[
MIN][dim] = vector[dim];
471 template<u
int01 tdims = t_dims>
472 constexpr void addToBounds(
typename std::enable_if<tdims == 1, const t_type&>::type scaler)
474 for (
uint01 dim = 0; dim < tdims; ++dim)
476 if ((*
this)[
MAX][dim] < scaler)
477 (*this)[
MAX][dim] = scaler;
478 if ((*
this)[
MIN][dim] > scaler)
479 (*this)[
MIN][dim] = scaler;
497 for (
uint01 dim = 0; dim < t_dims; ++dim)
499 if ((*
this)[
MAX][dim] < bounds[
MAX][dim])
500 (*this)[
MAX][dim] = bounds[
MAX][dim];
501 if ((*
this)[
MIN][dim] > bounds[
MIN][dim])
502 (*this)[
MIN][dim] = bounds[
MIN][dim];
555 template<
bool t_allow_bounds = true>
580 t_vertex closest_edge;
581 for(
uint01 dim = 0; dim < t_dims; ++dim)
582 closest_edge[dim] =
abs(vertex[dim] - (*
this)[
MIN][dim]) >
abs(vertex[dim] - (*
this)[
MAX][dim]) ? (*this)[
MAX][dim] : (*this)[
MIN][dim];
602 t_vertex closest_vertex;
603 for(
uint01 dim = 0; dim < t_dims; ++dim)
604 closest_vertex[dim] = (vertex[dim] < (*
this)[
MIN][dim]) ? (*this)[
MIN][dim] : (vertex[dim] > (*this)[
MAX][dim]) ? (*
this)[
MAX][dim] : vertex[dim];
605 return closest_vertex;
624 t_vertex furthest_vertex;
625 for(
uint01 dim = 0; dim < t_dims; ++dim)
626 furthest_vertex[dim] =
abs(vertex[dim] - (*
this)[
MIN][dim]) >
abs(vertex[dim] - (*
this)[
MAX][dim]) ? (*this)[
MIN][dim] : (*this)[
MAX][dim];
627 return furthest_vertex;
653 t_type unit_value = (-distance_a / (distance_b - distance_a));
654 for (
uint01 dim = 0; dim < exclusion_axis; ++dim)
656 t_type hit_location = origin[dim] + ray[dim] * unit_value;
657 if (hit_location < (*
this)[
MIN][dim] || hit_location > (*
this)[
MAX][dim])
660 for (
uint01 dim = exclusion_axis + 1; dim < t_dims; ++dim)
662 t_type hit_location = origin[dim] + ray[dim] * unit_value;
663 if (hit_location < (*
this)[
MIN][dim] || hit_location > (*
this)[
MAX][dim])
681 template<
class t_other_vertex_type>
684 for (
uint01 dim = 0; dim < t_dims; ++dim)
686 if (!((*
this)[
MAX][dim] > bounds[
MIN][dim] && (*
this)[
MIN][dim] < bounds[
MAX][dim]))
693 template<
class t_other_vertex_type>
701 for (
uint01 i = 0; i < t_dims; ++i)
722 template<
bool t_allow_bounds = true>
725 t_type dist_squared = circle.
radius() * circle.
radius();
726 for (
uint01 dim = 0; dim < t_dims; ++dim)
728 if (circle.getCenter()[dim] < (*
this)[
MIN][dim])
730 t_type value = circle.
center()[dim] - (*this)[
MIN][dim];
731 dist_squared -= (value * value);
733 else if (circle.getCenter()[dim] > (*
this)[
MAX][dim])
735 t_type value = circle.
center()[dim] - (*this)[
MAX][dim];
736 dist_squared -= (value * value);
740 if (dist_squared < 0)
745 if (dist_squared <= 0)
782 t_vertex min = (*this)[
MIN];
783 t_vertex max = (*this)[
MAX];
789 (*this)[
MAX] -= center_scale;
790 (*this)[
MIN] -= center_scale;
797 template<u
int01 t_dims,
class t_type,
class t_vertex>
798 struct Constant<Bounds<t_dims, t_type, t_vertex>>
805 template<u
int01 t_dims,
class t_type,
class t_vertex>
806 static constexpr bool IsInvalid(
const Bounds<t_dims, t_type, t_vertex>& value)
808 for (
uint01 dim = 0; dim < 2; ++dim)
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
constexpr bool validate() const
Definition Bounds.hpp:763
constexpr Bounds()
Definition Bounds.hpp:54
constexpr Bounds(const t_vertex &min, const t_vertex &max)
Definition Bounds.hpp:87
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:171
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:158
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:279
constexpr void addToBounds(const LineSegment< t_dims, t_type, t_vertex > &line_segment)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:518
constexpr void addToBounds(const t_vertex &vector)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:461
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:128
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:218
constexpr t_vertex closestValue(const t_vertex &vertex) const
Closest value.
Definition Bounds.hpp:600
constexpr bool contains(const Bounds &bounds) const
Query if this object contains the given bounds.
Definition Bounds.hpp:365
constexpr Bounds(const RadialObject< t_dims, t_type, t_vertex > &radial)
Definition Bounds.hpp:115
constexpr void addToBounds(const Bounds &bounds)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:495
constexpr bool contains(const Triangle< t_dims, t_type, t_vertex > &tri) const
Fully contains.
Definition Bounds.hpp:442
constexpr Bounds(const Vector< 2, t_vertex > &bounds)
Definition Bounds.hpp:94
constexpr Bounds(const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Bounds.hpp:105
constexpr bool contains(const RadialObject< t_dims, t_type > &radial_object) const
Query if this object contains the given radial_object.
Definition Bounds.hpp:556
constexpr bool intersects(const RadialObject< t_dims, t_type > &circle) const
Query if this object contains the given circle.
Definition Bounds.hpp:723
constexpr Bounds(const t_vertex ¢er, 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:84
constexpr Bounds(const Bounds &bounds_a, const Bounds &bounds_b)
Definition Bounds.hpp:98
constexpr void addToBounds(const Triangle< t_dims, t_type, t_vertex > &triangle)
Adds to the bounds such that the new bounds fully encompesses the argument.
Definition Bounds.hpp:536
constexpr Bounds< t_dims, t_type > scale(const t_type &scale, const Vector< t_dims, t_type > ¢er) const
Definition Bounds.hpp:249
constexpr void addToBounds(typename std::enable_if< tdims==1, const t_type & >::type scaler)
Definition Bounds.hpp:472
constexpr Bounds< t_dims, t_type > scale(const t_type ¢er_scale) const
Definition Bounds.hpp:256
constexpr Bounds< t_dims, t_type > scale(const Vector< t_dims, t_type > &scale, const Vector< t_dims, t_type > ¢er) const
Scales this geometry about a center point.
Definition Bounds.hpp:238
Bounds< t_dims, t_type > & operator-=(const t_type ¢er_scale)
Definition Bounds.hpp:787
constexpr bool contains(const t_type &value) const
Query if this object contains the given value.
Definition Bounds.hpp:302
constexpr Bounds< t_dims, t_type > scale(const Vector< t_dims, t_type > ¢er_scale) const
Definition Bounds.hpp:244
constexpr t_vertex center() const
Returns the center of the bounds.
Definition Bounds.hpp:143
constexpr bool contains(const LineSegment< t_dims, t_type, t_vertex > &line) const
Author: Tyler Parke.
Definition Bounds.hpp:403
constexpr Bounds(const t_type &min_scaler, const t_type &max_scaler)
Definition Bounds.hpp:90
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:648
constexpr Bounds(const Triangle< t_dims, t_type, t_vertex > &tri)
Definition Bounds.hpp:109
constexpr t_vertex furthestValue(const t_vertex &vertex) const
Furthest value.
Definition Bounds.hpp:622
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:200
constexpr bool intersects(const LineSegment< t_dims, t_type, t_other_vertex_type > &seg) const
Definition Bounds.hpp:694
void ensureValid()
Ensures that this is a valid bounds object. Values are swapped within the structure to ensure that MA...
Definition Bounds.hpp:780
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:67
constexpr Bounds(const Bounds &bounds, const t_vertex &vector)
Definition Bounds.hpp:102
constexpr bool contains(const t_vertex &vector) const
Query if this object contains the given vector.
Definition Bounds.hpp:329
constexpr bool intersects(const Bounds< t_dims, t_type, t_other_vertex_type > &bounds) const
Query if this object intersects the given pair.
Definition Bounds.hpp:682
constexpr t_vertex closestEdge(const t_vertex &vertex) const
Closest edge.
Definition Bounds.hpp:578
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:153
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:173
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
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:177
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:101
@ MIN
Definition BaseValues.hpp:191
@ MAX
Definition BaseValues.hpp:192
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:78
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:45
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:379
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:655
@ B
Definition BaseValues.hpp:166
@ A
Definition BaseValues.hpp:164
@ C
Definition BaseValues.hpp:168
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:231
static const t_type Min
Definition BaseValues.hpp:232
static const t_type Max
Definition BaseValues.hpp:233