QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RBox.h
Go to the documentation of this file.
1
20#ifndef RBOX_H
21#define RBOX_H
22
23#include "../core_global.h"
24
25#include <QRectF>
26#include <QSharedPointer>
27
28#include "RVector.h"
29
30class RLine;
31class RShape;
32class RTriangle;
33class RPolyline;
34
35#define RDEFAULT_RBOX RBox()
36
47public:
48 RBox();
49 explicit RBox(const QRectF& rect);
50 RBox(double x1, double y1, double x2, double y2);
51 RBox(const RVector& c1, const RVector& c2);
52 RBox(const RVector& center, double range);
53 RBox(const RVector& center, double width, double height);
54
55 bool isValid() const;
56 bool isSane() const;
57
58 bool equalsFuzzy(const RBox& b, double tol = RS::PointTolerance) const;
59 bool equalsFuzzy2D(const RBox& b, double tol = RS::PointTolerance) const;
60
61 RBox get2D() const {
62 return RBox(c1.get2D(), c2.get2D());
63 }
64
65 double getWidth() const;
66 double getHeight() const;
67 RVector getSize() const;
68 double getArea() const;
69 RVector getCenter() const;
70 RVector getMinimum() const;
71 RVector getMaximum() const;
72 bool isOutside(const RBox& other) const;
73 bool isOutsideXY(const RBox& other) const;
74 bool contains(const RBox& other) const;
78 bool contains(const RVector& v) const;
79 bool containsBox(const RBox& other) const {
80 return contains(other);
81 }
82 bool containsPoint(const RVector& v) const {
83 return contains(v);
84 }
85 bool intersects(const RBox& other) const;
86 bool intersectsWith(const RShape& shape, bool limited = true) const;
87
88 void growToInclude(const RBox& other);
89 void growToIncludeBoxes(const QList<RBox>& others);
90 void growToIncludeBox(const RBox& other) {
91 growToInclude(other);
92 }
96 void growToInclude(const RVector& v);
97 void growToIncludePoint(const RVector& v) {
98 growToInclude(v);
99 }
100
101 RVector getCorner1() const;
102 void setCorner1(const RVector& v);
103 RVector getCorner2() const;
104 void setCorner2(const RVector& v);
105
106 QList<RVector> getCorners() const;
107 QList<RVector> getCorners2d() const;
108 QList<RLine> getLines2d() const;
109 RPolyline getPolyline2d() const;
110 QList<RTriangle> getTriangles() const;
111
112 RBox& grow(double offset);
113 RBox& growXY(double offset);
114 RBox& growXY(double offsetX, double offsetY);
115
116 void move(const RVector& offset);
117 bool scaleByReference(const RVector& referencePoint, const RVector& targetPoint, bool keepAspectRatio = false, bool fromCenter = false);
118
119 QRectF toQRectF() const;
120
121 bool operator ==(const RBox& other) const;
122 bool operator !=(const RBox& other) const {
123 return !operator==(other);
124 }
125
126 void transform(QTransform& t);
127
128#if QT_VERSION >= 0x060000
133 RBox copy() const {
134 return *this;
135 }
136#endif
137
138public:
149};
150
151QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox& b);
152
155Q_DECLARE_METATYPE(QSharedPointer<RBox>)
156Q_DECLARE_METATYPE(QSharedPointer<RBox>*)
157Q_DECLARE_METATYPE(QList<RBox>)
158
159#endif
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition RBox.cpp:640
Q_DECLARE_METATYPE(RMath *)
Represents a box e.g.
Definition RBox.h:46
bool containsBox(const RBox &other) const
Definition RBox.h:79
RVector c1
Getter function for this property: getCorner1 Setter function for this property: setCorner1
Definition RBox.h:143
void growToIncludeBox(const RBox &other)
Definition RBox.h:90
RBox get2D() const
Definition RBox.h:61
void growToIncludePoint(const RVector &v)
Definition RBox.h:97
bool containsPoint(const RVector &v) const
Definition RBox.h:82
RVector c2
Getter function for this property: getCorner2 Setter function for this property: setCorner2
Definition RBox.h:148
Low-level mathematical representation of a line.
Definition RLine.h:41
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RS.h:920
Interface for geometrical shape classes.
Definition RShape.h:72
Low-level mathematical representation of a triangle.
Definition RTriangle.h:49
Represents a 3d vector (x/y/z).
Definition RVector.h:47
RVector get2D() const
Definition RVector.h:86
#define QCADCORE_EXPORT
Definition core_global.h:10
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition simple_modify.js:58