]> Shamusworld >> Repos - architektonas/blob - src/base/circle.h
Bugfixes related to removing Snapper class.
[architektonas] / src / base / circle.h
1 #ifndef __CIRCLE_H__
2 #define __CIRCLE_H__
3
4 #include "atomicentity.h"
5
6 /**
7  * Holds the data that defines a circle.
8  */
9 class CircleData
10 {
11         public:
12                 CircleData()
13                 {
14                 }
15
16                 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 Circle;
34
35                 friend std::ostream & operator<<(std::ostream & os, const 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 Circle: public AtomicEntity
52 {
53         public:
54                 Circle(EntityContainer * parent, const CircleData & d);
55                 virtual ~Circle();
56
57                 virtual Entity * clone();
58                 virtual RS2::EntityType rtti() const;
59                 virtual bool isEdge() const;
60                 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, 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, 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 Circle & a);
93
94                 virtual void calculateBorders();
95
96         protected:
97                 CircleData data;
98 };
99
100 #endif