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>
81 lib_assert(
false,
"Segment does not have oposite value");
104 lib_assert(
false,
"Not a valid vertex request");
126 lib_assert(
false,
"Not a valid vertex request");
141 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
149 :
Vector<3, t_vertex>(t_vertex(a), t_vertex(a), t_vertex(a))
152 constexpr Triangle(
const t_type& a,
const t_type& b,
const t_type& c)
153 :
Vector<3, t_vertex>(t_vertex(a), t_vertex(b), t_vertex(c))
156 explicit constexpr Triangle(
const t_vertex& vector)
157 :
Vector<3, t_vertex>(vector)
160 constexpr Triangle(
const t_vertex& a,
const t_vertex& b,
const t_vertex& c)
161 :
Vector<3, t_vertex>(a, b, c)
182 switch (triangle_node)
208 switch (triangle_node)
234 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
235 return (*
this)[triangle_node];
253 [[nodiscard]]
constexpr const t_vertex&
vertex(
uint01 triangle_node)
const
255 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
256 return (*
this)[triangle_node];
278 lib_assert(triangle_node_a <= 2 && triangle_node_b <= 2,
"Tried to access bad Triangle Node");
322 template<
class t_angle_type>
325 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
326 const uint01 left = triangle_node > 0 ? triangle_node - 1 : 2;
327 const uint01 right = triangle_node < 2 ? triangle_node + 1 : 0;
333 lib_assert(triangle_node <= 2,
"Tried to access bad Triangle Node");
334 uint01 left = triangle_node > 0 ? triangle_node - 1 : 2;
335 uint01 right = triangle_node < 2 ? triangle_node + 1 : 0;
343 return (y *
sqrt(1.0 - ((x * x) / (y * y)))) / x;
360 template<
class t_angle_type>
384 template<
class t_area_type>
385 [[nodiscard]]
constexpr inline t_area_type
area()
const
419 [[nodiscard]]
constexpr t_vertex
center()
const
438 template<u
int01 t_new_dims,
class t_new_type>
456 template<
bool is_normalized,
class t_normal_type = t_type>
463 return cross_product;
515 [[nodiscard]]
constexpr bool contains(
const t_vertex& vertex_point, t_type epsilon = t_type(0.0001))
const
518 for(
uint01 dim = 0; dim < t_dims; dim++)
525 const t_vertex dbp = vertex_point -
vertex(
A);
528 t_type dotca =
dot(dca, dca);
529 t_type dotcaba =
dot(dca, dba);
530 t_type dotcabp =
dot(dca, dbp);
531 t_type dotba =
dot(dba, dba);
532 t_type dotbabp =
dot(dba, dbp);
535 t_type invDenom = (dotca * dotba - dotcaba * dotcaba);
536 t_type u = ((dotba * dotcabp) - (dotcaba * dotbabp)) / invDenom;
537 t_type v = ((dotca * dotbabp) - (dotcaba * dotcabp)) / invDenom;
540 if ((u >= 0) && (v >= 0) && (u + v < 1))
573 switch (object_to_check)
583 if (
equals(edge_a, edge_b, epsilon))
592 const t_vertex vertex_1 =
vertex(object_to_check);
596 if (
equals(vertex_1, vertex_2, epsilon))
609 for (
uint01 i = 0; i <= 2; i++)
735 const t_type dot_1 =
dot(normal_abp, normal_bcp);
736 if(dot_1 >= epsilon + 1 || dot_1 <= -epsilon + 1)
740 const t_type dot_2 =
dot(normal_bcp, normal_cap);
741 if((dot_2 >= epsilon + 1 && dot_2 <= -epsilon + 1))
833 lib_assert(
false,
"Should never arrive here in triangle identity line");
835 lib_assert(
false,
"Should never arrive here in triangle identity line");
908 template<u
int01 t_dims,
class t_type,
class t_vertex>
911 const t_vertex edge0 = tri.
edge(
B,
A).ray();
912 const t_vertex edge1 = tri.
edge(
C,
A).ray();
914 const t_type a =
dot(edge0, edge0);
915 const t_type b =
dot(edge0, edge1);
916 const t_type c =
dot(edge1, edge1);
918 const t_type det = a * c - b * b;
920 return closestPoint(tri, point, edge0, edge1, a, b, c, det);
923 template<u
int01 t_dims,
class t_type,
class t_vertex>
924 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)
926 const t_vertex v0(tri.
vertex(
A) - point);
927 const t_type d =
dot(edge0, v0);
928 const t_type e =
dot(edge1, v0);
930 t_type s = b * e - c * d;
931 t_type t = b * d - a * e;
976 t_type numer = tmp1 - tmp0;
977 t_type denom = a - 2 * b + c;
983 t =
clip(-e / c, 0.f, 1.f);
991 t_type numer = c + e - b - d;
992 t_type denom = a - 2 * b + c;
1004 t_type numer = c + e - b - d;
1005 t_type denom = a - 2 * b + c;
1011 return tri.
vertex(
A) + s * edge0 + t * edge1;
1031 template<
bool t_has_winding, u
int01 t_dims,
class t_type,
class t_vertex>
1046 else if(!t_has_winding && tri_a.
vertex(
B) == tri_b.
vertex((
C + dif) % 3))
1057 template<u
int01 t_dims,
class t_type,
class t_vector>
1065 template<u
int01 t_dims,
class t_type>
1066 static constexpr bool isNaN(
const Triangle<t_dims, t_type>& value)
1068 for (
uint01 dim = 0; dim < t_dims; ++dim)
1070 if (isNaN(value[dim]))
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
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:815
Stores an angle in an optimized format.
Definition StringStream.h:352
A line segment represented by two vertices, a start and end.
Definition Line.hpp:55
Definition Triangle.hpp:68
static constexpr TriangleLocation NextVertexCCW(TriangleLocation location)
Returns the point location counter-clockwise to given point location.
Definition Triangle.hpp:96
static constexpr TriangleLocation oppositeLocation(TriangleLocation location)
Definition Triangle.hpp:70
static constexpr TriangleLocation NextVertexCW(TriangleLocation location)
Returns the point location clockwise to given point location.
Definition Triangle.hpp:118
Definition Triangle.hpp:143
constexpr Vector< t_dims, t_normal_type > normal() const
Definition Triangle.hpp:457
constexpr Triangle< t_new_dims, t_new_type > as() const
Definition Triangle.hpp:439
constexpr bool contains(const Vector< t_dims - 1, t_type > &p) const
Definition Triangle.hpp:481
constexpr t_vertex & vertex(uint01 triangle_node)
Definition Triangle.hpp:232
constexpr t_vertex centroid() const
Definition Triangle.hpp:402
constexpr LineSegment< t_dims, t_type, t_vertex > edge(TriangleLocation location) const
Edges the given location.
Definition Triangle.hpp:297
constexpr uint01 vertexIndex(const t_vertex &p) const
Definition Triangle.hpp:638
constexpr const t_vertex & vertex(TriangleLocation triangle_node) const
Vertices the given triangle node.
Definition Triangle.hpp:206
constexpr TriangleLocation getLocation(const LineSegment< t_dims, t_type, t_vertex > &line, t_type epsilon=cast< t_type >(0)) const
Definition Triangle.hpp:746
constexpr t_area_type area() const
Definition Triangle.hpp:385
constexpr Triangle(const t_vertex &vector)
Definition Triangle.hpp:156
constexpr TriangleLocation getIdentityOf(const LineSegment< t_dims, t_type, t_vertex > &line) const
Definition Triangle.hpp:691
constexpr TriangleLocation getLocation(const t_vertex &p, t_type epsilon=cast< t_type >(0)) const
Definition Triangle.hpp:722
constexpr const t_vertex & vertex(uint01 triangle_node) const
Definition Triangle.hpp:253
constexpr TriangleLocation sharesObject(TriangleLocation object_to_check, const Triangle< t_dims, t_type, t_vertex > &tri, t_type epsilon=0) const
Definition Triangle.hpp:571
constexpr Triangle(const t_type &a)
Definition Triangle.hpp:148
constexpr TriangleLocation getIdentityOf(const LineSegment< t_dims, t_type, t_vertex > &line, t_type epsilon) const
Definition Triangle.hpp:660
constexpr Triangle(const t_vertex &a, const t_vertex &b, const t_vertex &c)
Definition Triangle.hpp:160
constexpr fltp08 tan(uint01 triangle_node) const
Definition Triangle.hpp:331
bool hasVertex(const t_vertex &point) const
Definition Triangle.hpp:883
constexpr bool contains(const t_vertex &vertex_point, t_type epsilon=t_type(0.0001)) const
Definition Triangle.hpp:515
constexpr void invert()
Definition Triangle.hpp:849
constexpr Triangle()
Definition Triangle.hpp:145
constexpr Triangle(const t_type &a, const t_type &b, const t_type &c)
Definition Triangle.hpp:152
constexpr t_vertex center() const
Definition Triangle.hpp:419
constexpr const t_vertex & nextVertexCCW(const t_vertex &point) const
Definition Triangle.hpp:865
constexpr TriangleLocation getIdentityOf(const t_vertex &p, t_type epsilon) const
Definition Triangle.hpp:652
constexpr t_vertex & vertex(TriangleLocation triangle_node)
Vertices the given triangle node.
Definition Triangle.hpp:180
constexpr Angle< t_angle_type > angle(TriangleLocation location) const
Definition Triangle.hpp:361
constexpr LineSegment< t_dims, t_type, t_vertex > edge(uint01 triangle_node_a, uint01 triangle_node_b) const
Definition Triangle.hpp:276
constexpr TriangleLocation getIdentityOf(const t_vertex &p) const
Definition Triangle.hpp:645
constexpr const t_vertex & nextVertexCW(const t_vertex &point) const
Definition Triangle.hpp:879
constexpr Angle< t_angle_type > angle(uint01 triangle_node) const
Definition Triangle.hpp:323
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_type magnitudeSquared() const
Definition Vector.hpp:458
constexpr Vector< t_dims, t_norm_type > normalized(Vector< t_dims, t_norm_type > value_if_nan=Constant< Vector< t_dims, t_norm_type > >::NaN) const
Definition Vector.hpp:500
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:116
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:240
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1096
TriangleLocation
Values that represent triangle locations.
Definition Triangle.hpp:52
@ angle_c
Definition Triangle.hpp:62
@ edge_ab
Definition Triangle.hpp:54
@ mixed_location_tri
Definition Triangle.hpp:64
@ angle_b
Definition Triangle.hpp:61
@ vertex_a
Definition Triangle.hpp:57
@ inside_tri
Definition Triangle.hpp:63
@ angle_a
Definition Triangle.hpp:60
@ tri_location_nan
Definition Triangle.hpp:65
@ edge_bc
Definition Triangle.hpp:55
@ edge_ca
Definition Triangle.hpp:56
@ vertex_b
Definition Triangle.hpp:58
@ outside_tri
Definition Triangle.hpp:53
@ vertex_c
Definition Triangle.hpp:59
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
@ RADIANS
Definition Angle.h:65
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:42
constexpr Vector< t_dims, t_type > closestPoint(const Triangle< t_dims, t_type, t_vertex > &tri, const t_vertex &point)
Definition Triangle.hpp:909
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
Definition VectorFunctions.hpp:954
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1309
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
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:819
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
@ C
Definition BaseValues.hpp:205
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67
Definition BaseValues.hpp:272
static const t_type Min
Definition BaseValues.hpp:276
static const t_type Max
Definition BaseValues.hpp:278
static const t_type NaN
Definition BaseValues.hpp:274