mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 05:39:18 +01:00
Merge pull request #5549 from alexrj/pshape-contains
Finish implementation of PShape.contains()
This commit is contained in:
@@ -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]) +
|
||||
|
||||
Reference in New Issue
Block a user