if (Global::fixedLength)
{
if (dragged->type == OTLine)
- {
- dragged->length = Vector::Magnitude(dragged->p[0], dragged->p[1]);
- }
+ dragged->length = ((Line *)dragged)->Length();
+ }
+
+ // Needed for fixed angle handling
+ if (Global::fixedAngle)
+ {
+ if (dragged->type == OTLine)
+ dragged->p[2] = ((Line *)dragged)->Unit();
}
if (dragged->type == OTCircle)
case OTLine:
if (obj->hitPoint[0])
{
+/*
+N.B.: Mixing fixed length with fixed angle (and in this order) is probably *not* going to work out in any meaningful way, and we should probably make the GUI force these to be mutually exclusive. Besides, this combined effect already works by dragging the line segment by clicking on it. :-P
+*/
if (Global::fixedLength)
{
- Vector line = point - obj->p[1];
- Vector unit = line.Unit();
+ Vector unit = Vector::Unit(obj->p[1], point);
point = obj->p[1] + (unit * obj->length);
}
+ if (Global::fixedAngle)
+ {
+ // Calculate the component of the current vector along the
+ // fixed angle: A_compB = (A • Bu) * Bu (p[2] has the unit
+ // vector "Bu".)
+ double magnitudeAlongB = Vector::Dot(Vector(point - obj->p[1]), obj->p[2]);
+ point = obj->p[1] + (obj->p[2] * magnitudeAlongB);
+ }
+
obj->p[0] = point;
}
else if (obj->hitPoint[1])
{
if (Global::fixedLength)
{
- Vector line = point - obj->p[0];
- Vector unit = line.Unit();
+ Vector unit = Vector::Unit(obj->p[0], point);
point = obj->p[0] + (unit * obj->length);
}
+ if (Global::fixedAngle)
+ {
+ double magnitudeAlongB = Vector::Dot(Vector(point - obj->p[0]), obj->p[2]);
+ point = obj->p[0] + (obj->p[2] * magnitudeAlongB);
+ }
+
obj->p[1] = point;
}
else if (obj->hitObject)