def random_rectangle(max_side, min_side, sigma=0.5, ratio=1.0, coherce=True):
assert min_side <= max_side
#
half_side = (max_side-min_side)/2
center = max_side-half_side
width = random.normalvariate(0, sigma)*half_side
height = random.normalvariate(0, sigma)*half_side
#
if ratio > 1:
height = height/ratio
else:
width = width*ratio
# Coherce value to max
if coherce:
width = coherce_to(max_side, min_side, width+center)
height = coherce_to(max_side, min_side, height+center)
return width, height
评论列表
文章目录