-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.py
31 lines (26 loc) · 1.01 KB
/
generator.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
from point import Point
import random
def readPointsFile(fileName: str):
pointsArr = []
with open(fileName) as pointsFile:
pointsFile.readline() # wywalam sobie linie z ilością
for pointString in pointsFile:
pointString = pointString.strip().split(' ')
pointString.pop(0)
pointsArr.append(Point([int(pointCoord) for pointCoord in pointString]))
return pointsArr
def generateFile(pointsArr: list, fileName: str):
with open(fileName, "w") as pointsFile:
pointsFile.write("{}".format(len(pointsArr)))
i = 1
for point in pointsArr:
pointsFile.write("\n{} {} {}".format(i, point.x, point.y))
i += 1
def generatePointsArray(n: int, rangeX=[-1000,1000], rangeY=[-1000,1000]):
# generacja tablicy punktów
allPoints = []
for _ in range(n):
x = random.randint(rangeX[0], rangeX[1])
y = random.randint(rangeY[0], rangeY[1])
allPoints.append(Point([x, y]))
return allPoints