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 "RDirected.h"
28 #include "REllipseProxy.h"
29 #include "RLine.h"
30 #include "RVector.h"
31 
32 class RBox;
33 
43 class QCADCORE_EXPORT REllipse: public RShape, public RDirected {
44 public:
45  REllipse();
46  REllipse(const RVector& center,
47  const RVector& majorPoint,
48  double ratio,
49  double startParam, double endParam,
50  bool reversed);
51  virtual ~REllipse();
52 
53  virtual REllipse* clone() const {
54  return new REllipse(*this);
55  }
56 
57  bool isValid();
58 
59  virtual void to2D();
60 
61  virtual RBox getBoundingBox() const;
62 
63  virtual QList<RVector> getEndPoints() const;
64  virtual QList<RVector> getMiddlePoints() const;
65  virtual QList<RVector> getCenterPoints() const;
66  virtual QList<RVector> getPointsWithDistanceToEnd(
67  double distance, RS::From from = RS::FromAny) const;
68 
69  virtual RVector getVectorTo(const RVector& point,
70  bool limited = true, double strictRange = RMAXDOUBLE) const;
71 
72  void moveStartPoint(const RVector& pos, bool changeAngleOnly=false);
73  void moveEndPoint(const RVector& pos, bool changeAngleOnly=false);
74 
75  QList<RVector> getFoci() const;
76 
77  RVector getCenter() const;
78  void setCenter(const RVector& vector);
79  RVector getMajorPoint() const;
80  RVector getMinorPoint() const;
81  void setMajorPoint(const RVector& vector);
82  void setMinorPoint(const RVector &p);
83  bool switchMajorMinor();
84  double getRatio() const;
85  void setRatio(double radius);
86 
87  double getStartParam() const;
88  void setStartParam(double startParam);
89 
90  double getEndParam() const;
91  void setEndParam(double endParam);
92 
93  double getStartAngle() const;
94  void setStartAngle(double a);
95 
96  double angleToParam(double a) const;
97 
98  double getEndAngle() const;
99  void setEndAngle(double a);
100 
101  double getAngleLength(bool allowForZeroLength = false) const;
102 
103  bool isAngleWithinArc(double a) const {
104  if (isFullEllipse()) {
105  return true;
106  }
107  return RMath::isAngleBetween(a, getStartAngle(), getEndAngle(), reversed);
108  }
109  bool isParamWithinArc(double a) const {
110  if (isFullEllipse()) {
111  return true;
112  }
113  return RMath::isAngleBetween(a, getStartParam(), getEndParam(), reversed);
114  }
115 
116  bool isReversed() const;
117  void setReversed(bool reversed);
118 
119  virtual double getDirection1() const;
120  virtual double getDirection2() const;
121 
122  virtual RS::Side getSideOfPoint(const RVector& point) const;
123 
124  virtual RVector getStartPoint() const;
125  virtual RVector getEndPoint() const;
126  double getMajorRadius() const;
127  double getMinorRadius() const;
128  double getAngle() const;
129  void setAngle(double a);
130  bool isFullEllipse() const;
131  bool isCircular() const;
132  double getLength() const;
133  double getSimpsonLength(double f1, double f2) const;
134 
135  bool contains(const RVector& p) const;
136 
137 // virtual double getAngleAt(double distance, RS::From from = RS::FromStart) const;
138 
139  double getAngleAt(const RVector& pos) const;
140  double getParamTo(const RVector& pos) const;
141  double getRadiusAt(double param) const;
142  RVector getPointAt(double param) const;
143  RVector getMiddlePoint() const;
144 
145  virtual bool move(const RVector& offset);
146  virtual bool rotate(double rotation, const RVector& center = RDEFAULT_RVECTOR);
147  virtual bool scale(const RVector& scaleFactors, const RVector& center = RDEFAULT_RVECTOR);
148  virtual bool mirror(const RLine& axis);
149 
150  virtual bool reverse();
151 
152  virtual QSharedPointer<RShape> getTransformed(const QTransform& transform) const;
153 
154  virtual RS::Ending getTrimEnd(const RVector& trimPoint, const RVector& clickPoint);
155  virtual bool trimStartPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid);
156  virtual bool trimEndPoint(const RVector& trimPoint, const RVector& clickPoint = RVector::invalid);
157 
158  void correctMajorMinor();
159  double getSweep() const;
160 
161  QList<RVector> getBoxCorners();
162 
163  QList<RLine> getTangents(const RVector& point) const;
164 
165  QList<RSpline> approximateWithSplines() const;
166 
167  static bool hasProxy() {
168  return ellipseProxy!=NULL;
169  }
170 
174  static void setEllipseProxy(REllipseProxy* p) {
175  if (ellipseProxy!=NULL) {
176  delete ellipseProxy;
177  }
178  ellipseProxy = p;
179  }
180 
185  return ellipseProxy;
186  }
187 
188 protected:
189  virtual void print(QDebug dbg) const;
190 
191 public:
206  double ratio;
211  double startParam;
216  double endParam;
221  bool reversed;
222 
223 private:
225 };
226 
230 Q_DECLARE_METATYPE(QSharedPointer<REllipse>)
231 Q_DECLARE_METATYPE(QSharedPointer<REllipse>*)
232 
233 #endif
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid)=0
Represents a box e.g.
Definition: RBox.h:43
Ending
Entity ending.
Definition: RS.h:149
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:184
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
static REllipseProxy * ellipseProxy
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: REllipse.h:224
virtual QList< RVector > getEndPoints() const =0
virtual double getDirection1() const =0
virtual RVector getEndPoint() const =0
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)=0
#define QCADCORE_EXPORT
Definition: core_global.h:10
double startParam
Getter function for this property: getStartParam.
Definition: REllipse.h:211
double endParam
Getter function for this property: getEndParam.
Definition: REllipse.h:216
virtual double getLength() const =0
Proxy for advanced ellipse functionality.
Definition: REllipseProxy.h:37
virtual RBox getBoundingBox() const =0
Start or end.
Definition: RS.h:200
static bool hasProxy()
Definition: REllipse.h:167
Side
Side used for side of a point relativ to an entity (right hand or left hand side) ...
Definition: RS.h:139
bool isParamWithinArc(double a) const
Definition: REllipse.h:109
virtual bool move(const RVector &offset)=0
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
Definition: RShape.h:151
double ratio
Getter function for this property: getRatio.
Definition: REllipse.h:206
static bool isAngleBetween(double a, double a1, double a2, bool reversed)
Tests if angle a is between a1 and a2.
Definition: RMath.cpp:545
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, RS::From from=RS::FromAny) const =0
Q_DECLARE_METATYPE(RMath *)
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:43
virtual QList< RVector > getMiddlePoints() const =0
RVector center
Getter function for this property: getCenter.
Definition: REllipse.h:196
#define RMAXDOUBLE
Definition: RMath.h:63
bool isAngleWithinArc(double a) const
Definition: REllipse.h:103
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid)=0
virtual bool mirror(const RLine &axis)=0
Low-level mathematical representation of a line.
Definition: RLine.h:42
virtual RS::Side getSideOfPoint(const RVector &point) const =0
virtual RVector getStartPoint() const =0
virtual bool reverse()=0
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const =0
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RDirected.h:36
bool reversed
Getter function for this property: isReversed.
Definition: REllipse.h:221
From
End used to specify from which end of a shape to measure a distance.
Definition: RS.h:197
virtual double getDirection2() const =0
virtual bool scale(double scaleFactor, const RVector &center=RVector())
Definition: RShape.cpp:1675
static void setEllipseProxy(REllipseProxy *p)
Definition: REllipse.h:174
Interface for geometrical shape classes.
Definition: RShape.h:52
virtual QList< RVector > getCenterPoints() const =0
virtual void print(QDebug dbg) const
Definition: RShape.cpp:1679
static const RVector invalid
invalid vector
Definition: RVector.h:307
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)=0
virtual REllipse * clone() const
Definition: REllipse.h:53
#define RDEFAULT_RVECTOR
Definition: RVector.h:37
RVector majorPoint
Getter function for this property: getMajorPoint.
Definition: REllipse.h:201