processing / processing/processing4
PShape.contains() is broken for transformed shapes (double invert)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 494
- Forks
- 183
- Avg merge
- 4h 39m
- Merged PRs (30d)
- 3
Description
contains() in PShape is inverting the matrix twice, so it cancels itself out and hit-testing runs in the wrong space.
In PShape.java:
PMatrix inverseCoords = matrix.get();
inverseCoords.invert();
inverseCoords.invert();
inverseCoords.mult(new PVector(x, y), p);
That second invert() should not be there.
So for translated/rotated/scaled shapes, contains(x, y) gives wrong answers.
Quick repro:
PShape s = createShape(RECT, 0, 0, 50, 50);
s.translate(100, 100);
println(s.contains(120, 120)); // false, should be true
Expected: point-in-shape test respects the shape transform.
Actual: transform handling is wrong because inverse matrix is never actually applied.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in PShape.java at contains(), where the issue identifies two consecutive matrix inversions. Run the supplied translated-rectangle repro and verify that removing the extra inversion makes contains(120, 120) return true for the transformed shape.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100