33#include <NDEVR/Polygon.h>
34#include <NDEVR/Polyline.h>
35#include <NDEVR/Plane.h>
36#include <NDEVR/Intersection.h>
45 template<u
int01 t_dims,
class t_type,
class t_vertex>
49 for (
uint01 dim = 0; dim < t_dims; ++dim)
51 if (vertex[dim] < bounds[MIN][dim])
53 t_type val = bounds[MIN][dim] - vertex[dim];
54 distance += val * val;
56 else if (vertex[dim] > bounds[MAX][dim] )
58 t_type val = vertex[dim] - bounds[MAX][dim];
59 distance += val * val;
64 template<u
int01 t_dims,
class t_type,
class t_vertex>
67 return distanceSquared(bounds, vertex);
71 template<u
int01 t_dims,
class t_type,
class t_vertex_a,
class t_vertex_b>
74 if (bounds.contains(line))
78 for (
uint01 i = 0; i < t_dims; ++i)
80 if ( bounds.doesIntersect(line.vertex(A)[i] - bounds[MIN][i], line.vertex(B)[i] - bounds[MIN][i], line.vertex(A), v, i)
81 || bounds.doesIntersect(line.vertex(A)[i] - bounds[MAX][i], line.vertex(B)[i] - bounds[MAX][i], line.vertex(A), v, i))
87 t_type p1 =
getMax(t_type(0), t1.template dimensionalValue<MIN>(), t2.template dimensionalValue<MIN>());
88 t_type p2 =
getMax(t_type(0),
getMin(t1.template dimensionalValue<MAX>(), t2.template dimensionalValue<MAX>()));
90 t_type t =
getMax(t_type(0), ((val - p) * v).sum() / v.magnitudeSquared());
91 val = p + v * t - val;
92 return val.magnitudeSquared();
95 template<u
int01 t_dims,
class t_type,
class t_vertex_a,
class t_vertex_b>
98 return distanceSquared(line, bounds);
101 template<u
int01 t_dims,
class t_type,
class t_vertex>
105 for (
uint01 dim = 0; dim < t_dims; ++dim)
107 if (a[MAX][dim] < b[MIN][dim])
109 t_type val = b[MIN][dim] - a[MAX][dim];
110 distance += val * val;
112 else if(a[MIN][dim] < b[MAX][dim])
114 t_type val = a[MIN][dim] - b[MAX][dim];
115 distance += val * val;
120 template<u
int01 t_dims,
class t_type,
class t_vertex>
123 return left.template closestPoints<t_type>(right, epsilon).lengthSquared();
129 template<u
int01 t_dims,
class t_type,
class t_vertex>
132 return distanceSquared(vertex, ClosestPoint(tri, vertex));
134 template<u
int01 t_dims,
class t_type,
class t_vertex>
135 constexpr t_type distanceSquared(
const t_vertex& vertex,
const Triangle<t_dims, t_type, t_vertex>& tri)
137 return distanceSquared(vertex, ClosestPoint(tri, vertex));
139 template<u
int01 t_dims,
class t_type,
class t_vertex>
142 if (classify(line, tri) != IntersectionTypes::e_outside)
146 t_type dist_a = distanceSquared(line, tri.edge(A, B));
147 t_type dist_b = distanceSquared(line, tri.edge(B, C));
148 t_type dist_c = distanceSquared(line, tri.edge(C, A));
149 return getMin(dist_a, dist_b, dist_c);
151 template<u
int01 t_dims,
class t_type,
class t_vertex>
154 return distanceSquared(line, tri);
158 template<u
int01 t_dims,
class t_type,
class t_vertex>
161 lib_assert(
false,
"Not yet finished");
162 return Constant<t_type>::Invalid;
164 template<u
int01 t_dims,
class t_type,
class t_vertex>
167 lib_assert(
false,
"Not yet finished");
168 return Constant<t_type>::Invalid;
170 template<
class epsilon_type, u
int01 t_dims,
class t_type,
class t_vertex>
175 template<
class t_type,
class t_other_type>
176 t_type distanceSquared(
const t_other_type& original_object,
const Polygon<t_type>& poly)
178 auto object = original_object.template as<2, t_type>();
179 if (classify(poly,
object) != IntersectionTypes::e_outside)
185 t_type min = Constant<t_type>::Max;
186 for (
uint04 i = 0; i < poly.vertexCount(); i++)
188 const t_type current = distanceSquared(poly.edge(i),
object);
197 template<
class t_type,
class t_other_type>
198 t_type distanceSquared(
const Polygon<t_type>& poly,
const t_other_type& original_object)
200 return distanceSquared(original_object, poly);
203 template<u
int01 t_dims,
class t_type,
class t_other_type>
206 t_type min = Constant<t_type>::Max;
207 if (poly.vertexCount() == 0)
208 return Constant<fltp08>::Invalid;
209 if (poly.vertexCount() == 1)
210 return distanceSquared(poly.vertex(0), original_object);;
211 for (
uint04 i = 0; i < poly.vertexCount() - 1; i++)
213 const t_type current = distanceSquared(poly.segment(i), original_object);
221 template<u
int01 t_dims,
class t_type,
class t_other_type>
224 return distanceSquared(original_object, poly);
226 template<
class t_precision, u
int01 t_dims,
class t_type,
class t_vertex>
232 template<u
int01 t_dims,
class t_type,
class t_vertex>
235 return abs(
dot(plane.normal, vertex) + plane.d);
237 template<u
int01 t_dims,
class t_type,
class t_vertex>
240 return abs(
dot(plane.normal, vertex) + plane.d);
242 template<u
int01 t_dims,
class t_type,
class t_vertex>
245 t_type d = distance(plane, vertex);
248 template<u
int01 t_dims,
class t_type,
class t_vertex>
251 t_type d = distance(plane, vertex);
254 template<
class t_precision, u
int01 t_dims,
class t_type,
class t_vertex>
260 template<u
int01 t_dims,
class t_type,
class t_vertex>
266 const t_type s =
dot(plane.normal, c) + plane.d;
267 const t_type r =
dot(
abs(plane.normal), e);
272 template<u
int01 t_dims,
class t_type,
class t_vertex>
275 return distance(plane, bounds);
278 template<u
int01 t_dims,
class t_type,
class t_vertex>
281 auto d = distance(plane, bounds);;
285 template<u
int01 t_dims,
class t_type,
class t_vertex>
288 auto d = distance(plane, bounds);;
A specification of upper and lower bounds in N-dimensions.
Dummy class for including distance functions.
Logic for a given plane or N-dimensions.
A sequence of connected line segments defined by ordered vertices along a path.
A three-vertex polygon representing a triangle in N-dimensional space.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A point in N-dimensional space, used primarily for spatial location information.
The primary namespace for the NDEVR SDK.
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...
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 > ...
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
t_type sqrt(const t_type &value)
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.