ActiveLib
Loading...
Searching...
No Matches
Box.h
1
6#ifndef ACTIVE_GEOMETRY_BOX
7#define ACTIVE_GEOMETRY_BOX
8
9#include "Active/Geometry/Anchor2D.h"
10#include "Active/Geometry/Point.h"
11
12#include <memory>
13
14namespace active::geometry {
15
19 class Box {
20 public:
21
22 // MARK: - Types
23
24 using enum Anchor2D;
25
27 using Unique = std::unique_ptr<Box>;
29 using Shared = std::shared_ptr<Box>;
31 using Option = std::optional<Box>;
32
33 // MARK: - Constructors
34
38 Box() {}
44 Box(const Point &origin, const Point &end) : origin(origin), end(end) {}
49 Box(double x1, double y1, double z1, double x2, double y2, double z2) : origin(x1, y1, z1), end(x2, y2, z2) {}
55 Box(double width, double depth) : origin(), end(width, depth) {}
59 ~Box() {}
60
61 // MARK: - Variables
62
67
68 // MARK: - Operators
69
75 bool operator== (const Box& ref) const { return isEqual3D(ref); }
81 bool operator!= (const Box& ref) const { return !isEqual3D(ref); }
87 Box& operator= (const Box& source);
93 Box operator+ (const Point& offset) const;
99 Box& operator+= (const Point& offset);
105 Box operator- (const Point& offset) const;
111 Box& operator-= (const Point& offset);
117 Box operator* (double scale) const;
123 Box& operator*= (double scale);
129 Box operator/ (double scale) const { return (*this) * (1 / scale); }
135 Box& operator/= (double scale) { return (*this) *= (1 / scale); }
136
137 // MARK: - Functions (const)
138
145 bool isEqual2D(const Box& ref, double prec = math::eps) const;
152 bool isEqual3D(const Box& ref, double prec = math::eps) const;
157 Point getCentre() const { return (origin + end) / 2; }
163 Point getAnchor2D(Anchor2D anchor) const;
168 double getArea() const;
173 double getVolume() const;
178 double getWidth() const { return fabs(origin.x - end.x); }
183 double getDepth() const { return fabs(origin.y - end.y); }
188 double getHeight() const { return fabs(origin.z - end.z); }
193 double getMaxLength() const;
200 Position positionOf2D(const Point& ref, double prec = math::eps) const;
207 Position positionOf3D(const Point& ref, double prec = math::eps) const;
214 bool encloses2D(const Box& ref, double prec = math::eps) const;
221 bool encloses3D(const Box& ref, double prec = math::eps) const;
228 bool overlaps2D(const Box& ref, double prec = math::eps) const;
229
230 // MARK: - Functions (mutating)
231
236 void moveTo(const Point& position) { *this += (position - getAnchor2D(leftFront)); }
241 void setCentre(const Point& centre) { *this += (centre - getCentre()); }
246 void merge(const Point& ref);
251 void merge(const Box& ref);
255 void sort();
260 void magnify(double scale);
265 void resize(double len);
270 void rotate(double angle);
271 };
272
273}
274
275#endif //ACTIVE_GEOMETRY_BOX
Definition Box.h:19
Box()
Definition Box.h:38
Position positionOf3D(const Point &ref, double prec=math::eps) const
Definition Box.cpp:190
bool overlaps2D(const Box &ref, double prec=math::eps) const
Definition Box.cpp:292
std::unique_ptr< Box > Unique
Unique pointer.
Definition Box.h:27
Box operator/(double scale) const
Definition Box.h:129
Point getCentre() const
Definition Box.h:157
Box operator+(const Point &offset) const
Definition Box.cpp:38
bool encloses2D(const Box &ref, double prec=math::eps) const
Definition Box.cpp:256
Point origin
Box origin (for diagonally opposite points)
Definition Box.h:64
void merge(const Point &ref)
Definition Box.cpp:334
double getArea() const
Definition Box.cpp:141
double getWidth() const
Definition Box.h:178
Box(const Point &origin, const Point &end)
Definition Box.h:44
Point getAnchor2D(Anchor2D anchor) const
Definition Box.cpp:163
Point end
Box end.
Definition Box.h:66
Box(double x1, double y1, double z1, double x2, double y2, double z2)
Definition Box.h:49
std::optional< Box > Option
Optional.
Definition Box.h:31
bool operator!=(const Box &ref) const
Definition Box.h:81
void moveTo(const Point &position)
Definition Box.h:236
double getMaxLength() const
Definition Box.cpp:177
double getHeight() const
Definition Box.h:188
void rotate(double angle)
Definition Box.cpp:405
Box & operator*=(double scale)
Definition Box.cpp:102
bool encloses3D(const Box &ref, double prec=math::eps) const
Definition Box.cpp:279
Box operator-(const Point &offset) const
Definition Box.cpp:64
Position positionOf2D(const Point &ref, double prec=math::eps) const
Definition Box.cpp:227
bool operator==(const Box &ref) const
Definition Box.h:75
void magnify(double scale)
Definition Box.cpp:380
Box & operator/=(double scale)
Definition Box.h:135
Box & operator=(const Box &source)
Definition Box.cpp:22
std::shared_ptr< Box > Shared
Shared pointer.
Definition Box.h:29
Box & operator-=(const Point &offset)
Definition Box.cpp:76
bool isEqual3D(const Box &ref, double prec=math::eps) const
Definition Box.cpp:131
Box operator*(double scale) const
Definition Box.cpp:90
double getVolume() const
Definition Box.cpp:151
Box & operator+=(const Point &offset)
Definition Box.cpp:50
Box(double width, double depth)
Definition Box.h:55
bool isEqual2D(const Box &ref, double prec=math::eps) const
Definition Box.cpp:118
void setCentre(const Point &centre)
Definition Box.h:241
~Box()
Definition Box.h:59
double getDepth() const
Definition Box.h:183
void resize(double len)
Definition Box.cpp:392
void sort()
Definition Box.cpp:365
Definition Point.h:36
double z
Z coordinate.
Definition Point.h:86
double x
X coordinate.
Definition Point.h:82
double y
Y coordinate.
Definition Point.h:84
Definition Anchor2D.h:11
Anchor2D
Anchor positions in 2D.
Definition Anchor2D.h:35
Position
Relative spatial position.
Definition Position.h:12
constexpr double eps
Default length precision (0.01mm)
Definition MathFunctions.h:22