mac-comp127 / kilt-graphics

Graphics and UI library for learning software development principles in Java
https://mac-comp127.github.io/kilt-graphics/
2 stars 17 forks source link

GraphicsGroup should remove children by identity, not equality #18

Closed pcantrell closed 3 years ago

pcantrell commented 3 years ago

Description

GraphicsObjects compare equal by shape and position, but clients will expect group.remove(object) to remove the specific object they name, name just any GraphicsObject that compares equal.

Steps to Reproduce

GraphicsGroup group = new GraphicsGroup();
Rectangle r1 = new Rectangle(0, 0, 1, 1);
Rectangle r2 = new Rectangle(0, 0, 1, 1);
Rectangle r3 = new Rectangle(0, 0, 1, 1);
group.add(r1);
group.add(r2);
group.add(r3);
group.remove(r2);

Expected behavior

Group should contain [r2, r3].

Actual behavior

Group contains [r1, r3].

Reported by @andrewbethke.