def __init__(self, points = np.array([]), dimensions = (None, None), granularity = None):
"""
Creates the Voronoi object
:param points: predefined points
:type points: numpy array of shape (w, 2) where w is the number of points [x, y] style, default None
:param dimensions: dimensions of the points, from [w, 2] where w is the highest value, this *cannot* be None if points is None
:type dimensions: tuple of ints, maximum (x,y) dimensions, default None
:param granularity: how many points to create, must be given if dimensions are given
:type granularity: int, default None
"""
if len(points) == 0 and dimensions == (None, None):
print('You can\'t have both points and dimensions be empty, try passing in some points or dimensions and granularity.')
return
if len(points) == 0 and dimensions != None and granularity == None:
print('Granularity can\'t be none if dimensions are passed in, try passing in a granularity.')
return
if len(points) != 0:
self.points = points
else:
points = np.random.random((granularity, 2))
points = list(map(lambda x: np.array([x[0]*dimensions[0], x[1]*dimensions[1]]), points))
self.points = np.array(points)
self.bounding_region = [min(self.points[:, 0]), max(self.points[:, 0]), min(self.points[:, 1]), max(self.points[:, 1])]
评论列表
文章目录