FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Finish implementation of PShape.contains() by considering the transfo… · processing/processing@027fc7a · GitHub

Repository navigation

Commit 027fc7a

Browse files
committed
Finish implementation of PShape.contains() by considering the transformation matrix before checking for point inclusion. #1280
1 parent fa91706 commit 027fc7a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎core/src/processing/core/PShape.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,10 +2894,17 @@ public boolean isClosed() {
28942894
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
28952895
public boolean contains(float x, float y) {
28962896
if (family == PATH) {
2897+
// apply the inverse transformation matrix to the point coordinates
2898+
PMatrix inverseCoords = matrix.get();
2899+
inverseCoords.invert(); // maybe cache this?
2900+
inverseCoords.invert(); // maybe cache this?
2901+
PVector p = new PVector();
2902+
inverseCoords.mult(new PVector(x,y),p);
2903+
28972904
boolean c = false;
28982905
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
2899-
if (((vertices[i][Y] > y) != (vertices[j][Y] > y)) &&
2900-
(x <
2906+
if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) &&
2907+
(p.x <
29012908
(vertices[j][X]-vertices[i][X]) *
29022909
(y-vertices[i][Y]) /
29032910
(vertices[j][1]-vertices[i][Y]) +

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL