-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.py
41 lines (33 loc) · 1.14 KB
/
cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#implementation of class cluster
import csv
from point import Point
class Cluster:
points = [] # points in cluster
id = None # identification of cluster
def __init__(self, id, inPoints=None):
if inPoints:
self.points = inPoints
self.id = id
def __str__(self): #TODO what about ID?
stringList = []
for point in self.points:
stringList.append(str(point))
return str(stringList)
def __eq__(self, other):
if (self.id != other.id):
return False
if (len(self.points) != len(other.points)):
return False
i = 0
while i < len(self.points):
if (self.points[i] != other.points[i]):
return False
i += 1
return True
def append(self, point):
self.points.append(point)
def writeFile(self, out_file):
with open(out_file, 'a', newline='') as csv_file:
data_writer = csv.writer(csv_file, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for point in self.points:
data_writer.writerow([self.id] + point.coors)