Skip to content
Permalink
4fd9083563
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
41 lines (31 sloc) 1.01 KB
import random
class Coord:
def __init__( self, x=0, y=0 ):
self.x = int(x)
self.y = int(y)
def __eq__( self, other ):
return self.x == other.x and self.y == other.y
def randomise( self, range, coord=None ):
if coord is None:
self.x = random.randint( 0, range )
self.y = random.randint( 0, range )
return
x = random.gauss( coord.x, range/10 )
y = random.gauss( coord.y, range/10 )
if x < 0 : x = 0
if y < 0 : y = 0
if x > range : x = range
if y > range : y = range
self.x = int(x)
self.y = int(y)
class Point( Coord ):
def __init__( self, x=0, y=0, cluster=0 ):
Coord.__init__( self, x, y )
self.cluster = cluster
class Centroid( Coord ):
__counter = 0
def __init__( self, x=0, y=0 ):
self.cluster = Centroid.__counter
Centroid.__counter += 1
def __repr__( self ):
return f"Centroid[{self.cluster}] @ ({self.x},{self.y})"