Just stumbled across this and wonder why this basic function is missing. It is absolutely useful to get the extent of a Rectangle as a Point, so it can be passed on to other functions more easily:
The problem with this to me is that a Point is semantically different to a âsizeâ.
Personally Iâd like to see a juce::Size class where a Rectangle contains Point and Size members.
When Iâve had to return sizes of things that donât have a location, Iâve always used a Rectangle with zero origin as the methods of Rectangle are much better for making the size bigger or smaller.
IIRC the reason I didnât do that was some kind of symbol clash (this was many years ago). Probably would be something we could add now without any problem though, and yes, agreed that itâd be nice.
Kind of, but it would be a smaller interface as wouldnât have all the origin stuff.
Itâs more so you can be more expressive about the intent and inform callers that youâre not interested in the origin of a Rectangle or a returned object doesnât have any relevance.
Also, if you add a setSize (Rectangle<Type>) method, it would be ambiguous, if the origin is taken into account or not (kind of what @dave96 said already).
I wouldnât look at this too philosophically. Even then, the size of a Rectangle is equivalent to the local coordinate of its bottom-right corner. And thatâs a Point.
Oh, and Point does not necessarily denote âlocationâ (e.g. unity vectors, matrices)
It would be an issue if width and height used different base types, but AFAIK thatâs not the case.
But youâve hit one of the main objections there - what set of basis vectors are the coordinates of your point based on? ([1, 0], [0, 1]) or ([1, 0], [0, -1])? A point can have a negative extent in each direction, but what does a negative size mean?
Iâd argue that Point is very much âlocationâ. How are Points used with vectors and matrices where they donât represent offsets in each dimension from an origin?
Getting this stuff right is very important when youâre providing an API.
Exactly what I was talking about: Size is the offset from the origin. Negative size is not defined and can be eliminated easily. A rectangle with negative size is invalid anyway (corners swappend)
I think weâre talking at cross-purposes. Itâs obvious, mechanically, how you can use a Point as a size, but youâve needed to use the words âSize is the offset from the originâ to explain how to go from an inherently Point-y thing to a Size.
Just checked Smalltalk and there are several hundred senders and several dozen implementors of âextentâ. So, if the sacred mothership of OO used it for decades, in a world of philosophical purity where the null pointer is an instance of class UndefinedObject, it canât possibly be wrong
I think the term size is just perfect, no need to find a different one. The objection was to express a size using a Point or a zero positioned Rectangle.
Maybe it could be reassessed, if Size still collides. FWIW, I defined a struct Size in my engine with no problems.
Actually both Point and Size are subclasses of Pair<x,y>, which is the purely âmechanicalâ thing they are based on, only that Point and Size slightly differ in semantics.
Whether, in the context of the Juce library, making Size a class of its own is useful, I donât know. So yes, temporarily superimposing âSizeâ semantics on a Point for the sake of being able to return a function result, means bending the ontology a bit.
Another solution would be to make getSize() return a pair and have it implicitly convert to Point when used as such?