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)
Line(Vector pt1, Vector pt2, float th = 1.0, uint32_t c = 0, int l = LSSolid):
type(OTLine), id(Global::objectID++), layer(0), color(c), thickness(th),
style(l), selected(false), hovered(false), hitObject(false) { p[0] = pt1; p[1] = pt2; hitPoint[0] = hitPoint[1] = false; }
+ Vector Vect(void) { return Vector(p[0], p[1]); }
+ Vector Unit(void) { return Vector(p[0], p[1]).Unit(); }
+ double Length(void) { return Vector(p[0], p[1]).Magnitude(); }
};
struct Circle {
static double Dot(Vector v1, Vector v2);
static double Magnitude(Vector v1, Vector v2);
+ static Vector Unit(Point p1, Point p2);
static double Angle(Point p1, Point p2);
static double Parameter(Vector v1, Vector v2, Vector p);
static Vector Normal(Vector v1, Vector v2);