Commit ae1debb9 authored by Eddie Kohler's avatar Eddie Kohler

add is_default()

parent f24e4134
......@@ -8,8 +8,11 @@ class Transform { public:
Transform();
Transform(double, double, double, double, double, double);
// Transform(const Transform &) generated by compiler
// ~Transform() generated by compiler
double value(int i) const { assert(i>=0&&i<6); return _m[i]; }
bool is_default() const { return _default; }
void add_scale(double, double);
void add_scale(const Point &p) { add_scale(p.x, p.y); }
......@@ -38,6 +41,7 @@ class Transform { public:
private:
double _m[6];
bool _default;
};
......
......@@ -8,6 +8,7 @@ Transform::Transform()
{
_m[0] = _m[4] = 1;
_m[1] = _m[2] = _m[3] = _m[5] = 0;
_default = true;
}
Transform::Transform(double m0, double m1, double m2,
......@@ -19,6 +20,7 @@ Transform::Transform(double m0, double m1, double m2,
_m[3] = m3;
_m[4] = m4;
_m[5] = m5;
_default = (m2 == 0 && m0 == 1 && m1 == 0 && m3 == 0 && m4 == 1 && m5 == 0);
}
......@@ -29,6 +31,9 @@ Transform::add_scale(double x, double y)
_m[1] *= y;
_m[3] *= x;
_m[4] *= y;
if (x != 1 || y != 1)
_default = false;
}
void
......@@ -44,6 +49,9 @@ Transform::add_rotate(double r)
a = _m[3], b = _m[4];
_m[3] = a*c + b*s;
_m[4] = b*c - a*s;
if (r != 0)
_default = false;
}
void
......@@ -51,6 +59,9 @@ Transform::add_translate(double x, double y)
{
_m[2] += _m[0]*x + _m[1]*y;
_m[5] += _m[3]*x + _m[4]*y;
if (x != 0 || y != 0)
_default = false;
}
Transform
......@@ -68,31 +79,39 @@ Transform::transform(const Transform &t) const
Point &
operator*=(Point &p, const Transform &t)
{
double x = p.x;
p.x = x*t._m[0] + p.y*t._m[1] + t._m[2];
p.y = x*t._m[3] + p.y*t._m[4] + t._m[5];
if (!t.is_default()) {
double x = p.x;
p.x = x*t._m[0] + p.y*t._m[1] + t._m[2];
p.y = x*t._m[3] + p.y*t._m[4] + t._m[5];
}
return p;
}
Point
operator*(const Point &p, const Transform &t)
{
return Point(p.x*t._m[0] + p.y*t._m[1] + t._m[2],
p.x*t._m[3] + p.y*t._m[4] + t._m[5]);
return (t.is_default()
? p
: Point(p.x*t._m[0] + p.y*t._m[1] + t._m[2],
p.x*t._m[3] + p.y*t._m[4] + t._m[5]));
}
Bezier &
operator*=(Bezier &b, const Transform &t)
{
b.mpoint(0) *= t;
b.mpoint(1) *= t;
b.mpoint(2) *= t;
b.mpoint(3) *= t;
if (!t.is_default()) {
b.mpoint(0) *= t;
b.mpoint(1) *= t;
b.mpoint(2) *= t;
b.mpoint(3) *= t;
}
return b;
}
Bezier
operator*(const Bezier &b, const Transform &t)
{
return Bezier(b.point(0) * t, b.point(1) * t, b.point(2) * t, b.point(3) * t);
return (t.is_default()
? b
: Bezier(b.point(0) * t, b.point(1) * t, b.point(2) * t, b.point(3) * t));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment