]> Shamusworld >> Repos - architektonas/blob - src/base/rs_ellipse.h
dc0588c6b64418e3126a34f9d793e6ec961d89f3
[architektonas] / src / base / rs_ellipse.h
1 #ifndef RS_ELLIPSE_H
2 #define RS_ELLIPSE_H
3
4 #include "rs_atomicentity.h"
5
6 /**
7  * Holds the data that defines an ellipse.
8  */
9 class RS_EllipseData
10 {
11         public:
12                 RS_EllipseData(const Vector & center, const Vector & majorP, double ratio, double angle1, double angle2, bool reversed)
13                 {
14                         this->center = center;
15                         this->majorP = majorP;
16                         this->ratio = ratio;
17                         this->angle1 = angle1;
18                         this->angle2 = angle2;
19                         this->reversed = reversed;
20                 }
21
22                 friend class RS_Ellipse;
23
24                 friend std::ostream & operator<<(std::ostream & os, const RS_EllipseData & ed)
25                 {
26                         os << "(" << ed.center
27                         << "/" << ed.majorP
28                         << " " << ed.ratio
29                         << " " << ed.angle1
30                         << "," << ed.angle2
31                         << ")";
32                         return os;
33                 }
34
35         private:
36                 //! Ellipse center
37                 Vector center;
38                 //! Endpoint of major axis relative to center.
39                 Vector majorP;
40                 //! Ratio of minor axis to major axis.
41                 double ratio;
42                 //! Start angle
43                 double angle1;
44                 //! End angle
45                 double angle2;
46                 //! Reversed (cw) flag
47                 bool reversed;
48 };
49
50 /**
51  * Class for an ellipse entity. All angles are in Rad.
52  *
53  * @author Andrew Mustun
54  */
55 class RS_Ellipse: public RS_AtomicEntity
56 {
57         public:
58                 RS_Ellipse(RS_EntityContainer * parent, const RS_EllipseData & d);
59                 virtual ~RS_Ellipse();
60
61                 virtual RS_Entity * clone();
62                 virtual RS2::EntityType rtti() const;
63                 virtual Vector getStartpoint() const;
64                 virtual Vector getEndpoint() const;
65                 virtual void moveStartpoint(const Vector & pos);
66                 virtual void moveEndpoint(const Vector & pos);
67                 virtual RS2::Ending getTrimPoint(const Vector & coord, const Vector & trimPoint);
68                 double getEllipseAngle(const Vector & pos);
69                 RS_EllipseData getData();
70                 virtual VectorSolutions getRefPoints();
71                 bool isReversed() const;
72                 void setReversed(bool r);
73                 double getAngle() const;
74                 double getAngle1();
75                 void setAngle1(double a1);
76                 double getAngle2();
77                 void setAngle2(double a2);
78                 Vector getCenter();
79                 void setCenter(const Vector & c);
80                 Vector getMajorP();
81                 void setMajorP(const Vector & p);
82                 double getRatio();
83                 void setRatio(double r);
84                 virtual double getAngleLength() const;
85                 double getMajorRadius() const;
86                 double getMinorRadius() const;
87
88                 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
89                 virtual Vector getNearestPointOnEntity(const Vector & coord, bool onEntity = true, double * dist = NULL, RS_Entity ** entity = NULL);
90                 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
91                 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
92                 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL);
93                 virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL, RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE);
94                 virtual bool isPointOnEntity(const Vector & coord, double tolerance = RS_TOLERANCE);
95
96                 virtual void move(Vector offset);
97                 virtual void rotate(Vector center, double angle);
98                 virtual void scale(Vector center, Vector factor);
99                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
100                 virtual void moveRef(const Vector & ref, const Vector & offset);
101
102                 virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0);
103
104                 friend std::ostream & operator<<(std::ostream & os, const RS_Ellipse & a);
105
106                 //virtual void calculateEndpoints();
107                 virtual void calculateBorders();
108
109         protected:
110                 RS_EllipseData data;
111 };
112
113 #endif