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/21/2010 Added this text. :-)
15 #include "vectorsolutions.h"
20 * Constructor for no solution.
22 VectorSolutions::VectorSolutions(): vector(NULL)
30 VectorSolutions::VectorSolutions(const VectorSolutions & s): vector(NULL)
33 setTangent(s.isTangent());
35 for(int i=0; i<s.getNumber(); ++i)
40 * Constructor for num solutions.
42 VectorSolutions::VectorSolutions(int num): vector(NULL)
48 * Constructor for one solution.
50 VectorSolutions::VectorSolutions(const Vector & v1)
53 vector = new Vector[num];
59 * Constructor for two solutions.
61 VectorSolutions::VectorSolutions(const Vector & v1, const Vector & v2)
64 vector = new Vector[num];
71 * Constructor for three solutions.
73 VectorSolutions::VectorSolutions(const Vector & v1, const Vector & v2, const Vector & v3)
76 vector = new Vector[num];
84 * Constructor for four solutions.
86 VectorSolutions::VectorSolutions(const Vector & v1, const Vector & v2, const Vector & v3,
90 vector = new Vector[num];
99 * Constructor for four solutions.
101 VectorSolutions::VectorSolutions(const Vector & v1, const Vector & v2, const Vector & v3,
102 const Vector & v4, const Vector & v5)
105 vector = new Vector[num];
117 VectorSolutions::~VectorSolutions()
123 * Allocates 'num' vectors.
125 void VectorSolutions::alloc(int num)
129 vector = new Vector[num];
131 for(int i=0; i<num; ++i)
132 vector[i] = Vector(false);
138 * Deletes vector array and resets everything.
140 void VectorSolutions::clean()
151 * @return vector solution number i or an invalid vector if there
152 * are less solutions.
154 Vector VectorSolutions::get(int i) const
159 return Vector(false);
163 * @return Number of solutions available.
165 int VectorSolutions::getNumber() const
171 * @retval true There's at least one valid solution.
172 * @retval false There's no valid solution.
174 bool VectorSolutions::hasValid() const
176 for(int i=0; i<num; i++)
184 * Sets the solution i to the given vector.
185 * If i is greater than the current number of solutions available,
188 void VectorSolutions::set(int i, const Vector & v)
195 * Sets the tangent flag.
197 void VectorSolutions::setTangent(bool t)
203 * @return true if at least one of the solutions is a double solution
206 bool VectorSolutions::isTangent() const
212 * Rotates all vectors around the given center by the given angle.
214 void VectorSolutions::rotate(Vector center, double ang)
216 for(int i=0; i<num; i++)
218 vector[i].rotate(center, ang);
222 * Scales all vectors by the given factors with the given center.
224 void VectorSolutions::scale(Vector center, Vector factor)
226 for(int i=0; i<num; i++)
228 vector[i].scale(center, factor);
232 * @return vector solution which is the closest to the given coordinate.
233 * dist will contain the distance if it doesn't point to NULL (default).
235 Vector VectorSolutions::getClosest(const Vector & coord, double * dist, int * index) const
238 double minDist = RS_MAXDOUBLE;
239 Vector closestPoint(false);
241 for(int i=0; i<num; i++)
245 curDist = coord.distanceTo(vector[i]);
247 if (curDist < minDist)
249 closestPoint = vector[i];
264 VectorSolutions VectorSolutions::operator=(const VectorSolutions & s)
266 alloc(s.getNumber());
267 setTangent(s.isTangent());
269 for (int i=0; i<s.getNumber(); ++i)
275 std::ostream& operator << (std::ostream& os, const VectorSolutions& s)
277 for(int i=0; i<s.num; ++i)
278 os << "(" << s.get(i) << ")\n";
280 os << " tangent: " << (int)s.isTangent() << "\n";