mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
cleaning up from #5550
This commit is contained in:
@@ -2040,7 +2040,7 @@ public class PShape implements PConstants {
|
||||
parent.addName(nom, shape);
|
||||
} else {
|
||||
if (nameTable == null) {
|
||||
nameTable = new HashMap<String,PShape>();
|
||||
nameTable = new HashMap<>();
|
||||
}
|
||||
nameTable.put(nom, shape);
|
||||
}
|
||||
@@ -2387,14 +2387,14 @@ public class PShape implements PConstants {
|
||||
/**
|
||||
* ( begin auto-generated from PShape_setFill.xml )
|
||||
*
|
||||
* The <b>setFill()</b> method defines the fill color of a <b>PShape</b>.
|
||||
* This method is used after shapes are created or when a shape is defined explicitly
|
||||
* (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in the above example.
|
||||
* When a shape is created with <b>beginShape()</b> and <b>endShape()</b>, its
|
||||
* attributes may be changed with <b>fill()</b> and <b>stroke()</b> within
|
||||
* <b>beginShape()</b> and <b>endShape()</b>. However, after the shape is
|
||||
* created, only the <b>setFill()</b> method can define a new fill value for
|
||||
* the <b>PShape</b>.
|
||||
* The <b>setFill()</b> method defines the fill color of a <b>PShape</b>.
|
||||
* This method is used after shapes are created or when a shape is defined explicitly
|
||||
* (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in the above example.
|
||||
* When a shape is created with <b>beginShape()</b> and <b>endShape()</b>, its
|
||||
* attributes may be changed with <b>fill()</b> and <b>stroke()</b> within
|
||||
* <b>beginShape()</b> and <b>endShape()</b>. However, after the shape is
|
||||
* created, only the <b>setFill()</b> method can define a new fill value for
|
||||
* the <b>PShape</b>.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
*
|
||||
@@ -2543,14 +2543,14 @@ public class PShape implements PConstants {
|
||||
/**
|
||||
* ( begin auto-generated from PShape_setStroke.xml )
|
||||
*
|
||||
* The <b>setStroke()</b> method defines the outline color of a <b>PShape</b>.
|
||||
* This method is used after shapes are created or when a shape is defined
|
||||
* explicitly (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in
|
||||
* the above example. When a shape is created with <b>beginShape()</b> and
|
||||
* <b>endShape()</b>, its attributes may be changed with <b>fill()</b> and
|
||||
* <b>stroke()</b> within <b>beginShape()</b> and <b>endShape()</b>.
|
||||
* However, after the shape is created, only the <b>setStroke()</b> method
|
||||
* can define a new stroke value for the <b>PShape</b>.
|
||||
* The <b>setStroke()</b> method defines the outline color of a <b>PShape</b>.
|
||||
* This method is used after shapes are created or when a shape is defined
|
||||
* explicitly (e.g. <b>createShape(RECT, 20, 20, 80, 80)</b>) as shown in
|
||||
* the above example. When a shape is created with <b>beginShape()</b> and
|
||||
* <b>endShape()</b>, its attributes may be changed with <b>fill()</b> and
|
||||
* <b>stroke()</b> within <b>beginShape()</b> and <b>endShape()</b>.
|
||||
* However, after the shape is created, only the <b>setStroke()</b> method
|
||||
* can define a new stroke value for the <b>PShape</b>.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
*
|
||||
@@ -2891,7 +2891,10 @@ public class PShape implements PConstants {
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
/**
|
||||
* Return true if this x, y coordinate is part of this shape. Only works
|
||||
* with PATH shapes or GROUP shapes that contain other GROUPs or PATHs.
|
||||
*/
|
||||
public boolean contains(float x, float y) {
|
||||
if (family == PATH) {
|
||||
// apply the inverse transformation matrix to the point coordinates
|
||||
@@ -2900,7 +2903,8 @@ public class PShape implements PConstants {
|
||||
inverseCoords.invert(); // maybe cache this?
|
||||
PVector p = new PVector();
|
||||
inverseCoords.mult(new PVector(x,y),p);
|
||||
|
||||
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
boolean c = false;
|
||||
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
|
||||
if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) &&
|
||||
@@ -2913,19 +2917,18 @@ public class PShape implements PConstants {
|
||||
}
|
||||
}
|
||||
return c;
|
||||
|
||||
} else if (family == GROUP) {
|
||||
// If this is a group, loop through children until we find one that
|
||||
// contains the supplied coordinates. If a child does not support contains()
|
||||
// just throw a warning and continue.
|
||||
// If this is a group, loop through children until we find one that
|
||||
// contains the supplied coordinates. If a child does not support
|
||||
// contains() throw a warning and continue.
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
try {
|
||||
if (children[i].contains(x, y)) return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
PGraphics.showWarning(e);
|
||||
}
|
||||
if (children[i].contains(x, y)) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
} else {
|
||||
// https://github.com/processing/processing/issues/1280
|
||||
throw new IllegalArgumentException("The contains() method is only implemented for paths.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ X https://github.com/processing/processing/pull/5475
|
||||
contrib
|
||||
X Fixed a crash occuring while loading certain SVGs exported from Illustrator
|
||||
X https://github.com/processing/processing/pull/5526
|
||||
X Support PShape.contains() on GROUP objects
|
||||
X https://github.com/processing/processing/pull/5550
|
||||
X Improve implementation of PShape.contains() to take the CTM into account
|
||||
X https://github.com/processing/processing/pull/5549
|
||||
|
||||
|
||||
3.4
|
||||
_ add circle() and square()
|
||||
|
||||
Reference in New Issue
Block a user