QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
135  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const {
136  Q_UNUSED(distance)
137  Q_UNUSED(from)
138  return RNANDOUBLE;
139  }
140 
141  virtual RVector getPointAtPercent(double p) const;
142 
143  virtual bool intersectsWith(const RShape& other,
144  bool limited = true) const;
145 
146  QList<RVector> getIntersectionPoints(const RShape& other,
147  bool limited = true, bool same = false, bool force = false) const;
148 
153  static QList<RVector> getIntersectionPoints(const RShape& shape1,
154  const RShape& shape2, bool limited = true, bool same = false, bool force = false);
155 
156  virtual bool move(const RVector& offset)=0;
157  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR)=0;
158  virtual bool scale(double scaleFactor, const RVector& center = RVector());
159  virtual bool scale(const RVector& scaleFactors, const RVector& center = RVector())=0;
160  virtual bool mirror(const RLine& axis)=0;
161  virtual bool flipHorizontal();
162  virtual bool flipVertical();
163  virtual bool stretch(const RBox& area, const RVector& offset);
164  virtual bool stretch(const RPolyline& area, const RVector& offset);
165 
166  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const = 0;
167 
168  static bool order(QList<QList<QSharedPointer<RShape> > >& boundary);
169 
170  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
171  const RLine& line2, bool limited = true) {
172  return getIntersectionPointsLL(line1, line2, limited, limited);
173  }
174  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
175  const RLine& line2, bool limited1, bool limited2);
176  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
177  const RArc& arc2, bool limited = true) {
178  return getIntersectionPointsLA(line1, arc2, limited, limited);
179  }
180  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
181  const RArc& arc2, bool limited1, bool limited2);
182  static QList<RVector> getIntersectionPointsLC(const RLine& line1,
183  const RCircle& circle2, bool limited = true);
184  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
185  const REllipse& ellipse2, bool limited = true) {
186  return getIntersectionPointsLE(line1, ellipse2, limited, limited);
187  }
188  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
189  const REllipse& ellipse2, bool limited1, bool limited2);
190  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
191  const RTriangle& triangle2, bool limited = true) {
192  return getIntersectionPointsLT(line1, triangle2, limited, limited);
193  }
194  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
195  const RTriangle& triangle2, bool limited1, bool limited2);
196  static QList<RVector> getIntersectionPointsLS(const RLine& line1,
197  const RSpline& spline2, bool limited = true);
198  static QList<RVector> getIntersectionPointsLX(const RLine& line1,
199  const RExplodable& explodable2, bool limited = true);
200 
201  static QList<RVector> getIntersectionPointsAA(const RArc& arc1,
202  const RArc& arc2, bool limited = true);
203  static QList<RVector> getIntersectionPointsAC(const RArc& arc1,
204  const RCircle& circle2, bool limited = true);
205  static QList<RVector> getIntersectionPointsAE(const RArc& arc1,
206  const REllipse& ellipse2, bool limited = true);
207  static QList<RVector> getIntersectionPointsAT(const RArc& arc1,
208  const RTriangle& triangle2, bool limited = true);
209  static QList<RVector> getIntersectionPointsAS(const RArc& arc1,
210  const RSpline& spline2, bool limited = true);
211  static QList<RVector> getIntersectionPointsAX(const RArc& arc1,
212  const RExplodable& explodable2, bool limited = true);
213 
214  static QList<RVector> getIntersectionPointsCC(const RCircle& circle1,
215  const RCircle& circle2);
216  static QList<RVector> getIntersectionPointsCE(const RCircle& circle1,
217  const REllipse& ellipse2);
218  static QList<RVector> getIntersectionPointsCS(const RCircle& circle1,
219  const RSpline& spline2, bool limited = true);
220  static QList<RVector> getIntersectionPointsCX(const RCircle& circle1,
221  const RExplodable& explodable2, bool limited = true);
222 
223  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
224  const REllipse& ellipse2);
225  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
226  const REllipse& ellipse2, bool limited);
227  static QList<RVector> getIntersectionPointsES(const REllipse& ellipse1,
228  const RSpline& spline2, bool limited = true);
229  static QList<RVector> getIntersectionPointsEX(const REllipse& ellipse1,
230  const RExplodable& explodable2, bool limited = true);
231 
232  static QList<RVector> getIntersectionPointsXX(const RExplodable& explodable1,
233  const RExplodable& explodable2, bool limited = true, bool same = false);
234 
235  static const RExplodable* castToExplodable(const RShape* shape);
236 
237  void dump();
238 
242  friend QDebug operator<<(QDebug dbg, const RShape& s) {
243  s.print(dbg);
244  return dbg;
245  }
246 
247 private:
248  static double ellipse2tr(double x, double y, double AA, double BB,
249  double CC, double DD, double EE, double FF);
250 
251 private:
252  static double twopi;
253  static double epsTolerance;
254 
255 protected:
256  virtual void print(QDebug dbg) const;
257 };
258 
261 Q_DECLARE_METATYPE(QSharedPointer<RShape>)
262 Q_DECLARE_METATYPE(QSharedPointer<const RShape>)
263 Q_DECLARE_METATYPE(QSharedPointer<RShape>*)
264 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >)
265 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >*)
266 Q_DECLARE_METATYPE(QList<QSharedPointer<const RShape> >)
267 
268 #endif