test_stats.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:rectpack 作者: secnot 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号