QCAD
Open Source 2D CAD
RShape.h
Go to the documentation of this file.
1 
20 #ifndef RSHAPE_H
21 #define RSHAPE_H
22 
23 #include "../core_global.h"
24 
25 #include <QList>
26 #include <QSharedPointer>
27 
28 #include "RVector.h"
29 #include "RMath.h"
30 
31 class RArc;
32 class RBox;
33 class RCircle;
34 class REllipse;
35 class RExplodable;
36 class RLine;
37 class RPolyline;
38 class RSpline;
39 class RTriangle;
40 
41 #ifndef RDEFAULT_TOLERANCE_1E_MIN4
42 #define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
43 #endif
44 
53 public:
54  RShape() {
55  }
56 
57  virtual ~RShape() {
58  }
59 
60  virtual RShape* clone() const = 0;
61 
67  virtual bool isInterpolated() const {
68  return false;
69  }
70 
71  virtual RVector getClosestPointOnShape(const RVector& p,
72  bool limited = true, double strictRange = RMAXDOUBLE) const;
73 
77  virtual RBox getBoundingBox() const = 0;
78 
82  virtual void to2D() = 0;
83 
87  virtual double getLength() const = 0;
88 
99  virtual RVector getVectorTo(const RVector& point,
100  bool limited = true, double strictRange = RMAXDOUBLE) const = 0;
101 
102  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
103  virtual bool isOnShape(const RVector& point,
104  bool limited = true,
105  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
106  virtual QList<RVector> filterOnShape(const QList<RVector>& pointList,
107  bool limited = true,
108  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
109  virtual RVector getVectorFromEndpointTo(const RVector& point) const;
110 
114  virtual QList<RVector> getEndPoints() const = 0;
115 
119  virtual QList<RVector> getMiddlePoints() const = 0;
120 
124  virtual QList<RVector> getCenterPoints() const = 0;
125 
129  virtual QList<RVector> getPointsWithDistanceToEnd(
130  double distance, RS::From from = RS::FromAny) const = 0;
131 
132  virtual RVector getPointWithDistanceToStart(double distance) {
133  QList<RVector> res = getPointsWithDistanceToEnd(distance, RS::FromStart);
134  if (res.isEmpty()) {
135  return RVector::invalid;
136  }
137  return res[0];
138  }
139 
140  virtual RVector getPointWithDistanceToEnd(double distance) {
141  QList<RVector> res = getPointsWithDistanceToEnd(distance, RS::FromEnd);
142  if (res.isEmpty()) {
143  return RVector::invalid;
144  }
145  return res[0];
146  }
147 
151  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const {
152  Q_UNUSED(distance)
153  Q_UNUSED(from)
154  return RNANDOUBLE;
155  }
156 
157  virtual RVector getPointAtPercent(double p) const;
158 
159  virtual bool intersectsWith(const RShape& other,
160  bool limited = true) const;
161 
162  QList<RVector> getIntersectionPoints(const RShape& other,
163  bool limited = true, bool same = false, bool force = false) const;
164 
169  static QList<RVector> getIntersectionPoints(const RShape& shape1,
170  const RShape& shape2, bool limited = true, bool same = false, bool force = false);
171 
172  virtual bool move(const RVector& offset)=0;
173  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR)=0;
174  virtual bool scale(double scaleFactor, const RVector& center = RVector());
175  virtual bool scale(const RVector& scaleFactors, const RVector& center = RVector())=0;
176  virtual bool mirror(const RLine& axis)=0;
177  virtual bool flipHorizontal();
178  virtual bool flipVertical();
179  virtual bool stretch(const RBox& area, const RVector& offset);
180  virtual bool stretch(const RPolyline& area, const RVector& offset);
181 
182  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const = 0;
183 
184  static bool order(QList<QList<QSharedPointer<RShape> > >& boundary);
185 
186  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
187  const RLine& line2, bool limited = true) {
188  return getIntersectionPointsLL(line1, line2, limited, limited);
189  }
190  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
191  const RLine& line2, bool limited1, bool limited2);
192  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
193  const RArc& arc2, bool limited = true) {
194  return getIntersectionPointsLA(line1, arc2, limited, limited);
195  }
196  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
197  const RArc& arc2, bool limited1, bool limited2);
198  static QList<RVector> getIntersectionPointsLC(const RLine& line1,
199  const RCircle& circle2, bool limited = true);
200  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
201  const REllipse& ellipse2, bool limited = true) {
202  return getIntersectionPointsLE(line1, ellipse2, limited, limited);
203  }
204  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
205  const REllipse& ellipse2, bool limited1, bool limited2);
206  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
207  const RTriangle& triangle2, bool limited = true) {
208  return getIntersectionPointsLT(line1, triangle2, limited, limited);
209  }
210  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
211  const RTriangle& triangle2, bool limited1, bool limited2);
212  static QList<RVector> getIntersectionPointsLS(const RLine& line1,
213  const RSpline& spline2, bool limited = true);
214  static QList<RVector> getIntersectionPointsLX(const RLine& line1,
215  const RExplodable& explodable2, bool limited = true);
216 
217  static QList<RVector> getIntersectionPointsAA(const RArc& arc1,
218  const RArc& arc2, bool limited = true);
219  static QList<RVector> getIntersectionPointsAC(const RArc& arc1,
220  const RCircle& circle2, bool limited = true);
221  static QList<RVector> getIntersectionPointsAE(const RArc& arc1,
222  const REllipse& ellipse2, bool limited = true);
223  static QList<RVector> getIntersectionPointsAT(const RArc& arc1,
224  const RTriangle& triangle2, bool limited = true);
225  static QList<RVector> getIntersectionPointsAS(const RArc& arc1,
226  const RSpline& spline2, bool limited = true);
227  static QList<RVector> getIntersectionPointsAX(const RArc& arc1,
228  const RExplodable& explodable2, bool limited = true);
229 
230  static QList<RVector> getIntersectionPointsCC(const RCircle& circle1,
231  const RCircle& circle2);
232  static QList<RVector> getIntersectionPointsCE(const RCircle& circle1,
233  const REllipse& ellipse2);
234  static QList<RVector> getIntersectionPointsCS(const RCircle& circle1,
235  const RSpline& spline2, bool limited = true);
236  static QList<RVector> getIntersectionPointsCX(const RCircle& circle1,
237  const RExplodable& explodable2, bool limited = true);
238 
239  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
240  const REllipse& ellipse2);
241  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
242  const REllipse& ellipse2, bool limited);
243  static QList<RVector> getIntersectionPointsES(const REllipse& ellipse1,
244  const RSpline& spline2, bool limited = true);
245  static QList<RVector> getIntersectionPointsEX(const REllipse& ellipse1,
246  const RExplodable& explodable2, bool limited = true);
247 
248  static QList<RVector> getIntersectionPointsSX(const RSpline& spline1,
249  const RExplodable& explodable2, bool limited);
250 
251  static QList<RVector> getIntersectionPointsSS(const RSpline& spline1,
252  const RSpline& spline2, bool limited = true, bool same = false);
253 
254  static QList<RVector> getIntersectionPointsXX(const RExplodable& explodable1,
255  const RExplodable& explodable2, bool limited = true, bool same = false);
256 
257  static const RExplodable* castToExplodable(const RShape* shape);
258 
259  void dump();
260 
264  friend QDebug operator<<(QDebug dbg, const RShape& s) {
265  s.print(dbg);
266  return dbg;
267  }
268 
269 private:
270  static double ellipse2tr(double x, double y, double AA, double BB,
271  double CC, double DD, double EE, double FF);
272 
273 private:
274  static double twopi;
275  static double epsTolerance;
276 
277 protected:
278  virtual void print(QDebug dbg) const;
279 };
280 
283 Q_DECLARE_METATYPE(QSharedPointer<RShape>)
284 Q_DECLARE_METATYPE(QSharedPointer<const RShape>)
285 Q_DECLARE_METATYPE(QSharedPointer<RShape>*)
286 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >)
287 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >*)
288 Q_DECLARE_METATYPE(QList<QSharedPointer<const RShape> >)
289 
290 #endif
Represents a box e.g.
Definition: RBox.h:43
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:56
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RShape.h:67
static QList< RVector > getIntersectionPointsLE(const RLine &line1, const REllipse &ellipse2, bool limited=true)
Definition: RShape.h:200
Low-level mathematical representation of a triangle.
Definition: RTriangle.h:46
static QList< RVector > getIntersectionPointsLA(const RLine &line1, const RArc &arc2, bool limited=true)
Definition: RShape.h:192
Low-level mathematical representation of an arc.
Definition: RArc.h:41
Definition: RS.h:199
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual ~RShape()
Definition: RShape.h:57
static double epsTolerance
Definition: RShape.h:275
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:200
static double twopi
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RShape.h:274
virtual RVector getPointWithDistanceToEnd(double distance)
Definition: RShape.h:140
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:151
Q_DECLARE_METATYPE(RMath *)
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:43
#define RMAXDOUBLE
Definition: RMath.h:63
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:42
Definition: RS.h:198
Low-level mathematical representation of a line.
Definition: RLine.h:42
friend QDebug operator<<(QDebug dbg, const RShape &s)
Definition: RShape.h:264
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual RVector getPointWithDistanceToStart(double distance)
Definition: RShape.h:132
static QList< RVector > getIntersectionPointsLL(const RLine &line1, const RLine &line2, bool limited=true)
Definition: RShape.h:186
Low-level mathematical representation of a circle.
Definition: RCircle.h:39
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:197
static QList< RVector > getIntersectionPointsLT(const RLine &line1, const RTriangle &triangle2, bool limited=true)
Definition: RShape.h:206
RShape()
Definition: RShape.h:54
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1679
static const RVector invalid
invalid vector
Definition: RVector.h:307
#define RDEFAULT_RVECTOR
Definition: RVector.h:37