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>>
61 constexpr Bounds(
const t_vertex& vertex)
62 :
Vector<2, t_vertex>(vertex, vertex)
61 constexpr Bounds(
const t_vertex& vertex) {
…}
75 constexpr Bounds(
const t_vertex& min,
const t_vertex& max)
76 :
Vector<2, t_vertex>(min, max)
75 constexpr Bounds(
const t_vertex& min,
const t_vertex& max) {
…}
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))
78 constexpr Bounds(
const t_type& min_scaler,
const t_type& max_scaler) {
…}
83 :
Vector<2, t_vertex>(bounds)
99 getMin(tri.vertex(
A), tri.vertex(
B), tri.vertex(
C))
100 ,
getMax(tri.vertex(
A), tri.vertex(
B), tri.vertex(
C)))
104 :
Vector<2, t_vertex>(radial.
center() - radial.radius(), radial.
center() + radial.radius())
132 return span().product();
141 t_vertex side_lengths =
span();
142 for (
uint01 dim_a = 0; dim_a < t_dims; dim_a++)
144 for (
uint01 dim_b = 0; dim_b < t_dims; dim_b++)
148 area += side_lengths[dim_a] * side_lengths[dim_b];
161 constexpr void expand(
const t_type& expansion_scaler)
163 (*this)[
MIN] -= expansion_scaler;
164 (*this)[
MAX] += expansion_scaler;
161 constexpr void expand(
const t_type& expansion_scaler) {
…}
173 constexpr void expand(
const t_vertex& expansion_vector)
173 constexpr void expand(
const t_vertex& expansion_vector) {
…}
219 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex = Vertex<t_new_dims, t_new_type>>
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
241 return !(!(value >= (*this)[
MIN][0]) || !(value <= (*this)[
MAX][0]));
245 return !(!(value > (*this)[
MIN][0]) || !(value < (*this)[
MAX][0]));
257 template<
bool t_allow_bounds = true>
258 constexpr bool contains(
const t_vertex& vector)
const
262 for (
uint01 dim = 0; dim < t_dims; ++dim)
264 if (!(vector[dim] >= (*
this)[
MIN][dim]) || !(vector[dim] <= (*
this)[
MAX][dim]))
270 for (
uint01 dim = 0; dim < t_dims; ++dim)
272 if (!(vector[dim] > (*
this)[
MIN][dim]) || !(vector[dim] < (*
this)[
MAX][dim]))
258 constexpr bool contains(
const t_vertex& vector)
const {
…}
293 template<
bool t_allow_bounds = true>
298 for (
uint01 dim = 0; dim < t_dims; ++dim)
300 if (!(bounds[
MIN][dim] >= (*
this)[
MIN][dim]))
302 if (!(bounds[
MAX][dim] <= (*
this)[
MAX][dim]))
308 for (
uint01 dim = 0; dim < t_dims; ++dim)
310 if (!(bounds[
MIN][dim] >(*
this)[
MIN][dim]))
312 if (!(bounds[
MAX][dim] < (*
this)[
MAX][dim]))
331 template<
bool t_allow_bounds = true>
336 for (
uint01 dim = 0; dim < t_dims; ++dim)
346 for (
uint01 dim = 0; dim < t_dims; ++dim)
370 template<
bool t_allow_bounds = true>
373 for (
uint01 tri_index =
A; tri_index <=
C; tri_index++)
392 for (
uint01 dim = 0; dim < t_dims; ++dim)
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];
400 template<u
int01 tdims = t_dims>
401 constexpr void addToBounds(
typename std::enable_if<tdims == 1, const t_type&>::type scaler)
403 for (
uint01 dim = 0; dim < tdims; ++dim)
405 if ((*
this)[
MAX][dim] < scaler)
406 (*this)[
MAX][dim] = scaler;
407 if ((*
this)[
MIN][dim] > scaler)
408 (*this)[
MIN][dim] = scaler;
401 constexpr void addToBounds(
typename std::enable_if<tdims == 1, const t_type&>::type scaler) {
…}
426 for (
uint01 dim = 0; dim < t_dims; ++dim)
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];
484 template<
bool t_allow_bounds = true>
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];
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;
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;
582 t_type unit_value = (-distance_a / (distance_b - distance_a));
583 for (
uint01 dim = 0; dim < exclusion_axis; ++dim)
585 t_type hit_location = origin[dim] + ray[dim] * unit_value;
586 if (hit_location < (*
this)[
MIN][dim] || hit_location > (*
this)[
MAX][dim])
589 for (
uint01 dim = exclusion_axis + 1; dim < t_dims; ++dim)
591 t_type hit_location = origin[dim] + ray[dim] * unit_value;
592 if (hit_location < (*
this)[
MIN][dim] || hit_location > (*
this)[
MAX][dim])
610 template<
class t_other_vertex_type>
613 for (
uint01 dim = 0; dim < t_dims; ++dim)
615 if (!((*
this)[
MAX][dim] > bounds[
MIN][dim] && (*
this)[
MIN][dim] < bounds[
MAX][dim]))
622 template<
class t_other_vertex_type>
630 for (
uint01 i = 0; i < t_dims; ++i)
644 template<
bool t_allow_bounds = true>
647 t_type dist_squared = circle.
radius() * circle.
radius();
648 for (
uint01 dim = 0; dim < t_dims; ++dim)
650 if (circle.getCenter()[dim] < (*
this)[
MIN][dim])
652 t_type value = circle.
center()[dim] - (*this)[
MIN][dim];
653 dist_squared -= (value * value);
655 else if (circle.getCenter()[dim] > (*
this)[
MAX][dim])
657 t_type value = circle.
center()[dim] - (*this)[
MAX][dim];
658 dist_squared -= (value * value);
662 if (dist_squared < 0)
667 if (dist_squared <= 0)
694 t_vertex min = (*this)[
MIN];
695 t_vertex max = (*this)[
MAX];
701 (*this)[
MAX] -= center_scale;
702 (*this)[
MIN] -= center_scale;
709 template<u
int01 t_dims,
class t_type,
class t_vertex>
710 struct Constant<Bounds<t_dims, t_type, t_vertex>>
717 template<u
int01 t_dims,
class t_type,
class t_vertex>
718 static constexpr bool IsInvalid(
const Bounds<t_dims, t_type, t_vertex>& value)
720 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
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 ¢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: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 > ¢er) 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 ¢er_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 > ¢er) const
Scales this geometry about a center point.
Definition Bounds.hpp:185
Bounds< t_dims, t_type > & operator-=(const t_type ¢er_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 > ¢er_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
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