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