diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 830c0b391..1e3390798 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -2894,10 +2894,17 @@ public class PShape implements PConstants { // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html public boolean contains(float x, float y) { if (family == PATH) { + // apply the inverse transformation matrix to the point coordinates + PMatrix inverseCoords = matrix.get(); + inverseCoords.invert(); // maybe cache this? + inverseCoords.invert(); // maybe cache this? + PVector p = new PVector(); + inverseCoords.mult(new PVector(x,y),p); + boolean c = false; for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) { - if (((vertices[i][Y] > y) != (vertices[j][Y] > y)) && - (x < + if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) && + (p.x < (vertices[j][X]-vertices[i][X]) * (y-vertices[i][Y]) / (vertices[j][1]-vertices[i][Y]) +