From f489f0b6b62bc379f94bd20fca43884586fa10c4 Mon Sep 17 00:00:00 2001 From: Tats Date: Sun, 2 Mar 2014 21:09:48 -0500 Subject: [PATCH] Rewrote the includesPoint() method for Ellipse using transformations. --- Shape.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Shape.cpp b/Shape.cpp index 8640604..8c8d8a4 100644 --- a/Shape.cpp +++ b/Shape.cpp @@ -387,16 +387,7 @@ QTransform Ellipse::fromUnitCircle() const bool Ellipse::includesPoint(qreal x, qreal y) { - // From: http://stackoverflow.com/questions/7946187/point-and-ellipse-rotated-position-test-algorithm - qreal rotation = getRotationRadians(); - const QPointF& center = getCenter(); - qreal xDiff = x - center.x(); - qreal yDiff = y - center.y(); - qreal cosRotation = cos(rotation); - qreal sinRotation = sin(rotation); - qreal horizontal = (cosRotation*xDiff + sinRotation*yDiff) / getHorizontalRadius(); - qreal vertical = (sinRotation*xDiff - cosRotation*yDiff) / getVerticalRadius(); - return (horizontal*horizontal + vertical*vertical) <= 1; + return (QVector2D(toUnitCircle().map(QPointF(x, y))).length() <= 1); } void Ellipse::setVertex(int i, const QPointF& v)