Fix EllipseShape for Affectors in QtQuick.Particle
authorDaniel Oberländer <oberlaender.daniel@gmail.com>
Thu, 29 May 2014 19:37:54 +0000 (21:37 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 12 Jun 2014 15:15:11 +0000 (17:15 +0200)
EllipseShape was theated like rectangles if set as shape in an Affector
due to an unimplemented containment check (was marked as TODO in source
code). This fix implements the missing check.

Change-Id: I8df1406f147c56e799531fccf4963110c9fdd8ef
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
src/particles/qquickellipseextruder.cpp

index f4374d8..6016d59 100644 (file)
@@ -82,7 +82,13 @@ QPointF QQuickEllipseExtruder::extrude(const QRectF & r)
 
 bool QQuickEllipseExtruder::contains(const QRectF &bounds, const QPointF &point)
 {
-    return bounds.contains(point);//TODO: Ellipse
+    if (!bounds.contains(point))
+        return false;
+
+    QPointF relPoint(bounds.center() - point);
+    qreal xa = relPoint.x()/bounds.width();
+    qreal yb = relPoint.y()/bounds.height();
+    return  (xa * xa + yb * yb) < 0.25;
 }
 
 QT_END_NAMESPACE