Class: DPTM6::Path::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/dptm6/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, op) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
# File 'lib/dptm6/path.rb', line 6

def initialize(x, y, op)
  @x = x.to_f
  @y = y.to_f
  @op = op.to_sym
end

Instance Attribute Details

#nextObject

Returns the value of attribute next.



4
5
6
# File 'lib/dptm6/path.rb', line 4

def next
  @next
end

#opObject (readonly)

Returns the value of attribute op.



3
4
5
# File 'lib/dptm6/path.rb', line 3

def op
  @op
end

#prevObject

Returns the value of attribute prev.



4
5
6
# File 'lib/dptm6/path.rb', line 4

def prev
  @prev
end

#xObject (readonly)

Returns the value of attribute x.



3
4
5
# File 'lib/dptm6/path.rb', line 3

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



3
4
5
# File 'lib/dptm6/path.rb', line 3

def y
  @y
end

Instance Method Details

#connect(next_node) ⇒ Object



12
13
14
15
16
# File 'lib/dptm6/path.rb', line 12

def connect(next_node)
  self.next = next_node
  next_node.prev = self
  self
end

#output(op = @op) ⇒ Object



29
30
31
32
# File 'lib/dptm6/path.rb', line 29

def output(op = @op)
  @op = nil
  "%g %g %s " % [@x, @y, op]
end

#reconnect(opp_node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/dptm6/path.rb', line 18

def reconnect(opp_node)
  # assume that self.x == opp_node.x && self.y == opp_node.y
  if (self.next.x == opp_node.prev.x && self.next.y == opp_node.prev.y)
    opp_node.prev.connect(self.next)
    self.connect(opp_node)
    self
  else
    nil
  end
end