From: Shamus Hammons Date: Thu, 20 Mar 2014 15:42:00 +0000 (-0500) Subject: Fixed Dimension class to rotate, translate & mirror correctly. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=012cc8abb57350f9e9f126ad580ae58142452015 Fixed Dimension class to rotate, translate & mirror correctly. --- diff --git a/src/dimension.cpp b/src/dimension.cpp index 8729b1c..e5a7478 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -75,23 +75,18 @@ all objects move as a unified whole. if (dimensionType == DTLinearVert) { if ((angle < 0) || (angle > PI)) - // if ((angle < PI_OVER_2) || (angle > PI3_OVER_2)) { x1 = (position.x > endpoint.x ? position.x : endpoint.x); y1 = (position.y > endpoint.y ? position.y : endpoint.y); ortho = Vector(1.0, 0); - // ortho = Vector(0, 1.0); angle = PI3_OVER_2; - // angle = 0; } else { x1 = (position.x > endpoint.x ? endpoint.x : position.x); y1 = (position.y > endpoint.y ? endpoint.y : position.y); ortho = Vector(-1.0, 0); - // ortho = Vector(0, -1.0); angle = PI_OVER_2; - // angle = PI; } linePt1.x = linePt2.x = x1; @@ -226,7 +221,7 @@ I believe they are pixels. { painter->SetPen(QPen(Qt::magenta, 1.0, Qt::SolidLine)); painter->SetBrush(QBrush(QColor(Qt::magenta))); - painter->DrawArrowToLineHandle(hp2, (dimensionType == DTLinearVert ? ortho.Angle() : 0)); + painter->DrawArrowToLineHandle(hp2, (dimensionType == DTLinearVert ? v.Angle() - PI_OVER_2 : (v.Angle() < PI ? PI : 0))); painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine)); } @@ -237,7 +232,7 @@ I believe they are pixels. { painter->SetPen(QPen(Qt::magenta, 1.0, Qt::SolidLine)); painter->SetBrush(QBrush(QColor(Qt::magenta))); - painter->DrawArrowToLineHandle(hp3, PI_OVER_2); + painter->DrawArrowToLineHandle(hp3, (dimensionType == DTLinearHorz ? v.Angle() - PI_OVER_2 : (v.Angle() > PI_OVER_2 && v.Angle() < PI3_OVER_2 ? PI3_OVER_2 : PI_OVER_2))); painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine)); } @@ -481,6 +476,45 @@ bool Dimension::HitStateChanged(void) } +/*virtual*/ void Dimension::Translate(Vector amount) +{ + position += amount; + endpoint += amount; +} + + +/*virtual*/ void Dimension::Rotate(Point point, double angle) +{ + Point l1 = Geometry::RotatePointAroundPoint(position, point, angle); + Point l2 = Geometry::RotatePointAroundPoint(endpoint, point, angle); + position = l1; + endpoint = l2; +} + + +/*virtual*/ void Dimension::Mirror(Point p1, Point p2) +{ + Point l1 = Geometry::MirrorPointAroundLine(position, p1, p2); + Point l2 = Geometry::MirrorPointAroundLine(endpoint, p1, p2); + position = l1; + endpoint = l2; +} + + +/*virtual*/ void Dimension::Save(void) +{ + Object::Save(); + oldEndpoint = endpoint; +} + + +/*virtual*/ void Dimension::Restore(void) +{ + Object::Restore(); + endpoint = oldEndpoint; +} + + /*virtual*/ void Dimension::Enumerate(FILE * file) { fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i\n", layer, position.x, position.y, endpoint.x, endpoint.y, type); diff --git a/src/dimension.h b/src/dimension.h index fbc2896..b3993b0 100644 --- a/src/dimension.h +++ b/src/dimension.h @@ -22,6 +22,11 @@ class Dimension: public Object virtual bool PointerMoved(Vector); virtual void PointerReleased(void); virtual bool HitTest(Point); + virtual void Translate(Vector); + virtual void Rotate(Point, double); + virtual void Mirror(Point, Point); + virtual void Save(void); + virtual void Restore(void); virtual void Enumerate(FILE *); virtual Object * Copy(void); virtual Vector GetPointAtParameter(double parameter);