add rectangle example and fix a couple rectangle bugs.

This commit is contained in:
Kelvin Sherlock 2020-08-02 10:43:26 -04:00
parent 629f90bb04
commit feeb5f260e
2 changed files with 25 additions and 3 deletions

17
examples/rect.prez Normal file
View File

@ -0,0 +1,17 @@
#
#
#
rTwoRects(
(5, 5, 10, 20),
(5,5,10,40)
)
rRectList(
[2, 4, 15, 24],
(2, 4, 15, 24),
rect(x = 4, y = 2, height = 13, width = 20),
rect(point(x=4, y = 2), point(x = 4+20, y = 2 + 13)),
rect(h1 = 4, v1 = 2, h2 = 4 + 20, v2 = 2 + 13),
rect(top=2, left=4, right=4+20, bottom = 2 + 13)
)

11
rect.py
View File

@ -17,7 +17,7 @@ __all__ = ['point', 'rect', 'size']
def all_defined(*args): return args.count(None)==0
def all_none(*args): return args.count(None)==len(args)
def is_listy(x): type(x) in (tuple, list)
def is_listy(x): return type(x) in (tuple, list)
def point(*args, x=None, y=None, h=None, v=None):
@ -50,7 +50,8 @@ def size(*args, height=None, width=None):
def rect(*args,
x=None,y=None,height=None,width=None,
h1=None,h2=None,v1=None,v2=None):
h1=None,h2=None,v1=None,v2=None,
top=None,left=None,right=None,bottom=None):
if len(args) == 4: return args
@ -68,7 +69,11 @@ def rect(*args,
if all_defined(x,y,height,width):
return (y, x, y + height, x + width)
if all_defined(h1,h2,v1,v2):
return (v1, h2, v2, h2)
return (v1, h1, v2, h2)
if all_defined(top,left,bottom,right):
return (top, left, bottom, right)
raise ValueError("bad rect parameter")