Although a rectangle can be defined in a number of ways, the number of constructors for Rectangle is somewhat limited. This is due to the fact that many ways of defining a rectangle have overlapping function parameter prototypes; for instance, a rectangle could be defined as 4 integers; these 4 integers could represent (x, y, width, height), or (minExtentX, minExtentY, maxExtentX, maxExtentY). Because there is no way to differentiate between these methods in the constructor, currently Rectangle "chooses" one (x, y, width, height), and allows the other to be defined by specifying 2 Coords (maxExtent, minExtent).
While this certainly is functional, in certain cases it could be undesirable. From a "clean-code" standpoint, being forced to create Coords in-line with function calls can make code harder to read (and is in general something the library tries to prevent requiring). In addition, using Coords in general outside the pre-allocated range of Coords, if done very frequently, could cause performance degradation due to constant garbage collection/reallocation. Obviously one could be careful not to use a constructor for a Rectangle that requires a Coord in this case, however the math involved, while simple, could prove inconvenient.
Therefore, I propose the addition of either static functions of the Rectangle class, or static functions of some other class RectangleCreators
or some such, that simply take parameters and create an appropriate rectangle. These are effectively constructors, with the advantage of being able to change names of functions to differentiate between identical prototypes CreateWithSize(int x, int y, int width, int height)
vs CreateWithExtents(int minX, int minY, int maxX, int maxY)
.
This would require no modification of existing constructors (since they do cover many common cases), and would allow some convenience in cases where the parameter specification method doesn't precisely match an available constructor prototype.