Feature request for Rectangle


In Rectangle, we lack a withXXX() method to obtain a translated copy of it (keeping its size) with a given coordinate for its bottom side, and another for its right side.

There are two withBottom() and withRight() methods, but they do a different thing: they “move” the given side while leaving the others intact, which results in a resize rather than a translation.

Also, it is currently ambiguous which of the withXXX methods return a resized version of the rectangle (for example, withTop(), withLeft(), withBottom() and withRight()), as opposed to those with a similar name that return a translated version of a rectangle (for example, withX() and withY()).


I don’t agree that the naming is currently ambiguous - the ones that use the name of an edge (i.e. withLeft, withTop etc) move that edge and resize it. The ones that have the name of a coordinate (i.e. withX etc) move the whole thing. It’s all clearly described in the docs, but I didn’t want to end up with huge names like “withBottomKeepingTopUnchanged”

Adding some methods to align the right and bottom without resizing is a good request, though I’m not 100% sure what names would be good… “movedToRight”?


movedToRight(amount) sounds like one is getting a rectangle translated to the right by the given amount.

what about translatedWithRight() instead (or movedWithRight(), too)?


Hmm, not sure. Actually, I think I may have thought about adding this method before, but never did because of failure to choose a name…


don’t give up please

withRightX, withBottomY?

(to keep the “coordinate” = “translation” convention)

EDIT: that is consistent with CentreX and CentreY notation, that is used sometimes (don’t remember if in Rectangle or Component, I’m on the phone now)


thanks for those withRightX() and withBottomY() additions.
any chance to also have setRightX() and setBottomY()?


Would rather not add any more mutating methods - if you just use withRightX and withBottomY, the compiler should be able to figure out that it boils down to the same thing that setRightX would do.