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  RVector getCenter() const;
66  RVector getMinimum() const;
67  RVector getMaximum() const;
68  bool isOutside(const RBox& other) const;
69  bool isOutsideXY(const RBox& other) const;
70  bool contains(const RBox& other) const;
74  bool contains(const RVector& v) const;
75  bool containsBox(const RBox& other) const {
76  return contains(other);
77  }
78  bool containsPoint(const RVector& v) const {
79  return contains(v);
80  }
81  bool intersects(const RBox& other) const;
82  bool intersectsWith(const RShape& shape, bool limited = true) const;
83 
84  void growToInclude(const RBox& other);
85  void growToIncludeBoxes(const QList<RBox>& others);
86  void growToIncludeBox(const RBox& other) {
87  growToInclude(other);
88  }
92  void growToInclude(const RVector& v);
93  void growToIncludePoint(const RVector& v) {
94  growToInclude(v);
95  }
96 
97  RVector getCorner1() const;
98  void setCorner1(const RVector& v);
99  RVector getCorner2() const;
100  void setCorner2(const RVector& v);
101 
102  QList<RVector> getCorners() const;
103  QList<RVector> getCorners2d() const;
104  QList<RLine> getLines2d() const;
105  RPolyline getPolyline2d() const;
106  QList<RTriangle> getTriangles() const;
107 
108  RBox& grow(double offset);
109  RBox& growXY(double offset);
110 
111  void move(const RVector& offset);
112  bool scaleByReference(const RVector& referencePoint, const RVector& targetPoint, bool keepAspectRatio = false);
113 
114  QRectF toQRectF() const;
115 
116  bool operator ==(const RBox& other) const;
117  bool operator !=(const RBox& other) const {
118  return !operator==(other);
119  }
120 
121 public:
132 };
133 
134 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox& b);
135 
138 Q_DECLARE_METATYPE(QSharedPointer<RBox>)
139 Q_DECLARE_METATYPE(QSharedPointer<RBox>*)
140 Q_DECLARE_METATYPE(QList<RBox>)
141 
142 #endif
Represents a box e.g.
Definition: RBox.h:43
RVector c1
Getter function for this property: getCorner1.
Definition: RBox.h:126
void growToIncludePoint(const RVector &v)
Definition: RBox.h:93
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
void growToIncludeBox(const RBox &other)
Definition: RBox.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:109
RVector c2
Getter function for this property: getCorner2.
Definition: RBox.h:131
bool containsBox(const RBox &other) const
Definition: RBox.h:75
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RBox &b)
Stream operator for QDebug.
Definition: RBox.cpp:599
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RS.h:684
Q_DECLARE_METATYPE(RMath *)
RVector get2D() const
Definition: RVector.h:83
bool containsPoint(const RVector &v) const
Definition: RBox.h:78
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
Interface for geometrical shape classes.
Definition: RShape.h:52
RBox get2D() const
Definition: RBox.h:58