X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;fp=src%2Fdrawingview.cpp;h=2e435d26fe0456a743a8256eef0ded1df12864e0;hb=92b64dc831492f1d6311a8baece66408f7659f67;hp=8ad55628ced17fd993c289c2c58e524a490ea8b4;hpb=d00cd5f46252ca0fb3df6e8191dc75f8991b2aa2;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 8ad5562..2e435d2 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -1951,9 +1951,14 @@ void DrawingView::mousePressEvent(QMouseEvent * event) 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) @@ -2959,24 +2964,40 @@ void DrawingView::HandleObjectMovement(Point point) 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)