Skip to content

PShape.contains() is broken for transformed shapes (double invert) #1445

@avinxshKD

Description

@avinxshKD

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions