Override of includesPoint() methods in Ellipse.

This commit is contained in:
Tats
2014-03-02 17:37:49 -05:00
parent dea2781100
commit e72a1a3c77
2 changed files with 26 additions and 0 deletions
+15
View File
@@ -371,3 +371,18 @@ void Mesh::_reorderVertices()
// Copy.
vertices = newVertices;
}
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;
}
+11
View File
@@ -316,6 +316,17 @@ public:
return getVerticalAxis().length() / 2;
}
/** 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
*/
virtual bool includesPoint(qreal x, qreal y);
virtual bool includesPoint(const QPointF& p) {
return includesPoint(p.x(), p.y());
}
// Override the parent, checking to make sure the vertices are displaced correctly.
//protected:
// virtual void _vertexChanged(int i, Point* p=NULL) {