mirror of
https://github.com/ksherlock/prez.git
synced 2025-02-22 05:29:05 +00:00
add rectangle example and fix a couple rectangle bugs.
This commit is contained in:
parent
629f90bb04
commit
feeb5f260e
17
examples/rect.prez
Normal file
17
examples/rect.prez
Normal 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
11
rect.py
@ -17,7 +17,7 @@ __all__ = ['point', 'rect', 'size']
|
|||||||
|
|
||||||
def all_defined(*args): return args.count(None)==0
|
def all_defined(*args): return args.count(None)==0
|
||||||
def all_none(*args): return args.count(None)==len(args)
|
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):
|
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,
|
def rect(*args,
|
||||||
x=None,y=None,height=None,width=None,
|
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
|
if len(args) == 4: return args
|
||||||
|
|
||||||
@ -68,7 +69,11 @@ def rect(*args,
|
|||||||
if all_defined(x,y,height,width):
|
if all_defined(x,y,height,width):
|
||||||
return (y, x, y + height, x + width)
|
return (y, x, y + height, x + width)
|
||||||
if all_defined(h1,h2,v1,v2):
|
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")
|
raise ValueError("bad rect parameter")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user