33#include <NDEVR/BaseValues.h>
34#include <NDEVR/Buffer.h>
35#include <NDEVR/Vertex.h>
36#include <NDEVR/Bounds.h>
37#include <NDEVR/LineSegment.h>
56 template<u
int01 t_dims,
class t_type,
class t_vertex = Vertex<t_dims, t_type>>
63 , m_cache_length(
Constant<t_type>::NaN)
69 , m_cache_length(
Constant<t_type>::NaN)
73 : m_vertices(polygon.m_vertices)
74 , m_cache_bounds(polygon.m_cache_bounds)
75 , m_cache_length(polygon.m_cache_length)
83 std::swap(m_vertices, polygon.m_vertices);
84 std::swap(m_cache_bounds, polygon.m_cache_bounds);
85 std::swap(m_cache_length, polygon.m_cache_length);
102 if (
isNaN(m_cache_bounds))
105 for (
uint04 i = 0; i < m_vertices.
size(); i++)
110 return m_cache_bounds;
115 return m_vertices.
begin();
119 return m_vertices.
begin();
124 return m_vertices.
begin(index);
128 return m_vertices.
begin(index);
133 return m_vertices.
end();
135 decltype(
auto)
end()
const
137 return m_vertices.
end();
157 return m_vertices[index];
211 return m_vertices.
size();
228 if (m_vertices.
size() == 0)
231 return m_vertices.
size() - 1;
310 if (
segment(index).
template isParallel<t_type>(
segment(index - 1), 0.00001))
317 if (
segment(index - 1).
template isParallel<t_type>(
segment(index - 2), 0.00001))
342 if (m_vertices[index] !=
vertex)
344 m_vertices[index] =
vertex;
381 return m_vertices.
last();
417 else if (i > 0 &&
segment(i).
template isParallel<t_type>(
segment(i - 1), 0.00001))
451 template<u
int01 t_new_dims,
class t_new_type,
class t_new_vertex_type = Vertex<t_new_dims, t_new_type>>
473 template<
class t_precision>
476 if (
isNaN(m_cache_length))
492 return m_cache_length;
510 template<
class t_
inter_type>
511 constexpr inline t_vertex
pointAt(t_inter_type value)
const
521 fltp08 accumulated_distance = 0;
525 if (accumulated_distance + local_distance > value)
527 fltp08 line_percent =
clip((value - accumulated_distance) / local_distance, 0.0, 1.0);
532 accumulated_distance += local_distance;
554 return (m_vertices == polygon.m_vertices);
558 m_vertices = polygon.m_vertices;
559 m_cache_length = polygon.m_cache_length;
560 m_cache_bounds = polygon.m_cache_bounds;
565 std::swap(m_vertices, polygon.m_vertices);
566 m_cache_length = polygon.m_cache_length;
567 m_cache_bounds = polygon.m_cache_bounds;
576 t_type remainder_distance(0);
581 if (seg_length + remainder_distance >
length)
583 t_type local_accumulation =
length - remainder_distance;
584 lib_assert(local_accumulation > 0.0,
"Bad accumulation");
585 auto ray =
segment(i).ray().template normalized<fltp08>();
589 local_accumulation +=
length;
590 }
while (local_accumulation < seg_length);
591 remainder_distance =
length + seg_length - local_accumulation;
593 else if (!
isNaN(seg_length))
595 remainder_distance += seg_length;
602 t_type dist_squared = d * d;
616 if(ap != 0.0 && !
equals(ab, ap, 0.000001) && !
equals(ab, -ap, 0.000001))
620 t_type sum = (ab * ap).sum();
625 new_poly.add(new_distance * normal + p0);
630 new_poly.add(d * normal + new_poly.lastVertex());
644 t_type accumulated_distance = 0;
648 while (accumulated_distance + local_distance > max_distance)
650 auto direction = (
vertex(i) - new_poly.lastVertex()).
template normalized<t_type>();
651 t_type adjusted_distance = max_distance - accumulated_distance;
653 auto final_vertex = adjusted_distance * direction + new_poly.lastVertex();
654 new_poly.add(final_vertex);
655 new_polys.
add(new_poly);
658 new_poly.add(final_vertex);
659 local_distance = local_distance - adjusted_distance;
660 accumulated_distance = 0.0;
664 accumulated_distance += local_distance;
666 new_polys.
add(new_poly);
680 line = intersection(
bounds, line);
683 if (polyline.vertexCount() == 0 || polyline.lastVertex() != line.vertex(
A))
684 polyline.add(line.vertex(
A));
685 polyline.add(line.vertex(
B));
703 inline void invalidateCache()
const
722 void updateVertices(
const Buffer<t_vertex>&
vertices)
729 Buffer<t_vertex> m_vertices;
739 mutable Bounds<t_dims, t_type, t_vertex> m_cache_bounds;
749 mutable t_type m_cache_length;
#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
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
constexpr void addToBounds(const t_vertex &vector)
Adds to the bounds such that the new bounds fully encompasses the argument.
Definition Bounds.hpp:498
constexpr bool contains(const t_type &value) const
Query if this object contains the given value.
Definition Bounds.hpp:329
constexpr bool intersects(const Bounds< t_dims, t_type, t_other_vertex_type > &bounds) const
Query if this object intersects the given pair.
Definition Bounds.hpp:737
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
constexpr t_index_type size() const
Definition Buffer.hpp:1461
decltype(auto) last()
Definition Buffer.hpp:977
decltype(auto) end()
Definition Buffer.hpp:746
void removeIndex(t_index_type location)
Definition Buffer.hpp:1037
decltype(auto) begin()
Definition Buffer.hpp:504
void clear()
Definition Buffer.hpp:572
void removeLast()
Definition Buffer.hpp:1099
A line segment represented by two vertices, a start and end.
Definition Line.hpp:55
constexpr t_vertex ray() const
Definition Line.hpp:134
Definition MemoryManager.h:283
A polyline which stores vertex information for many points along a given path.
Definition CoordinateProjectionManager.h:44
Polyline(Buffer< t_vertex > &vertices)
Definition PolyLine.hpp:66
void simplify()
Definition PolyLine.hpp:406
Polyline & operator=(const Polyline &polygon)
Definition PolyLine.hpp:556
Polyline & operator=(Polyline &&polygon) noexcept
Definition PolyLine.hpp:563
t_precision length() const
Definition PolyLine.hpp:474
Buffer< Polyline< t_dims, t_type >, uint04, ObjectAllocator< false > > breakIntoPolylinesByLength(t_type max_distance) const
Definition PolyLine.hpp:637
decltype(auto) begin(uint04 index)
Definition PolyLine.hpp:126
Bounds< t_dims, t_type, t_vertex > bounds() const
Definition PolyLine.hpp:100
uint04 vertexCount() const
Definition PolyLine.hpp:209
void replace(uint04 index, const t_vertex &vertex)
Definition PolyLine.hpp:340
constexpr t_vertex pointAtLength(fltp08 value) const
Definition PolyLine.hpp:517
uint04 segmentCount() const
Definition PolyLine.hpp:226
Polyline(Polyline &&polygon) noexcept
Definition PolyLine.hpp:78
void removeLastVertex()
Definition PolyLine.hpp:393
bool operator==(const Polyline &polygon) const
Definition PolyLine.hpp:552
void addAndSimplify(uint04 index, const t_vertex &vertex)
Definition PolyLine.hpp:294
void setVertices(const Buffer< t_vertex > &vertices)
Definition PolyLine.hpp:247
void remove(uint04 index)
Definition PolyLine.hpp:362
decltype(auto) end()
Definition PolyLine.hpp:131
Polyline< t_dims, t_type > clipPolyline(const Bounds< t_vertex::NumberOfDimensions(), t_type > &bounds) const
Definition PolyLine.hpp:670
Polyline< t_dims, t_type > breakIntoSegmentsByDistance(t_type d) const
Definition PolyLine.hpp:600
Polyline(uint04 size=0)
Definition PolyLine.hpp:60
Polyline< t_dims, t_type > breakIntoSegmentsByLength(t_type length) const
Definition PolyLine.hpp:570
LineSegment< t_dims, t_type, t_vertex > segment(uint04 index) const
Definition PolyLine.hpp:175
decltype(auto) begin()
Definition PolyLine.hpp:113
constexpr t_vertex pointAt(t_inter_type value) const
Definition PolyLine.hpp:511
decltype(auto) begin(uint04 index) const
Definition PolyLine.hpp:122
void add(const t_vertex &vertex)
Definition PolyLine.hpp:265
void clear()
Definition PolyLine.hpp:434
void addAndSimplify(const t_vertex &vertex)
Definition PolyLine.hpp:270
decltype(auto) begin() const
Definition PolyLine.hpp:117
Polyline< t_dims, t_new_type, t_new_vertex_type > as() const
Definition PolyLine.hpp:452
const t_vertex & vertex(uint04 index) const
Definition PolyLine.hpp:155
const t_vertex & lastVertex() const
Definition PolyLine.hpp:379
const Buffer< t_vertex > & vertices() const
Definition PolyLine.hpp:192
decltype(auto) end() const
Definition PolyLine.hpp:135
void add(uint04 index, const t_vertex &vertex)
Definition PolyLine.hpp:289
Polyline(const Polyline &polygon) noexcept
Definition PolyLine.hpp:72
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 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 distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:42
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
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 t_type distance(const t_vertex &vertex, const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Distance.hpp:250
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
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272