]> Shamusworld >> Repos - architektonas/commitdiff
Fixed Dimension class to rotate, translate & mirror correctly.
authorShamus Hammons <jlhamm@acm.org>
Thu, 20 Mar 2014 15:42:00 +0000 (10:42 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 20 Mar 2014 15:42:00 +0000 (10:42 -0500)
src/dimension.cpp
src/dimension.h

index 8729b1cce27862a7842b1175dee87c1ec0f92fe9..e5a747842a32b8f6baa696c70f0dbf8219cdd9d8 100644 (file)
@@ -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);
index fbc2896a21735573983e69d477ae98d06f716e4d..b3993b0413856b858106b7a7d408cca38aba02c4 100644 (file)
@@ -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);