danilopucci
Well-Known Member
Hello guys,
I am currently experimenting some codes on OTClient and I have a conceptual question about width/height in Rect class
There is a bunch of "+1" and "-1" corrections on its values, which does not look right. I am blowing my mind trying to understand that and why and how it works as it is used all over the code.
As an example:
The width of a rectangle it is given only of x2 - x1 and not x2 -x1 + 1
Does anybody has an explanation about this approach? I have searched on openCV and other math/graphical libraries and the width is like I said above (as the math says).
On I first saw it on default constructor x2 and y2 is set as -1, I though that the bunch of "+1" was some offset compensation, but it is not.
Thank you
I am currently experimenting some codes on OTClient and I have a conceptual question about width/height in Rect class
There is a bunch of "+1" and "-1" corrections on its values, which does not look right. I am blowing my mind trying to understand that and why and how it works as it is used all over the code.
As an example:
C++:
TRect(T x, T y, T width, T height) : x1(x), y1(y), x2(x+width-1), y2(y+height-1) { }
T width() const { return x2 - x1 + 1; }
T height() const { return y2 - y1 + 1; }
The width of a rectangle it is given only of x2 - x1 and not x2 -x1 + 1
Does anybody has an explanation about this approach? I have searched on openCV and other math/graphical libraries and the width is like I said above (as the math says).
On I first saw it on default constructor x2 and y2 is set as -1, I though that the bunch of "+1" was some offset compensation, but it is not.
Thank you