From d0e697d77ae414ec5c22d43e57a57460b05e518e Mon Sep 17 00:00:00 2001 From: Tats Date: Sun, 2 Mar 2014 21:07:11 -0500 Subject: [PATCH] Remove unused center control point for color ellipses. --- Shape.cpp | 27 +++++++++++---------------- Shape.h | 10 ++++++++-- Util.cpp | 6 ++++-- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Shape.cpp b/Shape.cpp index 0936c54..5ad0bed 100644 --- a/Shape.cpp +++ b/Shape.cpp @@ -419,7 +419,8 @@ void Ellipse::setVertex(int i, const QPointF& v) // Set vertices. Shape::setVertex(1, transform.map( getVertex(1) )); Shape::setVertex(3, transform.map( getVertex(3) )); - Shape::setVertex(4, transform.map( getVertex(4) )); + if (hasCenterControl()) + Shape::setVertex(4, transform.map( getVertex(4) )); } // If changed one of the two other points, just change the vertical axis. @@ -459,25 +460,19 @@ void Ellipse::setVertex(int i, const QPointF& v) transform *= fromUnitCircle(); // Set vertices. - Shape::setVertex(4, transform.map( getVertex(4) )); + if (hasCenterControl()) + Shape::setVertex(4, transform.map( getVertex(4) )); } // Center control point (make sure it stays inside!). - else + else if (hasCenterControl()) { - if (includesPoint(v)) - Shape::setVertex(i, v); + // Map point as vector on a unit circle. + QVector2D vector(toUnitCircle().map(v)); - else - { - // Map point as vector on a unit circle. - QVector2D vector(toUnitCircle().map(v)); - - // Normalize it. - vector.normalize(); - - // Remap it to ellipse. - Shape::setVertex(4, fromUnitCircle().map(vector.toPointF())); - } + // Clip control point. + Shape::setVertex(4, vector.length() <= 1 ? + v : + fromUnitCircle().map(vector.toPointF())); } } diff --git a/Shape.h b/Shape.h index 23b7979..c4f2378 100644 --- a/Shape.h +++ b/Shape.h @@ -213,13 +213,14 @@ protected: class Ellipse : public Shape { public: Ellipse() {} - Ellipse(QPointF p1, QPointF p2, QPointF p3, QPointF p4) + Ellipse(QPointF p1, QPointF p2, QPointF p3, QPointF p4, bool hasCenterControl=true) { _addVertex(p1); _addVertex(p2); _addVertex(p3); _addVertex(p4); - _addVertex(getCenter()); // add a point in the center + if (hasCenterControl) + _addVertex(getCenter()); // add a point in the center } virtual ~Ellipse() {} @@ -234,6 +235,10 @@ public: return radiansToDegrees( getRotationRadians() ); } + bool hasCenterControl() const { + return (nVertices() == 5); + } + // QRect getBoundingRect() const { // return QRect(0, getVerticalAxis().manhattanLength(), // getHorizontalAxis().manhattanLength(), getVerticalAxis().manhattanLength()); @@ -264,6 +269,7 @@ public: /// Remaps point from circle with radius 1 set at origin (0,0) to ellipse coordinates. QTransform fromUnitCircle() const; + /** Return true if Shape includes point (x,y), false otherwise * Algorithm should work for all polygons, including non-convex * Found at http://www.cs.tufts.edu/comp/163/notes05/point_inclusion_handout.pdf diff --git a/Util.cpp b/Util.cpp index 7c48925..343943a 100644 --- a/Util.cpp +++ b/Util.cpp @@ -99,7 +99,8 @@ Ellipse* createEllipseForTexture(Texture* texture, int frameWidth, QPointF(texture->getX(), texture->getY() + halfHeight), QPointF(texture->getX() + halfWidth, texture->getY()), QPointF(texture->getX() + texture->getWidth(), texture->getY() + halfHeight), - QPointF(texture->getX() + halfWidth, texture->getY() + texture->getHeight()) + QPointF(texture->getX() + halfWidth, texture->getY() + texture->getHeight()), + true ); } @@ -130,7 +131,8 @@ Ellipse* createEllipseForColor(int frameWidth, int frameHeight) QPointF(frameWidth / 4, frameHeight / 2), QPointF(frameWidth / 2, frameHeight / 4), QPointF(frameWidth * 3 / 4, frameHeight / 2), - QPointF(frameWidth / 2, frameHeight * 3 / 4) + QPointF(frameWidth / 2, frameHeight * 3 / 4), + false ); }