-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_tag.py
44 lines (29 loc) · 1.19 KB
/
node_tag.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
42
43
44
from points import Point2D
from constants import *
class Tag(object):
last_used_idx = 0
@classmethod
def pop_unused_idx(cls):
new_idx = cls.last_used_idx + 1
cls.last_used_idx = new_idx
return new_idx
def __init__(self, x, y, label):
self.idx = Tag.pop_unused_idx()
self.position = Point2D(x, y)
self.translated_position = Point2D(x, y)
self.label = label
self.net_electrostatic_force = (0, 0)
self.net_spring_force = (0, 0)
self.displacement = (0, 0)
self.velocity = (0, 0)
self.is_selected = False
def __str__(self):
s = ('%i = %s' % (self.idx, self.label)) + '\n'
s = s + ('(x,y) = (%f,%f)' % (self.position.x, self.position.y)) + '\n'
(Fx, Fy) = self.net_electrostatic_force
s = s + ('electro-static Fx, Fy = %f, %f' % (Fx, Fy)) + '\n'
(Fx, Fy) = self.net_spring_force
s = s + ('spring Fx, Fy = %f, %f' % (Fx, Fy)) + '\n'
(dx, dy) = self.displacement
s = s + ('displacement dx, dy = %f, %f' % (dx, dy)) + '\n'
return s