config.py 文件源码

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

项目:haller 作者: bharat 项目源码 文件源码
def rotate(a, args):
    """
    Rotate panel layout by an arbitrary degree around the origin.
    """

    # Create a matrix that fits all panels and puts the origin at the center.
    # Downscale the matrix by 10x to reduce computation. Also scipy.ndimage.rotate
    # seems to have issues with large matrices where some elements get duplicated
    panels = {p['panelId']: p for p in a.panel_positions}
    for pid in panels:
        panels[pid]['x'] //= 10
        panels[pid]['y'] //= 10

    # calculate the max dimension of our bounding box, and make sure that our
    # resulting image can handle 2x the image size, in case we rotate 45 degrees
    dim = 2 * max([max(abs(p['x']), abs(p['y'])) for p in panels.values()])
    image = numpy.zeros(shape=(2 * dim, 2 * dim))

    # Put all panels in the matrix and rotate
    for (k, v) in panels.items():
        image[v['y'] + dim][v['x'] + dim] = k

    # Rotate
    r = args.rotate % 360
    rotated = ndimage.rotate(image, r, order=0, reshape=False)
    for (y, x) in numpy.transpose(numpy.nonzero(rotated)):
        p = panels[rotated[y][x]]
        p['x'] = (int(x) - dim) * 10
        p['y'] = (int(y) - dim) * 10
        p['o'] = (p['o'] + r) % 360

    # Cache the result for the future, along with the rotation we used
    config = configparser.ConfigParser()
    config.read('aurora.ini')
    config['device']['rotation'] = str(args.rotate % 360)
    config['device']['panel_positions'] = json.dumps(list(panels.values()))
    config.write(open('aurora.ini', 'w'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号