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