]> Shamusworld >> Repos - architektonas/blob - src/base/rs_circle.h
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / rs_circle.h
1 #ifndef RS_CIRCLE_H
2 #define RS_CIRCLE_H
3
4 #include "rs_atomicentity.h"
5
6 /**
7  * Holds the data that defines a circle.
8  */
9 class RS_CircleData
10 {
11         public:
12                 RS_CircleData()
13                 {
14                 }
15
16                 RS_CircleData(const Vector & center, double radius)
17                 {
18                         this->center = center;
19                         this->radius = radius;
20                 }
21
22                 void reset()
23                 {
24                         center = Vector(false);
25                         radius = 0.0;
26                 }
27
28                 bool isValid()
29                 {
30                         return (center.valid && radius > RS_TOLERANCE);
31                 }
32
33                 friend class RS_Circle;
34
35                 friend std::ostream & operator<<(std::ostream & os, const RS_CircleData & ad)
36                 {
37                         os << "(" << ad.center << "/" << ad.radius << ")";
38                         return os;
39                 }
40
41         public:
42                 Vector center;
43                 double radius;
44 };
45
46 /**
47  * Class for a circle entity.
48  *
49  * @author Andrew Mustun
50  */
51 class RS_Circle: public RS_AtomicEntity
52 {
53         public:
54                 RS_Circle (RS_EntityContainer * parent, const RS_CircleData & d);
55                 virtual ~RS_Circle();
56
57                 virtual RS_Entity * clone();
58                 virtual RS2::EntityType rtti() const;
59                 virtual bool isEdge() const;
60                 RS_CircleData getData();
61                 virtual VectorSolutions getRefPoints();
62                 virtual Vector getStartpoint() const;
63                 virtual Vector getEndpoint() const;
64                 double getDirection1() const;
65                 double getDirection2() const;
66                 Vector getCenter();
67                 void setCenter(const Vector & c);
68                 double getRadius();
69                 void setRadius(double r);
70                 double getAngleLength() const;
71                 virtual double getLength();
72
73                 bool createFromCR(const Vector & c, double r);
74                 bool createFrom2P(const Vector & p1, const Vector & p2);
75                 bool createFrom3P(const Vector & p1, const Vector & p2, const Vector & p3);
76                 virtual Vector getNearestEndpoint(const Vector & coord, double * dist = NULL);
77                 virtual Vector getNearestPointOnEntity(const Vector & coord, bool onEntity = true,
78                         double * dist = NULL, RS_Entity ** entity = NULL);
79                 virtual Vector getNearestCenter(const Vector & coord, double * dist = NULL);
80                 virtual Vector getNearestMiddle(const Vector & coord, double * dist = NULL);
81                 virtual Vector getNearestDist(double distance, const Vector & coord, double * dist = NULL);
82                 virtual Vector getNearestDist(double distance, bool startp);
83                 virtual double getDistanceToPoint(const Vector & coord, RS_Entity ** entity = NULL, RS2::ResolveLevel level = RS2::ResolveNone, double solidDist = RS_MAXDOUBLE);
84
85                 virtual void move(Vector offset);
86                 virtual void rotate(Vector center, double angle);
87                 virtual void scale(Vector center, Vector factor);
88                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
89                 virtual void moveRef(const Vector & ref, const Vector & offset);
90                 virtual void draw(PaintInterface * painter, GraphicView * view, double patternOffset = 0.0);
91
92                 friend std::ostream & operator<<(std::ostream & os, const RS_Circle & a);
93
94                 virtual void calculateBorders();
95
96         protected:
97                 RS_CircleData data;
98 };
99
100 #endif