]> Shamusworld >> Repos - architektonas/blob - src/base/rs_point.cpp
825659ba4763e966fd8d2e4cb9194166c9bf125c
[architektonas] / src / base / rs_point.cpp
1 // rs_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 "rs_point.h"
18
19 #include "graphicview.h"
20 #include "paintinterface.h"
21
22 /**
23  * Default constructor.
24  */
25 RS_Point::RS_Point(RS_EntityContainer * parent, const RS_PointData & d):
26         RS_AtomicEntity(parent), data(d)
27 {
28         calculateBorders();
29 }
30
31 /*virtual*/ RS_Entity * RS_Point::clone()
32 {
33         RS_Point * p = new RS_Point(*this);
34         p->initId();
35         return p;
36 }
37
38 /**     @return RS_ENTITY_POINT */
39 /*virtual*/ RS2::EntityType RS_Point::rtti() const
40 {
41         return RS2::EntityPoint;
42 }
43
44 /**
45  * @return Start point of the entity.
46  */
47 /*virtual*/ Vector RS_Point::getStartpoint() const
48 {
49         return data.pos;
50 }
51
52 /**
53  * @return End point of the entity.
54  */
55 /*virtual*/ Vector RS_Point::getEndpoint() const
56 {
57         return data.pos;
58 }
59
60 /** @return Copy of data that defines the point. */
61 RS_PointData RS_Point::getData() const
62 {
63         return data;
64 }
65
66 /** @return Position of the point */
67 Vector RS_Point::getPos()
68 {
69         return data.pos;
70 }
71
72 /** Sets a new position for this point. */
73 void RS_Point::setPos(const Vector & pos)
74 {
75         data.pos = pos;
76 }
77
78 void RS_Point::calculateBorders()
79 {
80         minV = maxV = data.pos;
81 }
82
83 VectorSolutions RS_Point::getRefPoints()
84 {
85         VectorSolutions ret(data.pos);
86         return ret;
87 }
88
89 Vector RS_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 RS_Point::getNearestPointOnEntity(const Vector & coord,
98         bool /*onEntity*/, double * dist, RS_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 RS_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 RS_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 RS_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 RS_Point::getDistanceToPoint(const Vector & coord, RS_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 RS_Point::moveStartpoint(const Vector & pos)
143 {
144         data.pos = pos;
145         calculateBorders();
146 }
147
148 void RS_Point::move(Vector offset)
149 {
150         data.pos.move(offset);
151         calculateBorders();
152 }
153
154 void RS_Point::rotate(Vector center, double angle)
155 {
156         data.pos.rotate(center, angle);
157         calculateBorders();
158 }
159
160 void RS_Point::scale(Vector center, Vector factor)
161 {
162         data.pos.scale(center, factor);
163         calculateBorders();
164 }
165
166 void RS_Point::mirror(Vector axisPoint1, Vector axisPoint2)
167 {
168         data.pos.mirror(axisPoint1, axisPoint2);
169         calculateBorders();
170 }
171
172 void RS_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 RS_Point & p)
184 {
185     os << " Point: " << p.getData() << "\n";
186     return os;
187 }