ActiveLib
Loading...
Searching...
No Matches
XList.h
1
6#ifndef ACTIVE_GEOMETRY_X_LIST
7#define ACTIVE_GEOMETRY_X_LIST
8
9#include "Active/Geometry/XPoint.h"
10
11#include "Active/Container/List.h"
12
13namespace active::geometry {
14
15 class PolyEdge;
16
24 class XList {
25 public:
26
27 // MARK: - Types
28
37
38 // MARK: - Constructors
39
45 XList(const XInfo& targetFilter = XInfo(), const XInfo& bladeFilter = XInfo());
46
47 // MARK: - Functions (const)
48
53 const_iterator begin() const { return m_intersect.begin(); }
58 const_iterator end() const { return m_intersect.end(); }
63 const XPoint* front() const { return m_intersect.front().get(); }
68 const XPoint* back() const { return m_intersect.back().get(); }
73 size_type size() const { return m_intersect.size(); }
77 bool empty() const { return m_intersect.empty(); }
82 const XInfo& getFilter(XPoint::Role role) const { return m_filter[getPart(role)]; }
89 bool withPos(XPoint::Role role, Position pos) const;
95 bool isPos(XPoint::Role role) const;
100 void setFilter(XPoint::Role role, const XInfo& filter) { m_filter[getPart(role)] = filter; }
101
102 // MARK: - Functions (mutating)
103
108 iterator begin() { return m_intersect.begin(); }
113 iterator end() { return m_intersect.end(); }
118 XPoint* front() { return m_intersect.front().get(); }
123 XPoint* back() { return m_intersect.back().get(); }
129 bool insert(XPoint&& pt);
135 bool insert(XPoint::Unique&& pt);
141 iterator erase(iterator iter) { return m_intersect.erase(iter); }
147 auto release(iterator& iter) { return m_intersect.release(iter); }
151 void clear() { m_intersect.clear(); }
156 void removeDuplicates(double prec = math::eps);
161 template <class Compare>
162 void sort(Compare comp) { m_intersect.sort(comp); }
166 void reverse() { m_intersect.reverse(); }
172 void addPos(XPoint::Role role, Position pos);
177 void setVertex(XPoint::Role role, vertOption vertexIndex) { m_filter[getPart(role)].vertexIndex = vertexIndex; }
182 void setPart(XPoint::Role role, partOption partIndex) { m_filter[getPart(role)].partIndex = partIndex; }
186 void swapFilters();
187
188 private:
189 XPoint::Role getPart(XPoint::Role role) const {
190 return (m_isSwapped) ? ((role == XPoint::target) ? XPoint::blade : XPoint::target) : role;
191 }
192
194 base m_intersect;
196 XInfo m_filter[2];
198 bool m_isSwapped;
199 };
200
201
202 //Compare points on the basis of position in the x-y plane
203 struct ComparePosition : public std::greater<XPoint::Unique> {
204 public:
209 ComparePosition(double prec = math::eps) { m_prec = prec; }
214 ComparePosition(const ComparePosition& source) { m_prec = source.m_prec; }
222 { return (math::isLess(pos1->x, pos2->x, m_prec) ||
223 (math::isEqual(pos1->x, pos2->x, m_prec) && math::isLess(pos1->y, pos2->y, m_prec))); }
224 private:
226 double m_prec;
227 };
228
229
230 //Class to sort points along the length of a poly-edge
232 public:
237 AlongLengthOf(const PolyEdge& edge);
244 bool operator() (XPoint::Unique& pos1, XPoint::Unique& pos2) const;
245
246 private:
247
248 Point m_origin;
249 double m_radius;
250 bool m_isClockwise;
251 };
252
253}
254
255#endif //ACTIVE_GEOMETRY_X_LIST
Definition List.h:27
typename base::const_iterator const_iterator
Container const iterator type.
Definition List.h:41
typename base::size_type size_type
Container size (index) type.
Definition List.h:37
auto release(iterator &pos)
Definition List.h:160
typename base::iterator iterator
Container iterator type.
Definition List.h:39
Definition Point.h:36
Definition PolyEdge.h:25
Definition XInfo.h:33
partOption partIndex
The ID of the component part (optional)
Definition XInfo.h:57
vertOption vertexIndex
The ID of the intersecting component vertex (optional)
Definition XInfo.h:55
Definition XList.h:24
XPoint * front()
Definition XList.h:118
void setVertex(XPoint::Role role, vertOption vertexIndex)
Definition XList.h:177
size_type size() const
Definition XList.h:73
void clear()
Definition XList.h:151
bool withPos(XPoint::Role role, Position pos) const
Definition XList.cpp:40
auto release(iterator &iter)
Definition XList.h:147
const XInfo & getFilter(XPoint::Role role) const
Definition XList.h:82
base::iterator iterator
The list iterator type.
Definition XList.h:32
const XPoint * front() const
Definition XList.h:63
base::size_type size_type
The list size type.
Definition XList.h:36
iterator end()
Definition XList.h:113
void sort(Compare comp)
Definition XList.h:162
iterator begin()
Definition XList.h:108
XPoint * back()
Definition XList.h:123
void reverse()
Definition XList.h:166
const_iterator begin() const
Definition XList.h:53
bool isPos(XPoint::Role role) const
Definition XList.cpp:54
bool insert(XPoint &&pt)
Definition XList.cpp:85
const XPoint * back() const
Definition XList.h:68
void addPos(XPoint::Role role, Position pos)
Definition XList.cpp:65
void removeDuplicates(double prec=math::eps)
Definition XList.cpp:120
bool empty() const
Definition XList.h:77
const_iterator end() const
Definition XList.h:58
XList(const XInfo &targetFilter=XInfo(), const XInfo &bladeFilter=XInfo())
Definition XList.cpp:24
iterator erase(iterator iter)
Definition XList.h:141
void swapFilters()
Definition XList.cpp:73
base::const_iterator const_iterator
The list const_iterator type.
Definition XList.h:34
void setPart(XPoint::Role role, partOption partIndex)
Definition XList.h:182
container::List< XPoint > base
The list container type.
Definition XList.h:30
void setFilter(XPoint::Role role, const XInfo &filter)
Definition XList.h:100
Definition XPoint.h:25
std::unique_ptr< XPoint > Unique
Unique pointer.
Definition XPoint.h:37
Definition Anchor2D.h:11
std::optional< vertex_index > vertOption
Optional vertex index (for an undefined or missing vertex index)
Definition Point.h:24
Position
Relative spatial position.
Definition Position.h:12
std::optional< part_index > partOption
Optional part index (for an undefined or missing part index)
Definition Point.h:28
bool isEqual(double val1, double val2, double prec=eps)
Definition MathFunctions.h:99
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22
bool isLess(double val1, double val2, double prec=eps)
Definition MathFunctions.h:89
Definition XList.h:231
AlongLengthOf(const PolyEdge &edge)
Definition XList.cpp:139
bool operator()(XPoint::Unique &pos1, XPoint::Unique &pos2) const
Definition XList.cpp:150
Definition XList.h:203
ComparePosition(double prec=math::eps)
Definition XList.h:209
bool operator()(XPoint::Unique &pos1, XPoint::Unique &pos2) const
Definition XList.h:221
ComparePosition(const ComparePosition &source)
Definition XList.h:214