Closed ldicker83 closed 4 years ago
We don't have a Vector
class yet, but constructing from two Point_2d
or Point_2df
can be done as mins
and maxs
(i.e. the smallest x/y and largest x/y) then derive the mW
and mH
values to reduce confusion with Rectangle(x, y, w, h)
.
I'm a little unclear what you mean by mins
and maxs
, though mathematically a Vector
is defined by Point
subtraction:
Vector vector = p2 - p1;
This implies the Point
class has an operator-
that looks something like:
Vector Point::operator-(Point rhs);
There would be no corresponding operator-=
, since the data type of the result is different from operator's class type.
mins
: The smallest x value and smallest y value pair contained by the rectangle i.e. a corner of the rectangle.
maxs
: The largest x value and largest y value pair contained by the rectangle i.e. the opposite corner of the rectangle.
I have to be deliberately vague because "smallest" by default according to Allegro 5/SDL2/windows is towards the upper left of the screen but to OpenGL it's the lower left and DirectX/Vulkan is whatever you want it to be when you set up your viewports. Similar but different for "largest".
The math still works correctly and independently of screen coordinate orientation (handedness) when using mins/maxs
instead of x/y/w/h
Ahh. Yes. I'd have been tempted to name them something like BottomLeft
and TopRight
. That would be context specific though. I suppose more general names would be in order.
I would also be tempted to number the points, though that's not very descriptive.
From #303:
Rectangle
should provide ways to get cornerPoint
s, or a sizeVector
. From there, arithmetic can be done on thePoint
andVector
components, which can then be used to create a newRectangle
.As part of that,
Rectangle
should be constructible from either twoPoint
s, or from aPoint
and aVector
(size).Originally posted by @DanRStevens in https://github.com/lairworks/nas2d-core/issues/303#issuecomment-570127304
As a note, the title of this issue is very poor but I'm tired and can't think of a better way to name this.