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  enum Type {
55  Unknown = -1,
56  Point = 0,
57  Line = 1,
58  Arc = 2,
59  Circle = 3,
60  Ellipse = 4,
61  Polyline = 5,
62  Spline = 6,
63  Triangle = 7,
64  XLine = 8,
65  Ray = 9
66  };
67 
68 public:
69  RShape() {
70  }
71 
72  virtual ~RShape() {
73  }
74 
75  virtual RShape::Type getType() const {
76  return Unknown;
77  }
78 
79  static bool isPointShape(const RShape& s) {
80  return s.getType()==RShape::Point;
81  }
82  static bool isLineShape(const RShape& s) {
83  return s.getType()==RShape::Line;
84  }
85  static bool isArcShape(const RShape& s) {
86  return s.getType()==RShape::Arc;
87  }
88  static bool isCircleShape(const RShape& s) {
89  return s.getType()==RShape::Circle;
90  }
91  static bool isEllipseShape(const RShape& s) {
92  return s.getType()==RShape::Ellipse;
93  }
94  static bool isFullEllipseShape(const RShape& s);
95  static bool isPolylineShape(const RShape& s) {
96  return s.getType()==RShape::Polyline;
97  }
98  static bool isSplineShape(const RShape& s) {
99  return s.getType()==RShape::Spline;
100  }
101  static bool isTriangleShape(const RShape& s) {
102  return s.getType()==RShape::Triangle;
103  }
104  static bool isXLineShape(const RShape& s) {
105  return s.getType()==RShape::XLine;
106  }
107  static bool isRayShape(const RShape& s) {
108  return s.getType()==RShape::Ray;
109  }
110 
111  virtual RShape* clone() const = 0;
112 
118  virtual bool isInterpolated() const {
119  return false;
120  }
121 
122  virtual RVector getClosestPointOnShape(const RVector& p,
123  bool limited = true, double strictRange = RMAXDOUBLE) const;
124 
128  virtual RBox getBoundingBox() const = 0;
129 
133  virtual void to2D() = 0;
134 
138  virtual double getLength() const = 0;
139 
150  virtual RVector getVectorTo(const RVector& point,
151  bool limited = true, double strictRange = RMAXDOUBLE) const = 0;
152 
153  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
154  virtual bool isOnShape(const RVector& point,
155  bool limited = true,
156  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
157  virtual QList<RVector> filterOnShape(const QList<RVector>& pointList,
158  bool limited = true,
159  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
160  virtual RVector getVectorFromEndpointTo(const RVector& point) const;
161 
165  virtual QList<RVector> getEndPoints() const = 0;
166 
170  virtual QList<RVector> getMiddlePoints() const = 0;
171 
175  virtual QList<RVector> getCenterPoints() const = 0;
176 
180  virtual QList<RVector> getPointsWithDistanceToEnd(
181  double distance, RS::From from = RS::FromAny) const = 0;
182 
183  virtual RVector getPointWithDistanceToStart(double distance) {
184  QList<RVector> res = getPointsWithDistanceToEnd(distance, RS::FromStart);
185  if (res.isEmpty()) {
186  return RVector::invalid;
187  }
188  return res[0];
189  }
190 
191  virtual RVector getPointWithDistanceToEnd(double distance) {
192  QList<RVector> res = getPointsWithDistanceToEnd(distance, RS::FromEnd);
193  if (res.isEmpty()) {
194  return RVector::invalid;
195  }
196  return res[0];
197  }
198 
202  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const {
203  Q_UNUSED(distance)
204  Q_UNUSED(from)
205  return RNANDOUBLE;
206  }
207 
208  virtual RVector getPointAtPercent(double p) const;
209 
210  virtual bool intersectsWith(const RShape& other,
211  bool limited = true) const;
212 
213  QList<RVector> getIntersectionPoints(const RShape& other,
214  bool limited = true, bool same = false, bool force = false) const;
215 
220  static QList<RVector> getIntersectionPoints(const RShape& shape1,
221  const RShape& shape2, bool limited = true, bool same = false, bool force = false);
222 
223  virtual bool move(const RVector& offset)=0;
224  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR)=0;
225  virtual bool scale(double scaleFactor, const RVector& center = RVector());
226  virtual bool scale(const RVector& scaleFactors, const RVector& center = RVector())=0;
227  virtual bool mirror(const RLine& axis)=0;
228  virtual bool flipHorizontal();
229  virtual bool flipVertical();
230  virtual bool stretch(const RBox& area, const RVector& offset);
231  virtual bool stretch(const RPolyline& area, const RVector& offset);
232 
233  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const = 0;
234 
235  static bool order(QList<QList<QSharedPointer<RShape> > >& boundary);
236 
237  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
238  const RLine& line2, bool limited = true) {
239  return getIntersectionPointsLL(line1, line2, limited, limited);
240  }
241  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
242  const RLine& line2, bool limited1, bool limited2);
243  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
244  const RArc& arc2, bool limited = true) {
245  return getIntersectionPointsLA(line1, arc2, limited, limited);
246  }
247  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
248  const RArc& arc2, bool limited1, bool limited2);
249  static QList<RVector> getIntersectionPointsLC(const RLine& line1,
250  const RCircle& circle2, bool limited = true);
251  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
252  const REllipse& ellipse2, bool limited = true) {
253  return getIntersectionPointsLE(line1, ellipse2, limited, limited);
254  }
255  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
256  const REllipse& ellipse2, bool limited1, bool limited2);
257  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
258  const RTriangle& triangle2, bool limited = true) {
259  return getIntersectionPointsLT(line1, triangle2, limited, limited);
260  }
261  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
262  const RTriangle& triangle2, bool limited1, bool limited2);
263  static QList<RVector> getIntersectionPointsLS(const RLine& line1,
264  const RSpline& spline2, bool limited = true);
265  static QList<RVector> getIntersectionPointsLX(const RLine& line1,
266  const RExplodable& explodable2, bool limited = true);
267 
268  static QList<RVector> getIntersectionPointsAA(const RArc& arc1,
269  const RArc& arc2, bool limited = true);
270  static QList<RVector> getIntersectionPointsAC(const RArc& arc1,
271  const RCircle& circle2, bool limited = true);
272  static QList<RVector> getIntersectionPointsAE(const RArc& arc1,
273  const REllipse& ellipse2, bool limited = true);
274  static QList<RVector> getIntersectionPointsAT(const RArc& arc1,
275  const RTriangle& triangle2, bool limited = true);
276  static QList<RVector> getIntersectionPointsAS(const RArc& arc1,
277  const RSpline& spline2, bool limited = true);
278  static QList<RVector> getIntersectionPointsAX(const RArc& arc1,
279  const RExplodable& explodable2, bool limited = true);
280 
281  static QList<RVector> getIntersectionPointsCC(const RCircle& circle1,
282  const RCircle& circle2);
283  static QList<RVector> getIntersectionPointsCE(const RCircle& circle1,
284  const REllipse& ellipse2);
285  static QList<RVector> getIntersectionPointsCS(const RCircle& circle1,
286  const RSpline& spline2, bool limited = true);
287  static QList<RVector> getIntersectionPointsCX(const RCircle& circle1,
288  const RExplodable& explodable2, bool limited = true);
289 
290  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
291  const REllipse& ellipse2);
292  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
293  const REllipse& ellipse2, bool limited);
294  static QList<RVector> getIntersectionPointsES(const REllipse& ellipse1,
295  const RSpline& spline2, bool limited = true);
296  static QList<RVector> getIntersectionPointsEX(const REllipse& ellipse1,
297  const RExplodable& explodable2, bool limited = true);
298 
299  static QList<RVector> getIntersectionPointsSX(const RSpline& spline1,
300  const RExplodable& explodable2, bool limited);
301 
302  static QList<RVector> getIntersectionPointsSS(const RSpline& spline1,
303  const RSpline& spline2, bool limited = true, bool same = false);
304 
305  static QList<RVector> getIntersectionPointsXX(const RExplodable& explodable1,
306  const RExplodable& explodable2, bool limited = true, bool same = false);
307 
308  static const RExplodable* castToExplodable(const RShape* shape);
309 
310  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
311 
312  static QList<QSharedPointer<RShape> > getOffsetLines(const RShape& shape, double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
313  static QList<QSharedPointer<RShape> > getOffsetArcs(const RShape& shape, double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
314 
315  static QList<QSharedPointer<RShape> > getReversedShapeList(const QList<QSharedPointer<RShape> >& shapes);
316 
317  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
318 
319  static QList<QSharedPointer<RShape> > trim(
320  const RShape& trimShape, const RVector& trimClickPos,
321  const RShape& limitingShape, const RVector& limitingClickPos,
322  bool trimBoth, bool samePolyline);
323 
324  static int getErrorCode() {
325  return errorCode;
326  }
327 
328  void dump();
329 
333  friend QDebug operator<<(QDebug dbg, const RShape& s) {
334  s.print(dbg);
335  return dbg;
336  }
337 
338 private:
339  static double ellipse2tr(double x, double y, double AA, double BB,
340  double CC, double DD, double EE, double FF);
341 
342 private:
343  static double twopi;
344  static double epsTolerance;
345 
346 protected:
347  virtual void print(QDebug dbg) const;
348  static int errorCode;
349 };
350 
354 Q_DECLARE_METATYPE(QSharedPointer<RShape>)
355 Q_DECLARE_METATYPE(QSharedPointer<const RShape>)
356 Q_DECLARE_METATYPE(QSharedPointer<RShape>*)
357 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >)
358 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >*)
359 Q_DECLARE_METATYPE(QList<QSharedPointer<const RShape> >)
360 
361 #endif
Represents a box e.g.
Definition: RBox.h:43
Definition: RShape.h:59
Definition: RShape.h:58
Definition: RShape.h:57
Base class for all circle drawing tools.
Definition: Circle.js:17
Definition: RShape.h:62
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:56
static int errorCode
Definition: RShape.h:348
virtual bool isInterpolated() const
Reimplement and return true if this shape relies on interpolation for geometrical operations such as ...
Definition: RShape.h:118
static QList< RVector > getIntersectionPointsLE(const RLine &line1, const REllipse &ellipse2, bool limited=true)
Definition: RShape.h:251
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:243
Definition: RShape.h:56
Low-level mathematical representation of an arc.
Definition: RArc.h:41
Definition: RShape.h:60
Definition: RS.h:200
void mirror(void e, void p1, void p2, void p3, void p4)
Mirrors the given entity or shape at the given axis.
Definition: simple_modify.js:41
Base class for all arc drawing tools.
Definition: Arc.js:17
static bool isPointShape(const RShape &s)
Definition: RShape.h:79
#define QCADCORE_EXPORT
Definition: core_global.h:10
void rotate(void e, void angle, void p1, void p2)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:54
virtual ~RShape()
Definition: RShape.h:72
Definition: RShape.h:64
static double epsTolerance
Definition: RShape.h:344
void move(void e, void p1, void p2)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:14
Definition: RShape.h:65
static bool isXLineShape(const RShape &s)
Definition: RShape.h:104
#define RNANDOUBLE
Definition: RMath.h:71
Start or end.
Definition: RS.h:201
Base class for all ellipse drawing tools.
Definition: Ellipse.js:17
static double twopi
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RShape.h:343
void isFullEllipseShape(void obj)
Checks if the given object is a full ellipse shape.
Definition: library.js:809
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:140
virtual RVector getPointWithDistanceToEnd(double distance)
Definition: RShape.h:191
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:202
Q_DECLARE_METATYPE(RMath *)
Base class for all line drawing tools.
Definition: Line.js:17
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:43
Type
Definition: RShape.h:54
#define RMAXDOUBLE
Definition: RMath.h:63
Base class for all spline drawing tools.
Definition: Spline.js:17
void scale(void e, void factor, void p1, void p2)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:27
static bool isArcShape(const RShape &s)
Definition: RShape.h:85
static bool isEllipseShape(const RShape &s)
Definition: RShape.h:91
#define RDEFAULT_TOLERANCE_1E_MIN4
Definition: RShape.h:42
void getIntersectionPoints(void e1, void e2, void limited)
Definition: simple_info.js:12
Definition: RS.h:199
Definition: RShape.h:61
Low-level mathematical representation of a line.
Definition: RLine.h:42
friend QDebug operator<<(QDebug dbg, const RShape &s)
Definition: RShape.h:333
static int getErrorCode()
Definition: RShape.h:324
static bool isPolylineShape(const RShape &s)
Definition: RShape.h:95
Interface for explodable shape classes.
Definition: RExplodable.h:40
virtual RVector getPointWithDistanceToStart(double distance)
Definition: RShape.h:183
Definition: RShape.h:63
static QList< RVector > getIntersectionPointsLL(const RLine &line1, const RLine &line2, bool limited=true)
Definition: RShape.h:237
static bool isLineShape(const RShape &s)
Definition: RShape.h:82
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:198
static QList< RVector > getIntersectionPointsLT(const RLine &line1, const RTriangle &triangle2, bool limited=true)
Definition: RShape.h:257
static bool isRayShape(const RShape &s)
Definition: RShape.h:107
RShape()
Definition: RShape.h:69
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
Base class for all polyline drawing tools.
Definition: Polyline.js:18
virtual RShape::Type getType() const
Definition: RShape.h:75
static bool isSplineShape(const RShape &s)
Definition: RShape.h:98
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1684
static const RVector invalid
invalid vector
Definition: RVector.h:307
static bool isTriangleShape(const RShape &s)
Definition: RShape.h:101
Base class for all point drawing tools.
Definition: Point.js:17
static bool isCircleShape(const RShape &s)
Definition: RShape.h:88
#define RDEFAULT_RVECTOR
Definition: RVector.h:37