Class: Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rtl/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dimsObject

Returns the value of attribute dims.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def dims
  @dims
end

#fixedObject

Returns the value of attribute fixed.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def fixed
  @fixed
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def id
  @id
end

#posObject

Returns the value of attribute pos.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def pos
  @pos
end

#radiusObject

Returns the value of attribute radius.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def radius
  @radius
end

#speedObject

Returns the value of attribute speed.



5
6
7
# File 'lib/rtl/graph.rb', line 5

def speed
  @speed
end

Instance Method Details



32
33
34
# File 'lib/rtl/graph.rb', line 32

def print_info
  pp "node #{@id} : pos=#{@pos},dims=#{@dims},v=#{@velocity}"
end

#xObject



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

#yObject



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