#! /usr/bin/python3
# ===================================================================
# test/verify round function
# ===================================================================
# if very accurate positioning of the center of a window
# is important, the window width and height should be an
# odd number number of pixels.
# why...
# the width and height are the number of pixels in a given
# direction (x,y) and start counting at 1. pixel coordinates start
# from 0. With even sided windows (for example 800,400) the
# center coordinates have a fractional part (i.e. 399.5,199.5).
# the problem is converting window sizes to window coordinates.
# for example, given a window size of 8 or 9 ...
#
# windows size 8 window size 9
# count coord count coord
# 1 0 1 0
# 2 1 2 1
# 3 2 3 2
# 4 3 4 3
# 5 4 5 4
# 6 5 6 5
# 7 6 7 6
# 8 7 8 7
# 9 8
#
# with size 8, the center is beween coordinates 4 and 5.
# with size 9, the center is exactly coordinate 4.
# ===================================================================
def test_round(winx,winy):
midx = winx/2
midy = winy/2
rmidx = round(midx)
rmidy = round(midy)
print()
print(f'winx = {winx:<6} {type(winx)}')
print(f'winy = {winy:<6} {type(winy)}')
print(f'winx/2 = {midx:<6} {type(midx)}')
print(f'winy/2 = {midy:<6} {type(midy)}')
print(f'round(winx/2) = {rmidx:<7} {type(rmidx)}')
print(f'round(winy/2) = {rmidy:<7} {type(rmidy)}')
# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------
test_round(10,6)
test_round(11,7)
print()