Class: Automaton::Layout::Node
- Inherits:
-
Object
- Object
- Automaton::Layout::Node
- Defined in:
- lib/layout.rb
Overview
A spring connected, repulsing node used by the spring force algorithm
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#position ⇒ Object
Returns the value of attribute position.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
- #attraction(other) ⇒ Object
- #connect(*nodes) ⇒ Object
- #connected?(other) ⇒ Boolean
-
#initialize(name, x, y) ⇒ Node
constructor
A new instance of Node.
- #repulsion(other) ⇒ Object
- #speed ⇒ Object
- #to_a ⇒ Object
- #vector(other) ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
Constructor Details
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
55 56 57 |
# File 'lib/layout.rb', line 55 def connections @connections end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
54 55 56 |
# File 'lib/layout.rb', line 54 def name @name end |
#position ⇒ Object
Returns the value of attribute position.
55 56 57 |
# File 'lib/layout.rb', line 55 def position @position end |
#velocity ⇒ Object
Returns the value of attribute velocity.
55 56 57 |
# File 'lib/layout.rb', line 55 def velocity @velocity end |
Instance Method Details
#attraction(other) ⇒ Object
79 80 81 82 83 |
# File 'lib/layout.rb', line 79 def attraction(other) return Vector[0, 0] unless connected?(other) vector = vector(other) vector.unit * -(ATTRACTION * (SPRING_LENGTH - vector.r.abs)) end |
#connect(*nodes) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/layout.rb', line 63 def connect(*nodes) @connections = @connections | nodes.to_set @connections.each do |node| node.connect(self) unless node.connected?(self) end end |
#connected?(other) ⇒ Boolean
70 71 72 |
# File 'lib/layout.rb', line 70 def connected?(other) @connections.member?(other) end |
#repulsion(other) ⇒ Object
74 75 76 77 |
# File 'lib/layout.rb', line 74 def repulsion(other) vector = vector(other) vector.unit * REPULSION * (1 / (4 * Math::PI * vector.r**2)) end |
#speed ⇒ Object
89 90 91 |
# File 'lib/layout.rb', line 89 def speed velocity.r end |
#to_a ⇒ Object
101 102 103 |
# File 'lib/layout.rb', line 101 def to_a [name, x, y] end |
#vector(other) ⇒ Object
85 86 87 |
# File 'lib/layout.rb', line 85 def vector(other) other.position - self.position end |
#x ⇒ Object
93 94 95 |
# File 'lib/layout.rb', line 93 def x position[0] end |
#y ⇒ Object
97 98 99 |
# File 'lib/layout.rb', line 97 def y position[1] end |