MCPcopy Index your code
hub / github.com/processing/processing / contains

Method contains

core/src/processing/core/PShape.java:2964–3004  ·  view source on GitHub ↗

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.

(float x, float y)

Source from the content-addressed store, hash-verified

2962 * with PATH shapes or GROUP shapes that contain other GROUPs or PATHs.
2963 */
2964 public boolean contains(float x, float y) {
2965 if (family == PATH) {
2966 PVector p = new PVector(x, y);
2967 if (matrix != null) {
2968 // apply the inverse transformation matrix to the point coordinates
2969 PMatrix inverseCoords = matrix.get();
2970 // TODO why is this called twice? [fry 190724]
2971 // commit was https://github.com/processing/processing/commit/027fc7a4f8e8d0a435366eae754304eea282512a
2972 inverseCoords.invert(); // maybe cache this?
2973 inverseCoords.invert(); // maybe cache this?
2974 inverseCoords.mult(new PVector(x, y), p);
2975 }
2976
2977 // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
2978 boolean c = false;
2979 for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
2980 if (((vertices[i][Y] > p.y) != (vertices[j][Y] > p.y)) &&
2981 (p.x <
2982 (vertices[j][X]-vertices[i][X]) *
2983 (y-vertices[i][Y]) /
2984 (vertices[j][1]-vertices[i][Y]) +
2985 vertices[i][X])) {
2986 c = !c;
2987 }
2988 }
2989 return c;
2990
2991 } else if (family == GROUP) {
2992 // If this is a group, loop through children until we find one that
2993 // contains the supplied coordinates. If a child does not support
2994 // contains() throw a warning and continue.
2995 for (int i = 0; i < childCount; i++) {
2996 if (children[i].contains(x, y)) return true;
2997 }
2998 return false;
2999
3000 } else {
3001 // https://github.com/processing/processing/issues/1280
3002 throw new IllegalArgumentException("The contains() method is only implemented for paths.");
3003 }
3004 }
3005
3006
3007 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Callers 10

parseFontMethod · 0.45
displayDensityMethod · 0.45
makeGraphicsMethod · 0.45
handleKeyEventMethod · 0.45
createInputRawMethod · 0.45
loadBytesMethod · 0.45
calcSketchPathMethod · 0.45
dataFileMethod · 0.45
parseOBJMethod · 0.45
getMethod · 0.45

Calls 3

invertMethod · 0.95
multMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected