def line_lattice_points(vertices):
""" Return number of points on boundary line not including vertices
"""
assert len(vertices)==2, "not a line: %s" % vertices
xspan = abs(vertices[0][0] - vertices[1][0])
yspan = abs(vertices[0][1] - vertices[1][1])
ret = 0
if xspan == 0 and yspan == 0:
ret = 0
elif xspan == 0:
ret = yspan - 1
elif yspan == 0:
ret = xspan - 1
elif xspan == yspan:
ret = xspan - 1
elif yspan > xspan:
ret = gcd(yspan, xspan) - 1
elif xspan > yspan:
ret = gcd(xspan, yspan) - 1
print "line_lattice_points %s=%d" % (vertices, ret)
return ret
评论列表
文章目录