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