Python排序pythonsort
发布时间
阅读量:
阅读量
#排序操作
def compare(a, b):
# 计算中心点
a_center_x = a[1]["x"] + a[1]["w"] / 2
a_x = a[1]["x"]
a_center_y = a[1]["y"] + a[1]["h"] / 2
a_y = a[1]["y"]
b_center_x = b[1]["x"] + b[1]["w"] / 2
b_x = b[1]["x"]
b_center_y = b[1]["y"] + b[1]["h"] / 2
b_y = b[1]["y"]
a_height = a[1]["h"] / 2
# a_height = 2*a[1]["h"] / 3
if abs(a_center_y - b_center_y) < a_height:
# 同行:返回-1,代表排序保持不变
# 返回1,代表交换顺序
if a_x < b_x:
return -1
eli
全部评论 (0)
还没有任何评论哟~
