Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/rtl/graph.rb
Instance Attribute Summary collapse
-
#dims ⇒ Object
Returns the value of attribute dims.
-
#fixed ⇒ Object
Returns the value of attribute fixed.
-
#id ⇒ Object
Returns the value of attribute id.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#speed ⇒ Object
Returns the value of attribute speed.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Node
constructor
A new instance of Node.
- #print_info ⇒ Object
- #x ⇒ Object
- #x=(v) ⇒ Object
- #y ⇒ Object
- #y=(v) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rtl/graph.rb', line 6 def initialize params={} puts "creating node #{params}" @id =params["id"] @radius=params["radius"] || rand(5..10) @pos =Vector.new *params["pos"] @speed =Vector.new *(params["speed"] || [0,0]) @fixed =Vector.new *(params["fixed"] || [false,false]) @dims =Vector.new *(params["dims"] || [10,5]) end |
Instance Attribute Details
#dims ⇒ Object
Returns the value of attribute dims.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def dims @dims end |
#fixed ⇒ Object
Returns the value of attribute fixed.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def fixed @fixed end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def id @id end |
#pos ⇒ Object
Returns the value of attribute pos.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def pos @pos end |
#radius ⇒ Object
Returns the value of attribute radius.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def radius @radius end |
#speed ⇒ Object
Returns the value of attribute speed.
5 6 7 |
# File 'lib/rtl/graph.rb', line 5 def speed @speed end |
Instance Method Details
#print_info ⇒ Object
32 33 34 |
# File 'lib/rtl/graph.rb', line 32 def print_info pp "node #{@id} : pos=#{@pos},dims=#{@dims},v=#{@velocity}" end |
#x ⇒ Object
24 25 26 |
# File 'lib/rtl/graph.rb', line 24 def x @pos.first end |
#x=(v) ⇒ Object
16 17 18 |
# File 'lib/rtl/graph.rb', line 16 def x=(v) @pos[0]=v end |
#y ⇒ Object
28 29 30 |
# File 'lib/rtl/graph.rb', line 28 def y @pos.last end |
#y=(v) ⇒ Object
20 21 22 |
# File 'lib/rtl/graph.rb', line 20 def y=(v) @pos[1]=v end |