mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02: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
|
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
public boolean contains(float x, float y) {
|
public boolean contains(float x, float y) {
|
||||||
if (family == PATH) {
|
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;
|
boolean c = false;
|
||||||
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
|
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
|
||||||
if (((vertices[i][Y] > y) != (vertices[j][Y] > y)) &&
|
if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) &&
|
||||||
(x <
|
(p.x <
|
||||||
(vertices[j][X]-vertices[i][X]) *
|
(vertices[j][X]-vertices[i][X]) *
|
||||||
(y-vertices[i][Y]) /
|
(y-vertices[i][Y]) /
|
||||||
(vertices[j][1]-vertices[i][Y]) +
|
(vertices[j][1]-vertices[i][Y]) +
|
||||||
|
|||||||
Reference in New Issue
Block a user