allow GEOMETRY in addition to PATH for contains()

This commit is contained in:
Ben Fry
2021-12-10 15:16:29 -05:00
parent 4eb0939a9e
commit a62fe39ede
3 changed files with 13 additions and 5 deletions
+3 -1
View File
@@ -3023,9 +3023,11 @@ public class PShape implements PConstants {
/**
* Return true if this x, y coordinate is part of this shape. Only works
* with PATH shapes or GROUP shapes that contain other GROUPs or PATHs.
* This method is not imperfect and doesn't account for all cases
* (not all complex shapes: concave shapes or holes may have issues).
*/
public boolean contains(float x, float y) {
if (family == PATH) {
if (family == PATH || family == GEOMETRY) {
PVector p = new PVector(x, y);
if (matrix != null) {
// apply the inverse transformation matrix to the point coordinates
+8 -4
View File
@@ -2730,12 +2730,16 @@ public class PShapeOpenGL extends PShape {
//
// Geometry utils
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
/**
* Return true if this x, y coordinate is part of this shape. Only works
* with PATH shapes or GROUP shapes that contain other GROUPs or PATHs.
* This method is not imperfect and doesn't account for all cases
* (not all complex shapes: concave shapes or holes may have issues).
*/
@Override
public boolean contains(float x, float y) {
if (family == PATH) {
if (family == PATH || family == GEOMETRY) {
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
boolean c = false;
for (int i = 0, j = inGeo.vertexCount-1; i < inGeo.vertexCount; j = i++) {
if (((inGeo.vertices[3 * i + 1] > y) != (inGeo.vertices[3 * j + 1] > y)) &&
+2
View File
@@ -3,6 +3,8 @@ X support extensions for directories with listFiles/listPaths
X otherwise asking for .jpg will return root folders (unless 'only files' specified)
X but because macOS actually puts extensions on folders (.app, etc), support it
X fix for disableStyle() with 2D shapes in P3D
X allow GEOMETRY (not just PATH) with contains() in PShape
X the method is still incomplete, but added a note about that too
X added workaround in PShapeOpenGL to get access to vertex data
_ still need to find the root cause
_ also need to check for other reports about this