1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 #include<iostream>
27 #include<cmath>
28 #include "rs_point.h"
29 #include "rs_circle.h"
30 #include "rs_graphicview.h"
31 #include "rs_painter.h"
32 
RS_Point(RS_EntityContainer * parent,const RS_PointData & d)33 RS_Point::RS_Point(RS_EntityContainer* parent,
34                    const RS_PointData& d)
35         :RS_AtomicEntity(parent), data(d) {
36     calculateBorders ();
37 }
38 
clone() const39 RS_Entity* RS_Point::clone() const {
40 	RS_Point* p = new RS_Point(*this);
41 	p->initId();
42 	return p;
43 }
44 
rtti() const45 RS2::EntityType RS_Point::rtti() const
46 {
47     return RS2::EntityPoint;
48 }
49 
calculateBorders()50 void RS_Point::calculateBorders () {
51     minV = maxV = data.pos;
52 }
53 
getRefPoints() const54 RS_VectorSolutions RS_Point::getRefPoints() const
55 {
56 	return RS_VectorSolutions{data.pos};
57 }
58 
getStartpoint() const59 RS_Vector RS_Point::getStartpoint() const
60 {
61     return data.pos;
62 }
63 
getEndpoint() const64 RS_Vector RS_Point::getEndpoint() const
65 {
66     return data.pos;
67 }
68 
getData() const69 RS_PointData RS_Point::getData() const
70 {
71     return data;
72 }
73 
getPos() const74 RS_Vector RS_Point::getPos() const
75 {
76     return data.pos;
77 }
78 
getCenter() const79 RS_Vector RS_Point::getCenter() const
80 {
81     return data.pos;
82 }
83 
getRadius() const84 double RS_Point::getRadius() const
85 {
86     return 0.;
87 }
88 
isTangent(const RS_CircleData & circleData) const89 bool RS_Point::isTangent(const RS_CircleData& circleData) const
90 {
91     double const dist=data.pos.distanceTo(circleData.center);
92     return fabs(dist - fabs(circleData.radius))<50.*RS_TOLERANCE;
93 }
94 
setPos(const RS_Vector & pos)95 void RS_Point::setPos(const RS_Vector& pos)
96 {
97     data.pos = pos;
98 }
99 
getNearestEndpoint(const RS_Vector & coord,double * dist) const100 RS_Vector RS_Point::getNearestEndpoint(const RS_Vector& coord, double* dist)const {
101 
102     if (dist) {
103         *dist = data.pos.distanceTo(coord);
104     }
105 
106     return data.pos;
107 }
108 
getNearestPointOnEntity(const RS_Vector & coord,bool,double * dist,RS_Entity ** entity) const109 RS_Vector RS_Point::getNearestPointOnEntity(const RS_Vector& coord,
110         bool /*onEntity*/, double* dist, RS_Entity** entity) const{
111     if (dist) {
112         *dist = data.pos.distanceTo(coord);
113     }
114     if (entity) {
115         *entity = const_cast<RS_Point*>(this);
116     }
117     return data.pos;
118 }
119 
getNearestCenter(const RS_Vector & coord,double * dist) const120 RS_Vector RS_Point::getNearestCenter(const RS_Vector& coord, double* dist) const{
121 
122     if (dist) {
123         *dist = data.pos.distanceTo(coord);
124     }
125 
126     return data.pos;
127 }
128 
getMiddlePoint() const129 RS_Vector RS_Point::getMiddlePoint()const{
130     return data.pos;
131 }
132 
getNearestMiddle(const RS_Vector & coord,double * dist,const int) const133 RS_Vector RS_Point::getNearestMiddle(const RS_Vector& coord,
134                                      double* dist,
135                                      const int /*middlePoints*/)const {
136     if (dist) {
137         *dist = data.pos.distanceTo(coord);
138     }
139 
140     return data.pos;
141 }
142 
getNearestDist(double,const RS_Vector &,double * dist) const143 RS_Vector RS_Point::getNearestDist(double /*distance*/,
144                                    const RS_Vector& /*coord*/,
145 								   double* dist) const{
146     if (dist) {
147         *dist = RS_MAXDOUBLE;
148     }
149     return RS_Vector(false);
150 }
151 
getDistanceToPoint(const RS_Vector & coord,RS_Entity ** entity,RS2::ResolveLevel,double) const152 double RS_Point::getDistanceToPoint(const RS_Vector& coord,
153                                     RS_Entity** entity,
154                                     RS2::ResolveLevel /*level*/,
155                                                                         double /*solidDist*/)const {
156     if (entity) {
157         *entity = const_cast<RS_Point*>(this);
158     }
159     return data.pos.distanceTo(coord);
160 }
161 
moveStartpoint(const RS_Vector & pos)162 void RS_Point::moveStartpoint(const RS_Vector& pos) {
163         data.pos = pos;
164         calculateBorders();
165 }
166 
move(const RS_Vector & offset)167 void RS_Point::move(const RS_Vector& offset) {
168     data.pos.move(offset);
169     calculateBorders();
170 }
171 
rotate(const RS_Vector & center,const double & angle)172 void RS_Point::rotate(const RS_Vector& center, const double& angle) {
173     data.pos.rotate(center, angle);
174     calculateBorders();
175 }
176 
rotate(const RS_Vector & center,const RS_Vector & angleVector)177 void RS_Point::rotate(const RS_Vector& center, const RS_Vector& angleVector) {
178     data.pos.rotate(center, angleVector);
179     calculateBorders();
180 }
181 
scale(const RS_Vector & center,const RS_Vector & factor)182 void RS_Point::scale(const RS_Vector& center, const RS_Vector& factor) {
183     data.pos.scale(center, factor);
184     calculateBorders();
185 }
186 
mirror(const RS_Vector & axisPoint1,const RS_Vector & axisPoint2)187 void RS_Point::mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) {
188     data.pos.mirror(axisPoint1, axisPoint2);
189     calculateBorders();
190 }
191 
draw(RS_Painter * painter,RS_GraphicView * view,double &)192 void RS_Point::draw(RS_Painter* painter,RS_GraphicView* view, double& /*patternOffset*/) {
193     if (painter==NULL || view==NULL) {
194         return;
195     }
196 
197     painter->drawPoint(view->toGui(getPos()));
198 }
199 
200 /**
201  * Dumps the point's data to stdout.
202  */
operator <<(std::ostream & os,const RS_Point & p)203 std::ostream& operator << (std::ostream& os, const RS_Point& p) {
204     os << " Point: " << p.getData() << "\n";
205     return os;
206 }
207 
operator <<(std::ostream & os,const RS_PointData & pd)208 std::ostream& operator << (std::ostream& os, const RS_PointData& pd)
209 {
210         os << "(" << pd.pos << ")";
211         return os;
212 }
213 
214 // EOF
215