33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
53 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
60 :
Vector<2, t_vertex>(p1, p2)
63 :
Vector<2, t_vertex>(line)
77 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex = Vertex<t_new_dims, t_new_type>>
97 template<
class t_
inter_type>
98 constexpr inline t_vertex
pointAt(t_inter_type index)
const
134 constexpr inline t_vertex
ray()
const
212 template<
class t_precision = t_type>
217 return (
equals(ray_1, ray_2, epsilon) ||
equals(ray_1, -ray_2, epsilon));
236 template<
class t_precision = t_type>
257 template<
class t_precision = t_type>
258 constexpr bool isCollinear(
const t_vertex& vert, t_precision epsilon = 0)
const
262 return (
equals(ray_1, ray_2, epsilon) ||
equals(ray_1, -ray_2, epsilon));
282 template<
class t_precision,
class t_other_vertex>
289 const t_precision a(
dot(u, u));
290 const t_precision b(
dot(u, v));
291 const t_precision c(
dot(v, v));
293 const t_precision d(
dot(u, w));
294 const t_precision e(
dot(v, w));
296 const t_precision
D((a * c) - (b * b));
307 if (sN <
static_cast<t_precision
>(0))
309 sN =
static_cast<t_precision
>(0);
322 sN =
static_cast<t_precision
>(0);
323 sD =
static_cast<t_precision
>(1);
328 if (tN <
static_cast<t_precision
>(0))
330 tN =
static_cast<t_precision
>(0);
333 sN =
static_cast<t_precision
>(0);
346 if ((-d + b) <
static_cast<t_precision
>(0))
347 sN =
static_cast<t_precision
>(0);
348 else if ((-d + b) > a)
358 t_precision sc =
abs(sN) <= epsilon ?
static_cast<t_precision
>(0) : sN / sD;
359 t_precision tc =
abs(sN) <= epsilon ?
static_cast<t_precision
>(0) : tN / tD;
389 t_type
sum = (ray_1 * ray_2).
sum();
392 if (mag_squared != 0)
416 template<
class t_precision = t_type>
455 template<
class t_
inter_type>
460 template<
class t_
inter_type>
487 template<
class t_precision = t_type>
507 return ray().magnitudeSquared();
528 template<
class t_precision = t_type>
552 template<
class t_precision = t_type>
556 if(!
isNaN(intersection_location))
577 template<
class t_precision = t_type>
598 template<
bool t_clip,
class t_precision>
609 else if (value <=
vertex(
B)[dim])
616 else if (value <=
vertex(
A)[dim])
641 template<
bool t_clip,
class t_precision>
652 else if (value <=
vertex(
B)[dim])
659 else if (value <=
vertex(
A)[dim])
663 const t_precision dt =
vertex(
A)[dim] - value;
664 const t_precision dy = value -
vertex(
B)[dim];
687 template<
class t_buffer_type>
690 if(vertices.size() < 2)
692 if(vertices.size() == 2)
695 t_vertex total_vector(0);
696 t_type total_volume = 0;
697 t_type total_x_sqr = 0;
698 for(
uint04 i = 0; i < vertices.size(); i++)
700 total_vector += vertices[i];
701 total_x_sqr += vertices[i][dim_0] * vertices[i][dim_0];
702 total_volume += vertices[i][dim_0] * vertices[i][dim_1];
705 const t_type x_sqr = total_vector[dim_0] * total_vector[dim_0];
706 const t_type a = (total_vector[dim_1] * total_x_sqr - total_vector[dim_0] * total_volume) / (vertices.size() * total_x_sqr - x_sqr);
708 const t_type b = (vertices.size() * total_volume - total_vector[dim_0] * total_vector[dim_1]) / (vertices.size() * total_x_sqr - x_sqr);
710 const t_vertex p1(vertices[0]);
711 const t_vertex p2 = vertices.getLast();
712 p1[dim_1] = a + b * p1[dim_0];
713 p2[dim_1] = a + b * p2[dim_0];
737 template<u
int01 t_dims,
class t_type,
class t_vertex>
740 const t_vertex v_t(vertex - line.
vertex(
A));
741 const t_type t =
dot(v_t, ray);
743 return v_t.magnitudeSquared();
744 else if (t >= dot_ray)
748 t_vertex vc = (ray * t) / dot_ray + line.
vertex(
A);
768 template<u
int01 t_dims,
class t_type,
class t_vertex>
771 const t_vertex ray_value(line.
ray());
772 const t_type dot_ray =
dot(ray_value, ray_value);
793 template<u
int01 t_dims,
class t_type,
class t_vertex>
818 template<u
int01 t_dims,
class t_type,
class t_vertex>
821 if (
equals(left[
A], right[
A], epsilon))
823 return (
equals(left[
B], right[
B], epsilon));
825 if (
equals(left[
B], right[
A], epsilon))
827 return (
equals(left[
A], right[
B], epsilon));
836 template<u
int01 t_dims,
class t_type>
837 static constexpr bool isNaN(
const LineSegment<t_dims, t_type>& value)
839 for (
uint01 dim = 0; dim < 2; ++dim)
841 if (isNaN(value[dim]))
847 template<u
int01 t_dims,
class t_type,
class t_vector>
A line segment represented by two vertices, a start and end.
Definition Line.hpp:55
constexpr LineSegment< t_dims, t_type > extend(const t_type &a_extension, const t_type &b_extension) const
Definition Line.hpp:471
constexpr Vector< t_dims, t_precision > intersection(const LineSegment &r, t_precision epsilon=0) const
Definition Line.hpp:529
constexpr t_vertex ray() const
Definition Line.hpp:134
constexpr LineSegment()
Definition Line.hpp:57
constexpr t_precision length() const
Definition Line.hpp:488
constexpr t_vertex pointAt(t_precision value, uint01 dim, const t_vertex &nan_return=Constant< t_vertex >::NaN) const
Definition Line.hpp:642
constexpr LineSegment(const t_vertex &p1, const t_vertex &p2)
Definition Line.hpp:59
constexpr LineSegment< t_dims, t_type > scale(const t_inter_type &scale) const
Definition Line.hpp:456
constexpr bool isCollinear(const LineSegment< t_dims, t_type > &line, t_precision epsilon=0) const
Definition Line.hpp:237
constexpr t_vertex midpoint() const
Definition Line.hpp:115
constexpr t_precision intersectionPosition(const LineSegment< t_dims, t_type > &segment) const
Definition Line.hpp:553
constexpr t_precision getLocationAt(t_precision value, uint01 dim) const
Definition Line.hpp:599
static constexpr LineSegment createBestFitLine(const t_buffer_type &vertices, uint01 dim_0, uint01 dim_1)
Definition Line.hpp:688
constexpr bool isCollinear(const t_vertex &vert, t_precision epsilon=0) const
Definition Line.hpp:258
constexpr LineSegment(const Vector< 2, t_vertex > &line)
Definition Line.hpp:62
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:171
constexpr t_vertex & vertex(uint01 index)
Definition Line.hpp:191
constexpr LineSegment< t_dims, t_type > extend(const t_type &extension) const
Definition Line.hpp:466
t_precision distanceSquared(const LineSegment< t_dims, t_type, t_vertex > &right, const t_precision &epsilon=cast< t_precision >(0)) const
Definition Line.hpp:417
constexpr t_type lengthSquared() const
Definition Line.hpp:505
constexpr t_vertex center() const
Definition Line.hpp:151
constexpr t_vertex closestValue(const t_vertex &p) const
Definition Line.hpp:412
constexpr t_vertex pointAt(t_inter_type index) const
Definition Line.hpp:98
constexpr bool isParallel(const LineSegment< t_dims, t_type, t_vertex > &line, t_precision epsilon=0) const
Definition Line.hpp:213
constexpr LineSegment< t_dims, t_type > scale(const t_inter_type &a_scale, const t_inter_type &b_scale) const
Definition Line.hpp:461
constexpr t_type closestPos(const t_vertex &p) const
Definition Line.hpp:384
constexpr LineSegment< t_new_dims, t_new_type, t_new_vertex > as() const
Definition Line.hpp:78
constexpr bool intersects(const LineSegment &segment, t_precision epsilon=cast< t_precision >(0.001)) const
Definition Line.hpp:578
constexpr LineSegment< t_dims, t_precision > closestPoints(const LineSegment< t_dims, t_type, t_other_vertex > &l2, t_precision epsilon=0) const
Definition Line.hpp:283
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
constexpr t_magnitude_type magnitude() const
Definition Vector.hpp:482
constexpr Vector() noexcept
Definition Vector.hpp:64
constexpr t_type sum() const
Definition Vector.hpp:545
constexpr t_type & operator[](uint01 dimension_index)
Definition Vector.hpp:568
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
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:42
constexpr t_type distanceSquaredOptimized(const LineSegment< t_dims, t_type, t_vertex > &line, const t_vertex &vertex, const t_vertex &ray, const t_type &dot_ray)
Definition Line.hpp:738
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
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 Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
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
@ D
Definition BaseValues.hpp:207
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