1 // rs_constructionline.cpp
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
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/28/2010 Added this text. :-)
15 #include "rs_constructionline.h"
22 RS_ConstructionLine::RS_ConstructionLine(RS_EntityContainer * parent,
23 const RS_ConstructionLineData & d): RS_AtomicEntity(parent), data(d)
31 RS_ConstructionLine::~RS_ConstructionLine()
35 RS_Entity * RS_ConstructionLine::clone()
37 RS_ConstructionLine * c = new RS_ConstructionLine(*this);
42 void RS_ConstructionLine::calculateBorders()
44 minV = Vector::minimum(data.point1, data.point2);
45 maxV = Vector::maximum(data.point1, data.point2);
48 Vector RS_ConstructionLine::getNearestEndpoint(const Vector & coord, double * dist)
53 dist1 = data.point1.distanceTo(coord);
54 dist2 = data.point2.distanceTo(coord);
61 nearerPoint = &data.point2;
68 nearerPoint = &data.point1;
74 Vector RS_ConstructionLine::getNearestPointOnEntity(const Vector & coord,
75 bool /*onEntity*/, double * /*dist*/, RS_Entity ** entity)
80 Vector ae = data.point2-data.point1;
81 Vector ea = data.point1-data.point2;
82 Vector ap = coord-data.point1;
83 Vector ep = coord-data.point2;
85 if (ae.magnitude() < 1.0e-6 || ea.magnitude() < 1.0e-6)
88 // Orthogonal projection from both sides:
89 Vector ba = ae * Vector::dotP(ae, ap) / (ae.magnitude() * ae.magnitude());
90 Vector be = ea * Vector::dotP(ea, ep) / (ea.magnitude() * ea.magnitude());
92 return data.point1 + ba;
95 Vector RS_ConstructionLine::getNearestCenter(const Vector & /*coord*/, double * dist)
100 return Vector(false);
103 Vector RS_ConstructionLine::getNearestMiddle(const Vector & /*coord*/, double * dist)
106 *dist = RS_MAXDOUBLE;
108 return Vector(false);
111 Vector RS_ConstructionLine::getNearestDist(double /*distance*/, const Vector & /*coord*/,
115 *dist = RS_MAXDOUBLE;
117 return Vector(false);
120 double RS_ConstructionLine::getDistanceToPoint(const Vector& coord,
122 RS2::ResolveLevel /*level*/, double /*solidDist*/)
124 RS_DEBUG->print("RS_ConstructionLine::getDistanceToPoint");
129 double dist = RS_MAXDOUBLE;
130 Vector ae = data.point2-data.point1;
131 Vector ea = data.point1-data.point2;
132 Vector ap = coord-data.point1;
133 Vector ep = coord-data.point2;
135 if (ae.magnitude() < 1.0e-6 || ea.magnitude() < 1.0e-6)
138 // Orthogonal projection from both sides:
139 Vector ba = ae * Vector::dotP(ae, ap) / RS_Math::pow(ae.magnitude(), 2);
140 Vector be = ea * Vector::dotP(ea, ep) / RS_Math::pow(ea.magnitude(), 2);
142 RS_DEBUG->print("ba: %f", ba.magnitude());
143 RS_DEBUG->print("ae: %f", ae.magnitude());
145 Vector cp = Vector::crossP(ap, ae);
146 dist = cp.magnitude() / ae.magnitude();
151 void RS_ConstructionLine::move(Vector offset)
153 data.point1.move(offset);
154 data.point2.move(offset);
155 //calculateBorders();
158 void RS_ConstructionLine::rotate(Vector center, double angle)
160 data.point1.rotate(center, angle);
161 data.point2.rotate(center, angle);
162 //calculateBorders();
165 void RS_ConstructionLine::scale(Vector center, Vector factor)
167 data.point1.scale(center, factor);
168 data.point2.scale(center, factor);
169 //calculateBorders();
172 void RS_ConstructionLine::mirror(Vector axisPoint1, Vector axisPoint2)
174 data.point1.mirror(axisPoint1, axisPoint2);
175 data.point2.mirror(axisPoint1, axisPoint2);
179 * Dumps the point's data to stdout.
181 std::ostream & operator<<(std::ostream & os, const RS_ConstructionLine & l)
183 os << " ConstructionLine: " << l.getData() << "\n";