Merge pull request #5549 from alexrj/pshape-contains

Finish implementation of PShape.contains()
This commit is contained in:
Ben Fry
2018-07-24 19:21:01 -04:00
committed by GitHub

View File

@@ -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]) +