In B4A v6.30 we got Rect.Width and Rect.Height properties which I use a lot.
But is it working correctly? This may or may not be a bug. I don't know.
In the past I always measure width as
Width = Right-Left+1
Height = Bottom-Top+1
This of course assumes the origin (0,0) is at the top left corner as it is with View positions.
So if a point is located at (0,0) and has a width=1 and height=1, shouldn't Right=0 and Bottom=0?
This means it starts and finishes on that 1 pixel located at (0,0). The Rectangle would be (0,0,0,0) and represents a single point.
a) If you agree with that, then Rect.Width and Rect.Height are not working correctly. Here is a code example.
b) If my statement in a) is incorrect, then it has to be calculated as:
Width = Right-Left
Height = Bottom-Top
But this seems strange to me because Rect.Right and Rect.Bottom are one more than necessary.
Can someone clarify?
TIA
But is it working correctly? This may or may not be a bug. I don't know.
In the past I always measure width as
Width = Right-Left+1
Height = Bottom-Top+1
This of course assumes the origin (0,0) is at the top left corner as it is with View positions.
So if a point is located at (0,0) and has a width=1 and height=1, shouldn't Right=0 and Bottom=0?
This means it starts and finishes on that 1 pixel located at (0,0). The Rectangle would be (0,0,0,0) and represents a single point.
a) If you agree with that, then Rect.Width and Rect.Height are not working correctly. Here is a code example.
B4X:
Private locRect As Rect
'Example #1
locRect.Initialize(0,0,0,0)
Log(locRect& " Width="&locRect.Width&" Height="&locRect.Height)
'Log Output: (Rect)(0, 0, 0, 0) Width=0 Height=0
'Why isn't Width=1 and Height=1?
'Example #2
locRect.Width = 1
locRect.Height = 1
Log(locRect& " Width="&locRect.Width&" Height="&locRect.Height)
'Log Output: (Rect)(0, 0, 1, 1) Width=1 Height=1
'Why isn't Rect=(0,0,0,0)
'Example #3
locRect.Left=1
locRect.Right=2
locRect.Top=1
locRect.Bottom=2
Log(locRect& " Width="&locRect.Width&" Height="&locRect.Height)
'Log Output: (Rect)(1, 1, 2, 2) Width=1 Height=1
'Why isn't Width=2 and Height=2?
b) If my statement in a) is incorrect, then it has to be calculated as:
Width = Right-Left
Height = Bottom-Top
But this seems strange to me because Rect.Right and Rect.Bottom are one more than necessary.
Can someone clarify?
TIA