Permalink
Cannot retrieve contributors at this time
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?
clustering/pyinclude/point.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (31 sloc)
1.01 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})" |