4 #include "rs_atomicentity.h"
9 * Holds the data that defines an arc.
15 RS_ArcData(const Vector& center,
17 double angle1, double angle2,
20 this->center = center;
21 this->radius = radius;
22 this->angle1 = angle1;
23 this->angle2 = angle2;
24 this->reversed = reversed;
28 center = Vector(false);
36 return (center.valid && radius>RS_TOLERANCE &&
37 fabs(angle1-angle2)>RS_TOLERANCE_ANGLE);
40 friend std::ostream& operator << (std::ostream& os, const RS_ArcData& ad) {
41 os << "(" << ad.center <<
60 * Class for an arc entity. All angles are in Rad.
62 * @author Andrew Mustun
64 class RS_Arc : public RS_AtomicEntity {
66 RS_Arc(RS_EntityContainer* parent,
70 virtual RS_Entity* clone() {
71 RS_Arc* a = new RS_Arc(*this);
76 /** @return RS2::EntityArc */
77 virtual RS2::EntityType rtti() const {
78 return RS2::EntityArc;
81 virtual bool isEdge() const {
85 /** @return Copy of data that defines the arc. **/
86 RS_ArcData getData() const {
90 virtual VectorSolutions getRefPoints();
92 /** Sets new arc parameters. **/
93 void setData(RS_ArcData d) {
97 /** @return The center point (x) of this arc */
98 Vector getCenter() const {
101 /** Sets new center. */
102 void setCenter(const Vector& c) {
106 /** @return The radius of this arc */
107 double getRadius() const {
110 /** Sets new radius. */
111 void setRadius(double r) {
115 /** @return The start angle of this arc */
116 double getAngle1() const {
119 /** Sets new start angle. */
120 void setAngle1(double a1) {
123 /** @return The end angle of this arc */
124 double getAngle2() const {
127 /** Sets new end angle. */
128 void setAngle2(double a2) {
132 * @return Direction 1. The angle at which the arc starts at
135 double getDirection1() const {
136 if (!data.reversed) {
137 return RS_Math::correctAngle(data.angle1+M_PI/2.0);
140 return RS_Math::correctAngle(data.angle1-M_PI/2.0);
144 * @return Direction 2. The angle at which the arc starts at
147 double getDirection2() const {
148 if (!data.reversed) {
149 return RS_Math::correctAngle(data.angle2-M_PI/2.0);
152 return RS_Math::correctAngle(data.angle2+M_PI/2.0);
157 * @retval true if the arc is reversed (clockwise),
158 * @retval false otherwise
160 bool isReversed() const {
161 return data.reversed;
163 /** sets the reversed status. */
164 void setReversed(bool r) {
168 /** @return Start point of the entity. */
169 virtual Vector getStartpoint() const {
172 /** @return End point of the entity. */
173 virtual Vector getEndpoint() const {
176 virtual void moveStartpoint(const Vector& pos);
177 virtual void moveEndpoint(const Vector& pos);
179 virtual void trimStartpoint(const Vector& pos);
180 virtual void trimEndpoint(const Vector& pos);
182 virtual RS2::Ending getTrimPoint(const Vector& coord,
183 const Vector& trimPoint);
185 virtual void reverse();
187 Vector getMiddlepoint() const;
188 double getAngleLength() const;
189 virtual double getLength();
190 double getBulge() const;
192 bool createFrom3P(const Vector& p1, const Vector& p2,
194 bool createFrom2PDirectionRadius(const Vector& startPoint, const Vector& endPoint,
195 double direction1, double radius);
196 bool createFrom2PBulge(const Vector& startPoint, const Vector& endPoint,
199 virtual Vector getNearestEndpoint(const Vector& coord,
200 double* dist = NULL);
201 virtual Vector getNearestPointOnEntity(const Vector& coord,
202 bool onEntity = true, double* dist = NULL, RS_Entity** entity=NULL);
203 virtual Vector getNearestCenter(const Vector& coord,
204 double* dist = NULL);
205 virtual Vector getNearestMiddle(const Vector& coord,
206 double* dist = NULL);
207 virtual Vector getNearestDist(double distance,
209 double* dist = NULL);
210 virtual Vector getNearestDist(double distance,
213 virtual double getDistanceToPoint(const Vector& coord,
214 RS_Entity** entity=NULL,
215 RS2::ResolveLevel level=RS2::ResolveNone,
216 double solidDist = RS_MAXDOUBLE);
217 virtual void move(Vector offset);
218 virtual void rotate(Vector center, double angle);
219 virtual void scale(Vector center, Vector factor);
220 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
221 virtual void moveRef(const Vector& ref, const Vector& offset);
222 virtual void stretch(Vector firstCorner,
226 // virtual void draw(RS_Painter* painter, RS_GraphicView* view, double patternOffset=0.0);
227 virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0);
229 friend std::ostream & operator<<(std::ostream & os, const RS_Arc & a);
231 virtual void calculateEndpoints();
232 virtual void calculateBorders();
238 * Startpoint. This is redundant but stored for performance
243 * Endpoint. This is redundant but stored for performance