Closed hsauro closed 2 years ago
Would it be better to return a point class than a list for coordinates? It would make handling the coordinates much easier.
eg
p = la.getNodePosition('ATP')
print (p.x, p.y)
This is clearer than using
print (p[0], p[1])
Here is a suitable point class one could use:
import math
class Point: def init(self,x_init,y_init): self.x = x_init self.y = y_init
def __add__(self, other): return Point(self.x + other.x, self.y + other.y) def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def move(self, dx, dy): '''Determines where x and y move''' self.x = self.x + dx self.y = self.y + dy def distance(self, other): dx = self.x - other.x dy = self.y - other.y return math.sqrt(dx**2 + dy**2) def __repr__(self): return "".join(["Point(", str(self.x), ",", str(self.y), ")"])
p1 = Point(10, 3) p2 = Point(1, 0)
fixed. I have updated all the get functions related to positions and sizes from list to point. The examples are also added due to its complex.
Would it be better to return a point class than a list for coordinates? It would make handling the coordinates much easier.
eg
p = la.getNodePosition('ATP')
print (p.x, p.y)
This is clearer than using
print (p[0], p[1])
Here is a suitable point class one could use:
import math
class Point: def init(self,x_init,y_init): self.x = x_init self.y = y_init
p1 = Point(10, 3) p2 = Point(1, 0)