]> Shamusworld >> Repos - architektonas/blob - src/base/point.cpp
Removed unnecessary RS_ prefix from classes and whatnot.
[architektonas] / src / base / point.cpp
1 // point.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/01/2010  Added this text. :-)
15 //
16
17 #include "point.h"
18
19 #include "graphicview.h"
20 #include "paintinterface.h"
21
22 /**
23  * Default constructor.
24  */
25 Point::Point(EntityContainer * parent, const PointData & d):
26         AtomicEntity(parent), data(d)
27 {
28         calculateBorders();
29 }
30
31 /*virtual*/ Entity * Point::clone()
32 {
33         Point * p = new Point(*this);
34         p->initId();
35         return p;
36 }
37
38 /**     @return RS_ENTITY_POINT */
39 /*virtual*/ RS2::EntityType Point::rtti() const
40 {
41         return RS2::EntityPoint;
42 }
43
44 /**
45  * @return Start point of the entity.
46  */
47 /*virtual*/ Vector Point::getStartpoint() const
48 {
49         return data.pos;
50 }
51
52 /**
53  * @return End point of the entity.
54  */
55 /*virtual*/ Vector Point::getEndpoint() const
56 {
57         return data.pos;
58 }
59
60 /** @return Copy of data that defines the point. */
61 PointData Point::getData() const
62 {
63         return data;
64 }
65
66 /** @return Position of the point */
67 Vector Point::getPos()
68 {
69         return data.pos;
70 }
71
72 /** Sets a new position for this point. */
73 void Point::setPos(const Vector & pos)
74 {
75         data.pos = pos;
76 }
77
78 void Point::calculateBorders()
79 {
80         minV = maxV = data.pos;
81 }
82
83 VectorSolutions Point::getRefPoints()
84 {
85         VectorSolutions ret(data.pos);
86         return ret;
87 }
88
89 Vector Point::getNearestEndpoint(const Vector & coord, double * dist)
90 {
91         if (dist != NULL)
92                 *dist = data.pos.distanceTo(coord);
93
94         return data.pos;
95 }
96
97 Vector Point::getNearestPointOnEntity(const Vector & coord,
98         bool /*onEntity*/, double * dist, Entity ** entity)
99 {
100         if (dist != NULL)
101                 *dist = data.pos.distanceTo(coord);
102
103         if (entity != NULL)
104                 *entity = this;
105
106         return data.pos;
107 }
108
109 Vector Point::getNearestCenter(const Vector & coord, double * dist)
110 {
111         if (dist != NULL)
112                 *dist = data.pos.distanceTo(coord);
113
114         return data.pos;
115 }
116
117 Vector Point::getNearestMiddle(const Vector & coord, double * dist)
118 {
119         if (dist != NULL)
120                 *dist = data.pos.distanceTo(coord);
121
122         return data.pos;
123 }
124
125 Vector Point::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
126 {
127         if (dist != NULL)
128                 *dist = RS_MAXDOUBLE;
129
130         return Vector(false);
131 }
132
133 double Point::getDistanceToPoint(const Vector & coord, Entity ** entity,
134         RS2::ResolveLevel /*level*/, double /*solidDist*/)
135 {
136         if (entity != NULL)
137                 *entity = this;
138
139         return data.pos.distanceTo(coord);
140 }
141
142 void Point::moveStartpoint(const Vector & pos)
143 {
144         data.pos = pos;
145         calculateBorders();
146 }
147
148 void Point::move(Vector offset)
149 {
150         data.pos.move(offset);
151         calculateBorders();
152 }
153
154 void Point::rotate(Vector center, double angle)
155 {
156         data.pos.rotate(center, angle);
157         calculateBorders();
158 }
159
160 void Point::scale(Vector center, Vector factor)
161 {
162         data.pos.scale(center, factor);
163         calculateBorders();
164 }
165
166 void Point::mirror(Vector axisPoint1, Vector axisPoint2)
167 {
168         data.pos.mirror(axisPoint1, axisPoint2);
169         calculateBorders();
170 }
171
172 void Point::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/)
173 {
174         if (painter == NULL || view == NULL)
175                 return;
176
177         painter->drawPoint(view->toGui(getPos()));
178 }
179
180 /**
181  * Dumps the point's data to stdout.
182  */
183 std::ostream & operator<<(std::ostream & os, const Point & p)
184 {
185     os << " Point: " << p.getData() << "\n";
186     return os;
187 }