From e3cdf379651c1366a35ab8d9c6fdc338c33b5bfc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 15 Jun 2018 16:16:58 +0200 Subject: [PATCH] Support PShape.contains() on GROUP objects by looping through its children (unsupported children will be skipped gracefully) --- core/src/processing/core/PShape.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 7d6f1d7a5..830c0b391 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -2906,6 +2906,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. + for (int i = 0; i < childCount; i++) { + try { + if (children[i].contains(x, y)) return true; + } catch (IllegalArgumentException e) { + PGraphics.showWarning(e); + } + } + return false; } else { throw new IllegalArgumentException("The contains() method is only implemented for paths."); }