33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Vertex.h>
47 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
54 :
Vector<2, t_vertex>(p1, p2)
57 :
Vector<2, t_vertex>(line)
69 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex = Vertex<t_new_dims, t_new_type>>
87 template<
class t_
inter_type>
88 constexpr inline t_vertex
pointAt(t_inter_type index)
const
120 constexpr inline t_vertex
ray()
const
188 template<
class t_precision = t_type>
193 return (
equals(ray_1, ray_2, epsilon) ||
equals(ray_1, -ray_2, epsilon));
210 template<
class t_precision = t_type>
229 template<
class t_precision = t_type>
230 constexpr bool isCollinear(
const t_vertex& vert, t_precision epsilon = 0)
const
234 return (
equals(ray_1, ray_2, epsilon) ||
equals(ray_1, -ray_2, epsilon));
252 template<
class t_precision,
class t_other_vertex>
259 const t_precision a(
dot(u, u));
260 const t_precision b(
dot(u, v));
261 const t_precision c(
dot(v, v));
263 const t_precision d(
dot(u, w));
264 const t_precision e(
dot(v, w));
266 const t_precision
D((a * c) - (b * b));
277 if (sN <
static_cast<t_precision
>(0))
279 sN =
static_cast<t_precision
>(0);
292 sN =
static_cast<t_precision
>(0);
293 sD =
static_cast<t_precision
>(1);
298 if (tN <
static_cast<t_precision
>(0))
300 tN =
static_cast<t_precision
>(0);
303 sN =
static_cast<t_precision
>(0);
316 if ((-d + b) <
static_cast<t_precision
>(0))
317 sN =
static_cast<t_precision
>(0);
318 else if ((-d + b) > a)
328 t_precision sc =
abs(sN) <= epsilon ?
static_cast<t_precision
>(0) : sN / sD;
329 t_precision tc =
abs(sN) <= epsilon ?
static_cast<t_precision
>(0) : tN / tD;
357 t_type
sum = (ray_1 * ray_2).
sum();
360 if (mag_squared != 0)
382 template<
class t_precision = t_type>
417 template<
class t_
inter_type>
422 template<
class t_
inter_type>
447 template<
class t_precision = t_type>
465 return ray().magnitudeSquared();
484 template<
class t_precision = t_type>
506 template<
class t_precision = t_type>
529 template<
class t_precision = t_type>
548 template<
bool t_clip,
class t_precision>
559 else if (value <=
vertex(
B)[dim])
566 else if (value <=
vertex(
A)[dim])
589 template<
bool t_clip,
class t_precision>
600 else if (value <=
vertex(
B)[dim])
607 else if (value <=
vertex(
A)[dim])
611 const t_precision dt =
vertex(
A)[dim] - value;
612 const t_precision dy = value -
vertex(
B)[dim];
633 template<
class t_buffer_type>
636 if(vertices.size() < 2)
638 if(vertices.size() == 2)
641 t_vertex total_vector(0);
642 t_type total_volume = 0;
643 t_type total_x_sqr = 0;
644 for(
uint04 i = 0; i < vertices.size(); i++)
646 total_vector += vertices[i];
647 total_x_sqr += vertices[i][dim_0] * vertices[i][dim_0];
648 total_volume += vertices[i][dim_0] * vertices[i][dim_1];
651 const t_type x_sqr = total_vector[dim_0] * total_vector[dim_0];
652 const t_type a = (total_vector[dim_1] * total_x_sqr - total_vector[dim_0] * total_volume) / (vertices.size() * total_x_sqr - x_sqr);
654 const t_type b = (vertices.size() * total_volume - total_vector[dim_0] * total_vector[dim_1]) / (vertices.size() * total_x_sqr - x_sqr);
656 const t_vertex p1(vertices[0]);
657 const t_vertex p2 = vertices.getLast();
658 p1[dim_1] = a + b * p1[dim_0];
659 p2[dim_1] = a + b * p2[dim_0];
681 template<u
int01 t_dims,
class t_type,
class t_vertex>
684 const t_vertex v_t(vertex - line.
vertex(
A));
685 const t_type t =
dot(v_t, ray);
687 return v_t.magnitudeSquared();
688 else if (t >= dot_ray)
692 t_vertex vc = (ray * t) / dot_ray + line.
vertex(
A);
710 template<u
int01 t_dims,
class t_type,
class t_vertex>
713 const t_vertex ray_value(line.
ray());
714 const t_type dot_ray =
dot(ray_value, ray_value);
733 template<u
int01 t_dims,
class t_type,
class t_vertex>
756 template<u
int01 t_dims,
class t_type,
class t_vertex>
759 if (
equals(left[
A], right[
A], epsilon))
761 return (
equals(left[
B], right[
B], epsilon));
763 if (
equals(left[
B], right[
A], epsilon))
765 return (
equals(left[
A], right[
B], epsilon));
774 template<u
int01 t_dims,
class t_type>
775 static constexpr bool IsInvalid(
const LineSegment<t_dims, t_type>& value)
777 for (
uint01 dim = 0; dim < 2; ++dim)
779 if (IsInvalid(value[dim]))
785 template<u
int01 t_dims,
class t_type,
class t_vector>
786 struct Constant<LineSegment<t_dims, t_type, t_vector>>
A line segment represented by two vertices, a start and end.
Definition Line.hpp:49
constexpr LineSegment< t_dims, t_type > extend(const t_type &a_extension, const t_type &b_extension) const
Definition Line.hpp:433
constexpr Vector< t_dims, t_precision > intersection(const LineSegment &r, t_precision epsilon=0) const
Definition Line.hpp:485
constexpr t_vertex ray() const
Definition Line.hpp:120
constexpr LineSegment()
Definition Line.hpp:51
constexpr t_vertex pointAt(t_precision value, uint01 dim, const t_vertex &nan_return=Constant< t_vertex >::Invalid) const
Definition Line.hpp:590
constexpr t_precision length() const
Definition Line.hpp:448
constexpr LineSegment(const t_vertex &p1, const t_vertex &p2)
Definition Line.hpp:53
constexpr LineSegment< t_dims, t_type > scale(const t_inter_type &scale) const
Definition Line.hpp:418
constexpr bool isCollinear(const LineSegment< t_dims, t_type > &line, t_precision epsilon=0) const
Definition Line.hpp:211
constexpr t_vertex midpoint() const
Definition Line.hpp:103
constexpr t_precision intersectionPosition(const LineSegment< t_dims, t_type > &segment) const
Definition Line.hpp:507
constexpr t_precision getLocationAt(t_precision value, uint01 dim) const
Definition Line.hpp:549
static constexpr LineSegment createBestFitLine(const t_buffer_type &vertices, uint01 dim_0, uint01 dim_1)
Definition Line.hpp:634
constexpr bool isCollinear(const t_vertex &vert, t_precision epsilon=0) const
Definition Line.hpp:230
constexpr LineSegment(const Vector< 2, t_vertex > &line)
Definition Line.hpp:56
constexpr const t_vertex & vertex(uint01 index) const
Definition Line.hpp:152
constexpr t_vertex & vertex(uint01 index)
Definition Line.hpp:169
constexpr LineSegment< t_dims, t_type > extend(const t_type &extension) const
Definition Line.hpp:428
t_precision distanceSquared(const LineSegment< t_dims, t_type, t_vertex > &right, const t_precision &epsilon=cast< t_precision >(0)) const
Definition Line.hpp:383
constexpr t_type lengthSquared() const
Definition Line.hpp:463
constexpr t_vertex center() const
Definition Line.hpp:135
constexpr t_vertex closestValue(const t_vertex &p) const
Definition Line.hpp:378
constexpr t_vertex pointAt(t_inter_type index) const
Definition Line.hpp:88
constexpr bool isParallel(const LineSegment< t_dims, t_type, t_vertex > &line, t_precision epsilon=0) const
Definition Line.hpp:189
constexpr LineSegment< t_dims, t_type > scale(const t_inter_type &a_scale, const t_inter_type &b_scale) const
Definition Line.hpp:423
constexpr t_type closestPos(const t_vertex &p) const
Definition Line.hpp:352
constexpr LineSegment< t_new_dims, t_new_type, t_new_vertex > as() const
Definition Line.hpp:70
constexpr bool intersects(const LineSegment &segment, t_precision epsilon=cast< t_precision >(0.001)) const
Definition Line.hpp:530
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:253
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr t_magnitude_type magnitude() const
Definition Vector.hpp:448
constexpr Vector() noexcept
Definition Vector.hpp:62
constexpr t_type sum() const
Definition Vector.hpp:505
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 & operator[](uint01 dimension_index)
Definition Vector.hpp:526
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
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_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:682
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
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
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
@ D
Definition BaseValues.hpp:174
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