QCAD
Open Source 2D CAD
REllipse.h
Go to the documentation of this file.
1 
20 #ifndef RELLIPSE_H
21 #define RELLIPSE_H
22 
23 #include "../core_global.h"
24 
25 #include "RShape.h"
26 #include "RSpline.h"
27 #include "REllipseProxy.h"
28 #include "RLine.h"
29 #include "RVector.h"
30 
31 class RBox;
32 
43 public:
44  REllipse();
45  REllipse(const RVector& center,
46  const RVector& majorPoint,
47  double ratio,
48  double startParam, double endParam,
49  bool reversed);
50  virtual ~REllipse();
51 
52  virtual RShape::Type getType() const {
53  return Ellipse;
54  }
55 
56  virtual REllipse* clone() const {
57  return new REllipse(*this);
58  }
59 
60  virtual bool isDirected() const {
61  return true;
62  }
63 
64  bool isValid();
65 
66  virtual void to2D();
67 
68  virtual QList<RVector> getVectorProperties() const;
69  virtual QList<double> getDoubleProperties() const;
70  virtual QList<bool> getBoolProperties() const;
71 
72  virtual RBox getBoundingBox() const;
73 
74  virtual QList<RVector> getEndPoints() const;
75  virtual QList<RVector> getMiddlePoints() const;
76  virtual QList<RVector> getCenterPoints() const;
77  virtual QList<RVector> getPointsWithDistanceToEnd(
78  double distance, int from = RS::FromAny) const;
79 
80  virtual RVector getVectorTo(const RVector& point,
81  bool limited = true, double strictRange = RMAXDOUBLE) const;
82 
83  void moveStartPoint(const RVector& pos, bool changeAngleOnly=false);
84  void moveEndPoint(const RVector& pos, bool changeAngleOnly=false);
85 
86  QList<RVector> getFoci() const;
87 
88  RVector getCenter() const;
89  void setCenter(const RVector& vector);
90  RVector getMajorPoint() const;
91  RVector getMinorPoint() const;
92  void setMajorPoint(const RVector& vector);
93  void setMinorPoint(const RVector &p);
94  bool switchMajorMinor();
95  double getRatio() const;
96  void setRatio(double radius);
97 
98  double getStartParam() const;
99  void setStartParam(double startParam);
100 
101  double getEndParam() const;
102  void setEndParam(double endParam);
103 
104  double getStartAngle() const;
105  void setStartAngle(double a);
106 
107  double angleToParam(double a) const;
108 
109  double getEndAngle() const;
110  void setEndAngle(double a);
111 
112  double getAngleLength(bool allowForZeroLength = false) const;
113 
114  bool isAngleWithinArc(double a) const {
115  if (isFullEllipse()) {
116  return true;
117  }
118  return RMath::isAngleBetween(a, getStartAngle(), getEndAngle(), reversed);
119  }
120  bool isParamWithinArc(double a) const {
121  if (isFullEllipse()) {
122  return true;
123  }
124  return RMath::isAngleBetween(a, getStartParam(), getEndParam(), reversed);
125  }
126 
127  bool isReversed() const;
128  void setReversed(bool reversed);
129 
130  virtual double getDirection1() const;
131  virtual double getDirection2() const;
132 
133  virtual RS::Side getSideOfPoint(const RVector& point) const;
134 
135  virtual RVector getStartPoint() const;
136  virtual RVector getEndPoint() const;
137  double getMajorRadius() const;
138  double getMinorRadius() const;
139  double getAngle() const;
140  void setAngle(double a);
141  bool isFullEllipse() const;
142  bool isCircular() const;
143  double getLength() const;
144  double getSimpsonLength(double f1, double f2) const;
145 
146  bool contains(const RVector& p) const;
147 
148  virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
149 
150  double getAngleAtPoint(const RVector& pos) const;
151  double getParamTo(const RVector& pos) const;
152  double getRadiusAt(double param) const;
153  RVector getPointAt(double param) const;
154  RVector getMiddlePoint() const;
155 
156  virtual bool move(const RVector& offset);
157  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
158  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
159  virtual bool mirror(const RLine& axis);
160 
161  virtual bool reverse();
162 
163  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
164 
165  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
166  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
167  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid, bool extend = false);
168  virtual bool trimStartPoint(double trimDist) {
169  return RShape::trimStartPoint(trimDist);
170  }
171  virtual bool trimEndPoint(double trimDist) {
172  return RShape::trimEndPoint(trimDist);
173  }
174 
175  void correctMajorMinor();
176  double getSweep() const;
177 
178  QList<RVector> getBoxCorners();
179 
180  QList<RLine> getTangents(const RVector& point) const;
181 
182  QList<RSpline> approximateWithSplines() const;
183  RPolyline approximateWithArcs(int segments) const;
184 
185  virtual QList<QSharedPointer<RShape> > getOffsetShapes(double distance, int number, RS::Side side, const RVector& position = RVector::invalid);
186  virtual QList<QSharedPointer<RShape> > splitAt(const QList<RVector>& points) const;
187 
188  static bool hasProxy() {
189  return ellipseProxy!=NULL;
190  }
191 
195  static void setEllipseProxy(REllipseProxy* p) {
196  if (ellipseProxy!=NULL) {
197  delete ellipseProxy;
198  }
199  ellipseProxy = p;
200  }
201 
206  return ellipseProxy;
207  }
208 
209 protected:
210  virtual void print(QDebug dbg) const;
211 
212 public:
227  double ratio;
232  double startParam;
237  double endParam;
242  bool reversed;
243 
244 private:
246 };
247 
251 Q_DECLARE_METATYPE(QSharedPointer<REllipse>)
252 Q_DECLARE_METATYPE(QSharedPointer<REllipse>*)
253 
254 #endif
Represents a box e.g.
Definition: RBox.h:43
Ending
Entity ending.
Definition: RS.h:152
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const =0
virtual void to2D()=0
Flattens this shape to the X/Y plane.
static REllipseProxy * getEllipseProxy()
Definition: REllipse.h:205
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
Definition: RShape.cpp:1897
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:262
static REllipseProxy * ellipseProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: REllipse.h:245
virtual QList< RVector > getEndPoints() const =0
virtual RVector getEndPoint() const
Definition: RShape.h:245
virtual QList< RVector > getVectorProperties() const
Definition: RShape.h:141
virtual QList< double > getDoubleProperties() const
Definition: RShape.h:143
virtual QList< bool > getBoolProperties() const
Definition: RShape.h:144
Definition: RShape.h:60
virtual bool reverse()
Definition: RShape.h:252
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
#define QCADCORE_EXPORT
Definition: core_global.h:10
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const =0
double startParam
Getter function for this property: getStartParam.
Definition: REllipse.h:232
double endParam
Getter function for this property: getEndParam.
Definition: REllipse.h:237
virtual bool trimEndPoint(double trimDist)
Definition: REllipse.h:171
virtual double getLength() const =0
Proxy for advanced ellipse functionality.
Definition: REllipseProxy.h:38
virtual RBox getBoundingBox() const =0
Start or end.
Definition: RS.h:203
static bool hasProxy()
Definition: REllipse.h:188
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Definition: RShape.h:281
virtual double getDirection1() const
Definition: RShape.h:230
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:142
bool isParamWithinArc(double a) const
Definition: REllipse.h:120
virtual bool isDirected() const
Definition: REllipse.h:60
virtual bool move(const RVector &offset)=0
virtual double getDirection2() const
Definition: RShape.h:233
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:208
double ratio
Getter function for this property: getRatio.
Definition: REllipse.h:227
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
Definition: RShape.cpp:2070
static bool isAngleBetween(double a, double a1, double a2, bool reversed)
Tests if angle a is between a1 and a2.
Definition: RMath.cpp:557
virtual RShape::Type getType() const
Definition: REllipse.h:52
Q_DECLARE_METATYPE(RMath *)
virtual RVector getMiddlePoint() const
Definition: RShape.h:248
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:42
virtual QList< RVector > getMiddlePoints() const =0
Type
Definition: RShape.h:54
RVector center
Getter function for this property: getCenter.
Definition: REllipse.h:217
#define RMAXDOUBLE
Definition: RMath.h:63
bool isAngleWithinArc(double a) const
Definition: REllipse.h:114
Definition: RS.h:201
virtual bool mirror(const RLine &axis)=0
Low-level mathematical representation of a line.
Definition: RLine.h:41
virtual RS::Side getSideOfPoint(const RVector &point) const
Definition: RShape.h:237
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
Definition: RShape.h:298
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
virtual bool trimStartPoint(double trimDist)
Definition: REllipse.h:168
bool reversed
Getter function for this property: isReversed.
Definition: REllipse.h:242
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:200
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1715
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
static void setEllipseProxy(REllipseProxy *p)
Definition: REllipse.h:195
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1719
static const RVector invalid
invalid vector
Definition: RVector.h:314
virtual REllipse * clone() const
Definition: REllipse.h:56
virtual RVector getStartPoint() const
Definition: RShape.h:242
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
RVector majorPoint
Getter function for this property: getMajorPoint.
Definition: REllipse.h:222