33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
35#include <NDEVR/LineSegment.h>
36#include <NDEVR/Angle.h>
37#include <NDEVR/AngleDefinitions.h>
79 lib_assert(
false,
"Segment does not have oposite value");
100 lib_assert(
false,
"Not a valid vertex request");
120 lib_assert(
false,
"Not a valid vertex request");
136 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
143 :
Vector<3, t_vertex>(t_vertex(a), t_vertex(a), t_vertex(a))
145 constexpr Triangle(
const t_type& a,
const t_type& b,
const t_type& c)
146 :
Vector<3, t_vertex>(t_vertex(a), t_vertex(b), t_vertex(c))
148 explicit constexpr Triangle(
const t_vertex& vector)
149 :
Vector<3, t_vertex>(vector)
151 constexpr Triangle(
const t_vertex& a,
const t_vertex& b,
const t_vertex& c)
152 :
Vector<3, t_vertex>(a, b, c)
170 switch (triangle_node)
194 switch (triangle_node)
218 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
219 return (*
this)[triangle_node];
235 [[nodiscard]]
constexpr const t_vertex&
vertex(
uint01 triangle_node)
const
237 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
238 return (*
this)[triangle_node];
258 lib_assert(triangle_node_a <= 2 && triangle_node_b <= 2,
"Tried to access bad Triangle Node");
298 template<
class t_angle_type>
301 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
302 const uint01 left = triangle_node > 0 ? triangle_node - 1 : 2;
303 const uint01 right = triangle_node < 2 ? triangle_node + 1 : 0;
309 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
310 uint01 left = triangle_node > 0 ? triangle_node - 1 : 2;
311 uint01 right = triangle_node < 2 ? triangle_node + 1 : 0;
319 return (y *
sqrt(1.0 - ((x * x) / (y * y)))) / x;
334 template<
class t_angle_type>
356 template<
class t_area_type>
357 [[nodiscard]]
constexpr inline t_area_type
area()
const
387 [[nodiscard]]
constexpr t_vertex
center()
const
404 template<u
int01 t_new_dims,
class t_new_type>
420 template<
bool is_normalized,
class t_normal_type = t_type>
427 return cross_product;
475 [[nodiscard]]
constexpr bool contains(
const t_vertex& vertex_point, t_type epsilon = t_type(0.0001))
const
478 for(
uint01 dim = 0; dim < t_dims; dim++)
485 const t_vertex dbp = vertex_point -
vertex(
A);
488 t_type dotca =
dot(dca, dca);
489 t_type dotcaba =
dot(dca, dba);
490 t_type dotcabp =
dot(dca, dbp);
491 t_type dotba =
dot(dba, dba);
492 t_type dotbabp =
dot(dba, dbp);
495 t_type invDenom = (dotca * dotba - dotcaba * dotcaba);
496 t_type u = ((dotba * dotcabp) - (dotcaba * dotbabp)) / invDenom;
497 t_type v = ((dotca * dotbabp) - (dotcaba * dotcabp)) / invDenom;
500 if ((u >= 0) && (v >= 0) && (u + v < 1))
531 switch (object_to_check)
541 if (
equals(edge_a, edge_b, epsilon))
550 const t_vertex vertex_1 =
vertex(object_to_check);
554 if (
equals(vertex_1, vertex_2, epsilon))
567 for (
uint01 i = 0; i <= 2; i++)
691 const t_type dot_1 =
dot(normal_abp, normal_bcp);
692 if(dot_1 >= epsilon + 1 || dot_1 <= -epsilon + 1)
696 const t_type dot_2 =
dot(normal_bcp, normal_cap);
697 if((dot_2 >= epsilon + 1 && dot_2 <= -epsilon + 1))
789 lib_assert(
false,
"Should never arrive here in triangle identity line");
791 lib_assert(
false,
"Should never arrive here in triangle identity line");
856 template<u
int01 t_dims,
class t_type,
class t_vertex>
859 const t_vertex edge0 = tri.
edge(
B,
A).ray();
860 const t_vertex edge1 = tri.
edge(
C,
A).ray();
862 const t_type a =
dot(edge0, edge0);
863 const t_type b =
dot(edge0, edge1);
864 const t_type c =
dot(edge1, edge1);
866 const t_type det = a * c - b * b;
868 return ClosestPoint(tri, point, edge0, edge1, a, b, c, det);
871 template<u
int01 t_dims,
class t_type,
class t_vertex>
872 constexpr Vector<t_dims, t_type> ClosestPoint(
const Triangle<t_dims, t_type, t_vertex>& tri,
const t_vertex& point,
const t_vertex& edge0,
const Vector<t_dims, t_type>& edge1, t_type a, t_type b, t_type c, t_type det)
874 const t_vertex v0(tri.
vertex(
A) - point);
875 const t_type d =
dot(edge0, v0);
876 const t_type e =
dot(edge1, v0);
878 t_type s = b * e - c * d;
879 t_type t = b * d - a * e;
924 t_type numer = tmp1 - tmp0;
925 t_type denom = a - 2 * b + c;
931 t =
clip(-e / c, 0.f, 1.f);
939 t_type numer = c + e - b - d;
940 t_type denom = a - 2 * b + c;
952 t_type numer = c + e - b - d;
953 t_type denom = a - 2 * b + c;
959 return tri.
vertex(
A) + s * edge0 + t * edge1;
977 template<
bool t_has_winding, u
int01 t_dims,
class t_type,
class t_vertex>
992 else if(!t_has_winding && tri_a.
vertex(
B) == tri_b.
vertex((
C + dif) % 3))
1003 template<u
int01 t_dims,
class t_type,
class t_vector>
1004 struct Constant<Triangle<t_dims, t_type, t_vector>>
1011 template<u
int01 t_dims,
class t_type>
1012 static constexpr bool IsInvalid(
const Triangle<t_dims, t_type>& value)
1014 for (
uint01 dim = 0; dim < t_dims; ++dim)
#define lib_assert(expression, message)
Definition LibAssert.h:61
static Angle< t_angle_type > Rotation(const Vector< t_dims, t_type > &left, const Vector< t_dims, t_type > &middle, const Vector< t_dims, t_type > &right)
Definition AngleFunctions.h:694
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
A line segment represented by two vertices, a start and end.
Definition Line.hpp:49
Base class for N-dimensional triangles.
Definition Triangle.hpp:66
static constexpr TriangleLocation NextVertexCCW(TriangleLocation location)
Returns the point location counter-clockwise to given point location.
Definition Triangle.hpp:92
static constexpr TriangleLocation oppositeLocation(TriangleLocation location)
Definition Triangle.hpp:68
static constexpr TriangleLocation NextVertexCW(TriangleLocation location)
Returns the point location clockwise to given point location.
Definition Triangle.hpp:112
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 Vector< t_dims, t_normal_type > normal() const
Definition Triangle.hpp:421
constexpr Triangle< t_new_dims, t_new_type > as() const
Definition Triangle.hpp:405
constexpr bool contains(const Vector< t_dims - 1, t_type > &p) const
Definition Triangle.hpp:443
constexpr t_vertex & vertex(uint01 triangle_node)
Definition Triangle.hpp:216
constexpr t_vertex centroid() const
Definition Triangle.hpp:372
constexpr LineSegment< t_dims, t_type, t_vertex > edge(TriangleLocation location) const
Edges the given location.
Definition Triangle.hpp:275
constexpr uint01 vertexIndex(const t_vertex &p) const
Definition Triangle.hpp:594
constexpr const t_vertex & vertex(TriangleLocation triangle_node) const
Vertices the given triangle node.
Definition Triangle.hpp:192
constexpr TriangleLocation getLocation(const LineSegment< t_dims, t_type, t_vertex > &line, t_type epsilon=cast< t_type >(0)) const
Definition Triangle.hpp:702
constexpr t_area_type area() const
Definition Triangle.hpp:357
constexpr Triangle(const t_vertex &vector)
Definition Triangle.hpp:148
constexpr TriangleLocation getIdentityOf(const LineSegment< t_dims, t_type, t_vertex > &line) const
Definition Triangle.hpp:647
constexpr TriangleLocation getLocation(const t_vertex &p, t_type epsilon=cast< t_type >(0)) const
Definition Triangle.hpp:678
constexpr const t_vertex & vertex(uint01 triangle_node) const
Definition Triangle.hpp:235
constexpr TriangleLocation sharesObject(TriangleLocation object_to_check, const Triangle< t_dims, t_type, t_vertex > &tri, t_type epsilon=0) const
Definition Triangle.hpp:529
constexpr Triangle(const t_type &a)
Definition Triangle.hpp:142
constexpr TriangleLocation getIdentityOf(const LineSegment< t_dims, t_type, t_vertex > &line, t_type epsilon) const
Definition Triangle.hpp:616
constexpr Triangle(const t_vertex &a, const t_vertex &b, const t_vertex &c)
Definition Triangle.hpp:151
constexpr fltp08 tan(uint01 triangle_node) const
Definition Triangle.hpp:307
bool hasVertex(const t_vertex &point) const
Definition Triangle.hpp:833
constexpr bool contains(const t_vertex &vertex_point, t_type epsilon=t_type(0.0001)) const
Definition Triangle.hpp:475
constexpr void invert()
Definition Triangle.hpp:803
constexpr Triangle()
Definition Triangle.hpp:140
constexpr Triangle(const t_type &a, const t_type &b, const t_type &c)
Definition Triangle.hpp:145
constexpr t_vertex center() const
Definition Triangle.hpp:387
constexpr const t_vertex & nextVertexCCW(const t_vertex &point) const
Definition Triangle.hpp:817
constexpr TriangleLocation getIdentityOf(const t_vertex &p, t_type epsilon) const
Definition Triangle.hpp:608
constexpr t_vertex & vertex(TriangleLocation triangle_node)
Vertices the given triangle node.
Definition Triangle.hpp:168
constexpr Angle< t_angle_type > angle(TriangleLocation location) const
Definition Triangle.hpp:335
constexpr LineSegment< t_dims, t_type, t_vertex > edge(uint01 triangle_node_a, uint01 triangle_node_b) const
Definition Triangle.hpp:256
constexpr TriangleLocation getIdentityOf(const t_vertex &p) const
Definition Triangle.hpp:601
constexpr const t_vertex & nextVertexCW(const t_vertex &point) const
Definition Triangle.hpp:829
constexpr Angle< t_angle_type > angle(uint01 triangle_node) const
Definition Triangle.hpp:299
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
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
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:426
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
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
Definition BaseFunctions.hpp:207
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1030
TriangleLocation
Values that represent triangle locations.
Definition Triangle.hpp:47
@ angle_c
Definition Triangle.hpp:57
@ edge_ab
Definition Triangle.hpp:49
@ mixed_location_tri
Definition Triangle.hpp:59
@ angle_b
Definition Triangle.hpp:56
@ vertex_a
Definition Triangle.hpp:52
@ inside_tri
Definition Triangle.hpp:58
@ angle_a
Definition Triangle.hpp:55
@ tri_location_nan
Definition Triangle.hpp:60
@ edge_bc
Definition Triangle.hpp:50
@ edge_ca
Definition Triangle.hpp:51
@ vertex_b
Definition Triangle.hpp:53
@ outside_tri
Definition Triangle.hpp:48
@ vertex_c
Definition Triangle.hpp:54
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
@ RADIANS
Definition Angle.h:57
constexpr bool Equals(const Triangle< t_dims, t_type, t_vertex > &tri_a, const Triangle< t_dims, t_type, t_vertex > &tri_b, t_type epsilon=0)
Definition Triangle.hpp:978
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:46
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
Definition VectorFunctions.hpp:898
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1225
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr Vector< t_dims, t_type > ClosestPoint(const Triangle< t_dims, t_type, t_vertex > &tri, const t_vertex &point)
Definition Triangle.hpp:857
constexpr bool equals(const LineSegment< t_dims, t_type, t_vertex > &left, const LineSegment< t_dims, t_type, t_vertex > &right, const t_type &epsilon=cast< t_type >(0))
Definition Line.hpp:757
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ C
Definition BaseValues.hpp:172
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
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