Line::Line(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2),
draggingLine(false), draggingHandle1(false), draggingHandle2(false), //needUpdate(false),
- length(Vector::Magnitude(p2, p1)), hitPoint1(false), hitPoint2(false), hitLine(false)
+ length(Vector::Magnitude(p2, p1)), angle(Vector(endpoint - position).Unit()),
+ hitPoint1(false), hitPoint2(false), hitLine(false)
{
}
Arc, etc. and by giving the Dimension object a pointer to our endpoints.
Problem still arises when we delete this object; The attached Dimension object will
-then have bad pointers! What is *should* do is delete the object if and only if this
+then have bad pointers! What it *should* do is delete the object if and only if this
line is not attached to any other object. If it is, then one of those attachment
points should be sent to the dimension object (done for position & endpoint).
Vector point1 = (draggingHandle1 ? endpoint : position);
Vector point2 = (draggingHandle1 ? position : endpoint);
+#if 0
Vector current(point2, point1);
Vector v = current.Unit() * length;
Vector v2 = point1 + v;
//bleh
if (!Object::fixedLength)
v2 = point2;
+#endif
+
+ if (Object::fixedAngle)
+ {
+ // Here we calculate the component of the current vector along the fixed angle.
+ // A_compB = (A . Bu) * Bu
+ double magnitudeAlongB = Vector::Dot(Vector(point2 - point1), angle);
+
+ if (draggingHandle1)
+ position = endpoint + (angle * magnitudeAlongB);
+
+ if (draggingHandle2)
+ endpoint = position + (angle * magnitudeAlongB);
+ }
+// else
+// v2 = point2;
//If we tell the dimension to flip sides, this is no longer a valid
//assumption. !!! FIX !!!
// it turns out to have a fixed length. :-)
length = Vector(endpoint - position).Magnitude();
}
+
+ if (!Object::fixedAngle)
+ {
+ // Calculate the new angle, just in case on the next move it turns out to
+ // be fixed. :-)
+ angle = Vector(endpoint - position).Unit();
+ }
}
draggingLine = false;