QCAD
Open Source 2D CAD
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 
27 #include "RVector.h"
28 #include "RTriangle.h"
29 
30 class RPolyline;
31 
32 #define RDEFAULT_RBOX RBox()
33 
44 public:
45  RBox();
46  explicit RBox(const QRectF& rect);
47  RBox(double x1, double y1, double x2, double y2);
48  RBox(const RVector& c1, const RVector& c2);
49  RBox(const RVector& center, double range);
50  RBox(const RVector& center, double width, double height);
51 
52  bool isValid() const;
53  bool isSane() const;
54 
55  bool equalsFuzzy(const RBox& b, double tol = RS::PointTolerance) const;
56  bool equalsFuzzy2D(const RBox& b, double tol = RS::PointTolerance) const;
57 
58  RBox get2D() const {
59  return RBox(c1.get2D(), c2.get2D());
60  }
61 
62  double getWidth() const;
63  double getHeight() const;
64  RVector getSize() const;
65  double getArea() const;
66  RVector getCenter() const;
67  RVector getMinimum() const;
68  RVector getMaximum() const;
69  bool isOutside(const RBox& other) const;
70  bool isOutsideXY(const RBox& other) const;
71  bool contains(const RBox& other) const;
75  bool contains(const RVector& v) const;
76  bool containsBox(const RBox& other) const {
77  return contains(other);
78  }
79  bool containsPoint(const RVector& v) const {
80  return contains(v);
81  }
82  bool intersects(const RBox& other) const;
83  bool intersectsWith(const RShape& shape, bool limited = true) const;
84 
85  void growToInclude(const RBox& other);
86  void growToIncludeBoxes(const QList<RBox>& others);
87  void growToIncludeBox(const RBox& other) {
88  growToInclude(other);
89  }
93  void growToInclude(const RVector& v);
94  void growToIncludePoint(const RVector& v) {
95  growToInclude(v);
96  }
97 
98  RVector getCorner1() const;
99  void setCorner1(const RVector& v);
100  RVector getCorner2() const;
101  void setCorner2(const RVector& v);
102 
103  QList<RVector> getCorners() const;
104  QList<RVector> getCorners2d() const;
105  QList<RLine> getLines2d() const;
106  RPolyline getPolyline2d() const;
107  QList<RTriangle> getTriangles() const;
108 
109  RBox& grow(double offset);
110  RBox& growXY(double offset);
111  RBox& growXY(double offsetX, double offsetY);
112 
113  void move(const RVector& offset);
114  bool scaleByReference(const RVector& referencePoint, const RVector& targetPoint, bool keepAspectRatio = false, bool fromCenter = false);
115 
116  QRectF toQRectF() const;
117 
118  bool operator ==(const RBox& other) const;
119  bool operator !=(const RBox& other) const {
120  return !operator==(other);
121  }
122 
123  void transform(QTransform& t);
124 
125 public:
136 };
137 
138 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox& b);
139 
142 Q_DECLARE_METATYPE(QSharedPointer<RBox>)
143 Q_DECLARE_METATYPE(QSharedPointer<RBox>*)
144 Q_DECLARE_METATYPE(QList<RBox>)
145 
146 #endif
RBox::growToIncludeBox
void growToIncludeBox(const RBox &other)
Definition: RBox.h:87
RBox::containsBox
bool containsBox(const RBox &other) const
Definition: RBox.h:76
RBox::growToIncludePoint
void growToIncludePoint(const RVector &v)
Definition: RBox.h:94
RS::PointTolerance
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RS.h:696
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RVector::get2D
RVector get2D() const
Definition: RVector.h:83
RShape
Interface for geometrical shape classes.
Definition: RShape.h:72
RBox::c2
RVector c2
Getter function for this property: getCorner2 Setter function for this property: setCorner2
Definition: RBox.h:135
RVector.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
operator<<
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition: RBox.cpp:637
RBox::c1
RVector c1
Getter function for this property: getCorner1 Setter function for this property: setCorner1
Definition: RBox.h:130
RBox::containsPoint
bool containsPoint(const RVector &v) const
Definition: RBox.h:79
RBox
Represents a box e.g.
Definition: RBox.h:43
move
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:60
RBox::get2D
RBox get2D() const
Definition: RBox.h:58
RPolyline
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10
RTriangle.h