Bug? Rectangle error

enonod

Well-Known Member
Licensed User
Longtime User
B4A Enterprise version 5.50

I have initialized a rectangle as left 397, top 43, width 43, height 43.
being an odd number of pixels it will have a perfect centre.
The IDE reports this rectangle as left 397, right 440 and CenterX as 418.
That indeed 'indicates' a width of 43 however...

The centre pixel is given by int((440 - 397)/2)+1 which is 22.
i.e. the 22nd pixel counting from the left inclusive. That indeed is pixel 418.

Equally, counting from the right inclusive, the 22nd pixel should be the same centre, 418 but it is in fact 419.
Therefore the reported Right should be 439 (not 440) to make this correct.

Wherever a rectangle is reported its left and right pixels should both be even or both be odd numbers if the inclusive pixels are odd. Reduce this to five pixels numbered 2,3,4,5,6 or 7,8,9,10,11; note also that the centre pixel follows suit in each case.

The reported example I began with does not obey this rule.
Conclusion: Whilst arithmetically 'looking' correct, there appears to be a 'fence posts and gaps' problem.
The reported Right is one too many.
 

enonod

Well-Known Member
Licensed User
Longtime User
Rect.CenterX / CenterY are calculated using the native Android methods.

Note that the Initialize method parameters are: Left, Top, Right, Bottom.
Thank you for responding and I apologise for my stupidity and your wasted time.

I should change the carpenter's adage to 'Think twice write once'
 
Top