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 #define RDEFAULT_TOLERANCE_1E_MIN4 1.0e-4
42 
51 public:
52  RShape() {
53  }
54 
55  virtual ~RShape() {
56  }
57 
58  virtual RShape* clone() const = 0;
59 
65  virtual bool isInterpolated() const {
66  return false;
67  }
68 
69  virtual RVector getClosestPointOnShape(const RVector& p,
70  bool limited = true, double strictRange = RMAXDOUBLE) const;
71 
75  virtual RBox getBoundingBox() const = 0;
76 
80  virtual void to2D() = 0;
81 
85  virtual double getLength() const = 0;
86 
97  virtual RVector getVectorTo(const RVector& point,
98  bool limited = true, double strictRange = RMAXDOUBLE) const = 0;
99 
100  virtual double getDistanceTo(const RVector& point, bool limited = true, double strictRange = RMAXDOUBLE) const;
101  virtual bool isOnShape(const RVector& point,
102  bool limited = true,
103  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
104  virtual QList<RVector> filterOnShape(const QList<RVector>& pointList,
105  bool limited = true,
106  double tolerance = RDEFAULT_TOLERANCE_1E_MIN4) const;
107  virtual RVector getVectorFromEndpointTo(const RVector& point) const;
108 
112  virtual QList<RVector> getEndPoints() const = 0;
113 
117  virtual QList<RVector> getMiddlePoints() const = 0;
118 
122  virtual QList<RVector> getCenterPoints() const = 0;
123 
127  virtual QList<RVector> getPointsWithDistanceToEnd(
128  double distance, RS::From from = RS::FromAny) const = 0;
129 
133  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const {
134  Q_UNUSED(distance)
135  Q_UNUSED(from)
136  return RNANDOUBLE;
137  }
138 
139  virtual RVector getPointAtPercent(double p) const;
140 
141  virtual bool intersectsWith(const RShape& other,
142  bool limited = true) const;
143 
144  QList<RVector> getIntersectionPoints(const RShape& other,
145  bool limited = true, bool same = false, bool force = false) const;
146 
151  static QList<RVector> getIntersectionPoints(const RShape& shape1,
152  const RShape& shape2, bool limited = true, bool same = false, bool force = false);
153 
154  virtual bool move(const RVector& offset)=0;
155  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR)=0;
156  virtual bool scale(double scaleFactor, const RVector& center = RVector());
157  virtual bool scale(const RVector& scaleFactors, const RVector& center = RVector())=0;
158  virtual bool mirror(const RLine& axis)=0;
159  virtual bool flipHorizontal();
160  virtual bool flipVertical();
161  virtual bool stretch(const RBox& area, const RVector& offset);
162  virtual bool stretch(const RPolyline& area, const RVector& offset);
163 
164  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const = 0;
165 
166  static bool order(QList<QList<QSharedPointer<RShape> > >& boundary);
167 
168  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
169  const RLine& line2, bool limited = true) {
170  return getIntersectionPointsLL(line1, line2, limited, limited);
171  }
172  static QList<RVector> getIntersectionPointsLL(const RLine& line1,
173  const RLine& line2, bool limited1, bool limited2);
174  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
175  const RArc& arc2, bool limited = true) {
176  return getIntersectionPointsLA(line1, arc2, limited, limited);
177  }
178  static QList<RVector> getIntersectionPointsLA(const RLine& line1,
179  const RArc& arc2, bool limited1, bool limited2);
180  static QList<RVector> getIntersectionPointsLC(const RLine& line1,
181  const RCircle& circle2, bool limited = true);
182  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
183  const REllipse& ellipse2, bool limited = true) {
184  return getIntersectionPointsLE(line1, ellipse2, limited, limited);
185  }
186  static QList<RVector> getIntersectionPointsLE(const RLine& line1,
187  const REllipse& ellipse2, bool limited1, bool limited2);
188  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
189  const RTriangle& triangle2, bool limited = true) {
190  return getIntersectionPointsLT(line1, triangle2, limited, limited);
191  }
192  static QList<RVector> getIntersectionPointsLT(const RLine& line1,
193  const RTriangle& triangle2, bool limited1, bool limited2);
194  static QList<RVector> getIntersectionPointsLS(const RLine& line1,
195  const RSpline& spline2, bool limited = true);
196  static QList<RVector> getIntersectionPointsLX(const RLine& line1,
197  const RExplodable& explodable2, bool limited = true);
198 
199  static QList<RVector> getIntersectionPointsAA(const RArc& arc1,
200  const RArc& arc2, bool limited = true);
201  static QList<RVector> getIntersectionPointsAC(const RArc& arc1,
202  const RCircle& circle2, bool limited = true);
203  static QList<RVector> getIntersectionPointsAE(const RArc& arc1,
204  const REllipse& ellipse2, bool limited = true);
205  static QList<RVector> getIntersectionPointsAT(const RArc& arc1,
206  const RTriangle& triangle2, bool limited = true);
207  static QList<RVector> getIntersectionPointsAS(const RArc& arc1,
208  const RSpline& spline2, bool limited = true);
209  static QList<RVector> getIntersectionPointsAX(const RArc& arc1,
210  const RExplodable& explodable2, bool limited = true);
211 
212  static QList<RVector> getIntersectionPointsCC(const RCircle& circle1,
213  const RCircle& circle2);
214  static QList<RVector> getIntersectionPointsCE(const RCircle& circle1,
215  const REllipse& ellipse2);
216  static QList<RVector> getIntersectionPointsCS(const RCircle& circle1,
217  const RSpline& spline2, bool limited = true);
218  static QList<RVector> getIntersectionPointsCX(const RCircle& circle1,
219  const RExplodable& explodable2, bool limited = true);
220 
221  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
222  const REllipse& ellipse2);
223  static QList<RVector> getIntersectionPointsEE(const REllipse& ellipse1,
224  const REllipse& ellipse2, bool limited);
225  static QList<RVector> getIntersectionPointsES(const REllipse& ellipse1,
226  const RSpline& spline2, bool limited = true);
227  static QList<RVector> getIntersectionPointsEX(const REllipse& ellipse1,
228  const RExplodable& explodable2, bool limited = true);
229 
230  static QList<RVector> getIntersectionPointsXX(const RExplodable& explodable1,
231  const RExplodable& explodable2, bool limited = true, bool same = false);
232 
233  static const RExplodable* castToExplodable(const RShape* shape);
234 
235  void dump();
236 
240  friend QDebug operator<<(QDebug dbg, const RShape& s) {
241  s.print(dbg);
242  return dbg;
243  }
244 
245 private:
246  static double ellipse2tr(double x, double y, double AA, double BB,
247  double CC, double DD, double EE, double FF);
248 
249 private:
250  static double twopi;
251  static double epsTolerance;
252 
253 protected:
254  virtual void print(QDebug dbg) const;
255 };
256 
259 Q_DECLARE_METATYPE(QSharedPointer<RShape>)
260 Q_DECLARE_METATYPE(QSharedPointer<const RShape>)
261 Q_DECLARE_METATYPE(QSharedPointer<RShape>*)
262 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >)
263 Q_DECLARE_METATYPE(QList<QSharedPointer<RShape> >*)
264 Q_DECLARE_METATYPE(QList<QSharedPointer<const RShape> >)
265 
266 #endif