mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Rewrote the includesPoint() method for Ellipse using transformations.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user