Skip to content

Commit 623e35c

Browse files
committed
cleaning up from #5550
1 parent 0ae242b commit 623e35c

2 files changed

Lines changed: 35 additions & 27 deletions

File tree

core/src/processing/core/PShape.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ public void addName(String nom, PShape shape) {
20402040
parent.addName(nom, shape);
20412041
} else {
20422042
if (nameTable == null) {
2043-
nameTable = new HashMap<String,PShape>();
2043+
nameTable = new HashMap<>();
20442044
}
20452045
nameTable.put(nom, shape);
20462046
}
@@ -2387,14 +2387,14 @@ public void setFill(boolean fill) {
23872387
/**
23882388
* ( begin auto-generated from PShape_setFill.xml )
23892389
*
2390-
* The <b>setFill()</b> method defines the fill color of a <b>PShape</b>.
2391-
* This method is used after shapes are created or when a shape is defined explicitly
2392-
* (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in the above example.
2393-
* When a shape is created with <b>beginShape()</b> and <b>endShape()</b>, its
2394-
* attributes may be changed with <b>fill()</b> and <b>stroke()</b> within
2395-
* <b>beginShape()</b> and <b>endShape()</b>. However, after the shape is
2396-
* created, only the <b>setFill()</b> method can define a new fill value for
2397-
* the <b>PShape</b>.
2390+
* The <b>setFill()</b> method defines the fill color of a <b>PShape</b>.
2391+
* This method is used after shapes are created or when a shape is defined explicitly
2392+
* (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in the above example.
2393+
* When a shape is created with <b>beginShape()</b> and <b>endShape()</b>, its
2394+
* attributes may be changed with <b>fill()</b> and <b>stroke()</b> within
2395+
* <b>beginShape()</b> and <b>endShape()</b>. However, after the shape is
2396+
* created, only the <b>setFill()</b> method can define a new fill value for
2397+
* the <b>PShape</b>.
23982398
*
23992399
* ( end auto-generated )
24002400
*
@@ -2543,14 +2543,14 @@ public void setStroke(boolean stroke) {
25432543
/**
25442544
* ( begin auto-generated from PShape_setStroke.xml )
25452545
*
2546-
* The <b>setStroke()</b> method defines the outline color of a <b>PShape</b>.
2547-
* This method is used after shapes are created or when a shape is defined
2548-
* explicitly (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in
2549-
* the above example. When a shape is created with <b>beginShape()</b> and
2550-
* <b>endShape()</b>, its attributes may be changed with <b>fill()</b> and
2551-
* <b>stroke()</b> within <b>beginShape()</b> and <b>endShape()</b>.
2552-
* However, after the shape is created, only the <b>setStroke()</b> method
2553-
* can define a new stroke value for the <b>PShape</b>.
2546+
* The <b>setStroke()</b> method defines the outline color of a <b>PShape</b>.
2547+
* This method is used after shapes are created or when a shape is defined
2548+
* explicitly (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in
2549+
* the above example. When a shape is created with <b>beginShape()</b> and
2550+
* <b>endShape()</b>, its attributes may be changed with <b>fill()</b> and
2551+
* <b>stroke()</b> within <b>beginShape()</b> and <b>endShape()</b>.
2552+
* However, after the shape is created, only the <b>setStroke()</b> method
2553+
* can define a new stroke value for the <b>PShape</b>.
25542554
*
25552555
* ( end auto-generated )
25562556
*
@@ -2891,7 +2891,10 @@ public boolean isClosed() {
28912891
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28922892

28932893

2894-
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
2894+
/**
2895+
* Return true if this x, y coordinate is part of this shape. Only works
2896+
* with PATH shapes or GROUP shapes that contain other GROUPs or PATHs.
2897+
*/
28952898
public boolean contains(float x, float y) {
28962899
if (family == PATH) {
28972900
// apply the inverse transformation matrix to the point coordinates
@@ -2900,7 +2903,8 @@ public boolean contains(float x, float y) {
29002903
inverseCoords.invert(); // maybe cache this?
29012904
PVector p = new PVector();
29022905
inverseCoords.mult(new PVector(x,y),p);
2903-
2906+
2907+
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
29042908
boolean c = false;
29052909
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
29062910
if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) &&
@@ -2913,19 +2917,18 @@ public boolean contains(float x, float y) {
29132917
}
29142918
}
29152919
return c;
2920+
29162921
} else if (family == GROUP) {
2917-
// If this is a group, loop through children until we find one that
2918-
// contains the supplied coordinates. If a child does not support contains()
2919-
// just throw a warning and continue.
2922+
// If this is a group, loop through children until we find one that
2923+
// contains the supplied coordinates. If a child does not support
2924+
// contains() throw a warning and continue.
29202925
for (int i = 0; i < childCount; i++) {
2921-
try {
2922-
if (children[i].contains(x, y)) return true;
2923-
} catch (IllegalArgumentException e) {
2924-
PGraphics.showWarning(e);
2925-
}
2926+
if (children[i].contains(x, y)) return true;
29262927
}
29272928
return false;
2929+
29282930
} else {
2931+
// https://github.com/processing/processing/issues/1280
29292932
throw new IllegalArgumentException("The contains() method is only implemented for paths.");
29302933
}
29312934
}

core/todo.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ X https://github.com/processing/processing/pull/5475
3131
contrib
3232
X Fixed a crash occuring while loading certain SVGs exported from Illustrator
3333
X https://github.com/processing/processing/pull/5526
34+
X Support PShape.contains() on GROUP objects
35+
X https://github.com/processing/processing/pull/5550
36+
X Improve implementation of PShape.contains() to take the CTM into account
37+
X https://github.com/processing/processing/pull/5549
38+
3439

3540
3.4
3641
_ add circle() and square()

0 commit comments

Comments
 (0)