ActiveLib
Loading...
Searching...
No Matches
PolyEdge.h
1
6#ifndef ACTIVE_GEOMETRY_POLY_EDGE
7#define ACTIVE_GEOMETRY_POLY_EDGE
8
9#include "Active/Geometry/PolyPoint.h"
10#include "Active/Geometry/Rotation.h"
11#include "Active/Geometry/Vector3.h"
12
13#include <memory>
14
15namespace active::geometry {
16
17 class Arc;
18 class Matrix3x3;
19 class Plane;
20 class XList;
21
25 class PolyEdge {
26 public:
27
28 // MARK: - Types
29
30 using enum Rotation;
32 using Unique = std::unique_ptr<PolyEdge>;
34 using Shared = std::shared_ptr<PolyEdge>;
36 using Option = std::optional<PolyEdge>;
37
38 // MARK: - Constructors
39
49 PolyEdge(const Point& origin, const PolyPoint& end);
58 PolyEdge(const Point& origin, const Point& end, double radius, Rotation rotation = anticlockwise, double prec = math::eps);
63 PolyEdge(const Arc& arc);
64
65 // MARK: - Variables
66
72 Vector3 normal = Vector3(0.0, 0.0, 1.0);
73
74 // MARK: - Operators
75
81 bool operator== (const PolyEdge& ref) const { return isEqual3D(ref); }
87 bool operator!= (const PolyEdge& ref) const { return !isEqual3D(ref); }
93 PolyEdge& operator= (const PolyEdge& source);
99 PolyEdge operator+ (const Point& offset) const;
111 PolyEdge operator- (const Point& offset) const;
123 PolyEdge operator* (double scale) const;
129 PolyEdge& operator*= (double scale);
135 PolyEdge operator* (const Matrix3x3& matrix) const;
141 PolyEdge& operator*= (const Matrix3x3& matrix);
142
143 // MARK: - Functions (const)
144
149 bool isArc(double prec = math::eps) const { return end.isArc(prec); }
156 bool isEqual2D(const PolyEdge& ref, double prec = math::eps) const;
163 bool isEqual3D(const PolyEdge& ref, double prec = math::eps) const;
170 bool isColinearTo2D(const PolyEdge& ref, double prec = math::eps) const;
176 bool isColinearTo3D(const PolyEdge& ref, double prec = math::eps) const;
183 bool isParallelTo2D(const PolyEdge& ref, double prec = math::eps) const;
189 bool isParallelTo3D(const PolyEdge& ref, double prec = math::eps) const;
196 bool isTangentialTo2D(const PolyEdge& ref, double prec = math::eps, double anglePrec = math::epsAngle) const;
202 double getRadius(bool isSigned = false) const;
207 double getSweep() const { return end.sweep; }
212 double azimuthAngle() const;
217 double altitudeAngle() const;
222 double startTangent() const;
227 double endTangent() const;
233 double getTangentAt(const Point& ref) const;
238 Point centre() const;
243 Point midpoint() const;
248 double getArea(bool isResultSigned = false) const;
252 double length2D() const;
257 double length3D() const;
263 std::optional<Arc> asArc(double prec = math::eps) const;
269 Point closestPointTo2D(const Point& ref, double prec = math::eps) const;
275 Point closestPointTo3D(const Point& ref, double prec = math::eps) const;
281 Point closestPointAlong2D(const Point& ref, double prec = math::eps) const;
287 Point closestPointAlong3D(const Point& ref, double prec = math::eps) const;
295 vertex_index intersectionWith2D(const PolyEdge& ref, XList& inter, double prec = math::eps) const;
303 vertex_index intersectionWith3D(const PolyEdge& ref, XList& inter, double prec = math::eps) const;
310 Position positionOf2D(const Point& ref, double prec = math::eps) const;
317 Position positionOf3D(const Point& ref, double prec = math::eps) const;
324 bool encloses2D(const Point& ref, double prec = math::eps) const;
330 bool encloses3D(const Point& ref, double prec = math::eps) const;
337 bool overlaps2D(const PolyEdge& ref, double prec = math::eps) const;
338
339 // MARK: - Functions (mutating)
340
347 void setRadius(double radius, std::optional<Rotation> rotation = std::nullopt, double prec = math::eps);
352 void setSweep(double sweep) { end.sweep = sweep; }
358 void stretchOrigin(const Point& pt, bool canInvert = true, double prec = math::eps);
363 void stretchEnd(const Point& pt, double prec = math::eps);
368 void setBaseLevel(double z = 0.0);
373 void offset(double shift);
382 void extend(double len, bool byEnd = true);
388 void extend(const Point& ref, bool byEnd = true);
395 void split(const Point& pos, PolyEdge& offcut, bool keepOrig = true);
402 void movePolar(double len, double azim, double alt);
408 void movePolar(double len, double angle);
412 PolyEdge& flip();
413 };
414
415}
416
417#endif //ACTIVE_GEOMETRY_POLY_EDGE
Class to represent an arc.
Definition Arc.h:25
A 3x3 matrix class.
Definition Matrix3x3.h:16
Definition Point.h:36
Definition PolyEdge.h:25
std::optional< PolyEdge > Option
Optional.
Definition PolyEdge.h:36
std::unique_ptr< PolyEdge > Unique
Unique pointer.
Definition PolyEdge.h:32
void setRadius(double radius, std::optional< Rotation > rotation=std::nullopt, double prec=math::eps)
Definition PolyEdge.cpp:606
Vector3 normal
The normal to the plane the edge lies in.
Definition PolyEdge.h:72
bool isParallelTo2D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:213
bool operator!=(const PolyEdge &ref) const
Definition PolyEdge.h:87
void split(const Point &pos, PolyEdge &offcut, bool keepOrig=true)
Definition PolyEdge.cpp:780
bool operator==(const PolyEdge &ref) const
The normal to the plane the edge is aligned to (vertical by default)
Definition PolyEdge.h:81
std::optional< Arc > asArc(double prec=math::eps) const
Definition PolyEdge.cpp:333
PolyEdge operator-(const Point &offset) const
Definition PolyEdge.cpp:105
Position positionOf2D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:532
PolyEdge & operator-=(const Point &offset)
Definition PolyEdge.cpp:117
Point closestPointAlong2D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:455
double length2D() const
Definition PolyEdge.cpp:311
double getTangentAt(const Point &ref) const
Definition PolyEdge.cpp:385
bool isTangentialTo2D(const PolyEdge &ref, double prec=math::eps, double anglePrec=math::epsAngle) const
Definition PolyEdge.cpp:279
Point midpoint() const
Definition PolyEdge.cpp:407
PolyEdge & operator+=(const Point &offset)
Definition PolyEdge.cpp:91
double getSweep() const
Definition PolyEdge.h:207
double azimuthAngle() const
Definition PolyEdge.cpp:343
bool isEqual2D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:185
PolyEdge & operator*=(double scale)
Definition PolyEdge.cpp:143
void extend(double len, bool byEnd=true)
Definition PolyEdge.cpp:728
bool encloses3D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:570
Point closestPointTo2D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:431
bool overlaps2D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:584
bool isArc(double prec=math::eps) const
Definition PolyEdge.h:149
void setBaseLevel(double z=0.0)
Definition PolyEdge.cpp:695
double length3D() const
Definition PolyEdge.cpp:321
void offset(double shift)
Definition PolyEdge.cpp:705
bool isColinearTo2D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:249
double startTangent() const
Definition PolyEdge.cpp:363
double altitudeAngle() const
Definition PolyEdge.cpp:353
Position positionOf3D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:545
double getArea(bool isResultSigned=false) const
Definition PolyEdge.cpp:419
PolyEdge & operator=(const PolyEdge &source)
Definition PolyEdge.cpp:63
Point origin
The edge origin.
Definition PolyEdge.h:68
Point centre() const
Definition PolyEdge.cpp:397
double getRadius(bool isSigned=false) const
Definition PolyEdge.cpp:294
Point closestPointAlong3D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:467
void setSweep(double sweep)
Definition PolyEdge.h:352
void stretchEnd(const Point &pt, double prec=math::eps)
Definition PolyEdge.cpp:683
bool isEqual3D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:199
bool isParallelTo3D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:231
PolyEdge()
Definition PolyEdge.h:43
Point closestPointTo3D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:443
vertex_index intersectionWith2D(const PolyEdge &ref, XList &inter, double prec=math::eps) const
Definition PolyEdge.cpp:481
void stretchOrigin(const Point &pt, bool canInvert=true, double prec=math::eps)
Definition PolyEdge.cpp:636
PolyEdge operator+(const Point &offset) const
Definition PolyEdge.cpp:79
PolyPoint end
The edge end.
Definition PolyEdge.h:70
vertex_index intersectionWith3D(const PolyEdge &ref, XList &inter, double prec=math::eps) const
Definition PolyEdge.cpp:507
double endTangent() const
Definition PolyEdge.cpp:373
void movePolar(double len, double azim, double alt)
Definition PolyEdge.cpp:829
bool encloses2D(const Point &ref, double prec=math::eps) const
Definition PolyEdge.cpp:557
bool isColinearTo3D(const PolyEdge &ref, double prec=math::eps) const
Definition PolyEdge.cpp:263
PolyEdge operator*(double scale) const
Definition PolyEdge.cpp:131
PolyEdge & flip()
Definition PolyEdge.cpp:838
std::shared_ptr< PolyEdge > Shared
Shared pointer.
Definition PolyEdge.h:34
Definition PolyPoint.h:24
double sweep
The sweep angle of an edge leading to this point (0.0 = atraight line)
Definition PolyPoint.h:78
bool isArc(double prec=math::eps) const
Definition PolyPoint.h:103
A 1x3 vector class.
Definition Vector3.h:20
Definition XList.h:24
Definition Anchor2D.h:11
int32_t vertex_index
Index of a vertex, e.g. within a polygon.
Definition Point.h:22
Position
Relative spatial position.
Definition Position.h:12
Rotation
Arc direction of travel.
Definition Rotation.h:12
@ anticlockwise
Anti-clockwise direction.
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22
constexpr double epsAngle
Default angle precision (0.1 degrees)
Definition MathFunctions.h:24