Class: Contrek::Finder::Node

Inherits:
Object
  • Object
show all
Includes:
Listable
Defined in:
lib/contrek/finder/node.rb

Constant Summary collapse

T_UP =
-1
T_DOWN =
1
OMAX =
1 << 0
OMIN =
1 << 1
IMAX =
1 << 2
IMIN =
1 << 3
OCOMPLETE =
OMIN | OMAX
TURN_MAX =
IMAX | OMAX
TURN_MIN =
IMIN | OMIN
TURNER =

0 = outer 1 = inner

[[OMAX, OMIN], [TURN_MAX, TURN_MIN]]
OUTER =
0
INNER =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, min_x, max_x, y, name, connectivity_offset = 0) ⇒ Node

Returns a new instance of Node.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/contrek/finder/node.rb', line 30

def initialize(cluster, min_x, max_x, y, name, connectivity_offset = 0)
  @name = name
  @min_x = min_x
  @max_x = max_x
  @y = y
  @tangs_sequence = nil
  @tangs_count = 0
  @track = 0
  @abs_x_index = 0
  @data_pointer = cluster.lists.get_data_pointer
  @up_indexer = 0
  @down_indexer = 0
  @outer_index = -1
  @inner_index = -1
  @inner_left_index = -1
  @inner_right_index = -1
  @upper_start = Float::INFINITY
  @upper_end = -1
  @lower_start = Float::INFINITY
  @lower_end = -1
  @start_point = {x: min_x, y: y}
  @end_point = {x: max_x, y: y}
  @cluster = cluster
  cluster.add_node(self, connectivity_offset)
end

Instance Attribute Details

#abs_x_indexObject

Returns the value of attribute abs_x_index.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def abs_x_index
  @abs_x_index
end

#data_pointerObject (readonly)

Returns the value of attribute data_pointer.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def data_pointer
  @data_pointer
end

#end_pointObject (readonly)

Returns the value of attribute end_point.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def end_point
  @end_point
end

#inner_indexObject

Returns the value of attribute inner_index.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def inner_index
  @inner_index
end

#inner_left_indexObject

Returns the value of attribute inner_left_index.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def inner_left_index
  @inner_left_index
end

#inner_right_indexObject

Returns the value of attribute inner_right_index.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def inner_right_index
  @inner_right_index
end

#lower_endObject (readonly)

Returns the value of attribute lower_end.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def lower_end
  @lower_end
end

#lower_startObject (readonly)

Returns the value of attribute lower_start.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def lower_start
  @lower_start
end

#max_xObject (readonly)

Returns the value of attribute max_x.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def max_x
  @max_x
end

#min_xObject (readonly)

Returns the value of attribute min_x.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def min_x
  @min_x
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def name
  @name
end

#outer_indexObject

Returns the value of attribute outer_index.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def outer_index
  @outer_index
end

#start_pointObject (readonly)

Returns the value of attribute start_point.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def start_point
  @start_point
end

#tangs_countObject (readonly)

Returns the value of attribute tangs_count.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def tangs_count
  @tangs_count
end

#tangs_sequenceObject (readonly)

Returns the value of attribute tangs_sequence.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def tangs_sequence
  @tangs_sequence
end

#trackObject

Returns the value of attribute track.



10
11
12
# File 'lib/contrek/finder/node.rb', line 10

def track
  @track
end

#upper_endObject (readonly)

Returns the value of attribute upper_end.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def upper_end
  @upper_end
end

#upper_startObject (readonly)

Returns the value of attribute upper_start.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def upper_start
  @upper_start
end

#yObject (readonly)

Returns the value of attribute y.



8
9
10
# File 'lib/contrek/finder/node.rb', line 8

def y
  @y
end

Instance Method Details

#add_intersection(other_node, other_node_index) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'lib/contrek/finder/node.rb', line 128

def add_intersection(other_node, other_node_index)
  if other_node.y < y
    @upper_start = other_node_index if other_node_index < @upper_start
    @upper_end = other_node_index if other_node_index > @upper_end
  else
    @lower_start = other_node_index if other_node_index < @lower_start
    @lower_end = other_node_index if other_node_index > @lower_end
  end
end

#coords_entering_to(enter_to, enter_mode, tracking) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/contrek/finder/node.rb', line 90

def coords_entering_to(enter_to, enter_mode, tracking)
  enter_to_index = if enter_to.y < y
    enter_to.abs_x_index + @up_indexer
  else
    @down_indexer - enter_to.abs_x_index
  end

  tg_index = @tangs_sequence[enter_to_index]
  if tg_index < 0
    node_up = @cluster.vert_nodes[y + T_UP][-(tg_index + 1)]
    if enter_mode == :a
      enter_to.track |= TURNER[tracking][OMAX - 1]
      point = node_up.end_point
    else
      enter_to.track |= TURNER[tracking][OMIN - 1]
      point = node_up.start_point
    end
  else
    node_down = @cluster.vert_nodes[y + T_DOWN][tg_index]
    if enter_mode == :a
      enter_to.track |= TURNER[tracking][OMIN - 1]
      point = node_down.start_point
    else
      enter_to.track |= TURNER[tracking][OMAX - 1]
      point = node_down.end_point
    end
  end
  point
end

#get_tangent_node_by_virtual_index(virtual_index) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/contrek/finder/node.rb', line 56

def get_tangent_node_by_virtual_index(virtual_index)
  return nil if virtual_index.nil?
  if virtual_index < 0
    @cluster.vert_nodes[y + T_UP][-(virtual_index + 1)]
  else
    @cluster.vert_nodes[y + T_DOWN][virtual_index]
  end
end

#my_next(last, versus, mode) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/contrek/finder/node.rb', line 65

def my_next(last, versus, mode)
  last_node_index = if last.y < y
    last.abs_x_index + @up_indexer
  else
    @down_indexer - last.abs_x_index
  end

  case mode
  when :outer
    if versus == :o
      (last_node_index == tangs_sequence.size - 1) ? last_node_index = 0 : last_node_index += 1
    else
      (last_node_index == 0) ? last_node_index = tangs_sequence.size - 1 : last_node_index -= 1
    end

  when :inner
    if versus == :o
      (last_node_index == 0) ? last_node_index = tangs_sequence.size - 1 : last_node_index -= 1
    else
      (last_node_index == tangs_sequence.size - 1) ? last_node_index = 0 : last_node_index += 1
    end
  end
  get_tangent_node_by_virtual_index(@tangs_sequence.at(last_node_index))
end

#precalc_tangs_sequences(cluster:) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/contrek/finder/node.rb', line 138

def precalc_tangs_sequences(cluster:)
  @tangs_sequence = []
  @up_indexer = -cluster.vert_nodes[@y + T_UP][@upper_start].abs_x_index if @upper_end >= 0
  if @upper_end >= 0
    (@upper_start..@upper_end).each do |upper_pos|
      @tangs_sequence << -(upper_pos + 1)
    end
  end
  if @lower_end >= 0
    lower_size = (@lower_end >= 0) ? (@lower_end - @lower_start + 1) : 0
    upper_size = (@upper_end >= 0) ? (@upper_end - @upper_start + 1) : 0
    @down_indexer = (cluster.vert_nodes[@y + T_DOWN][@lower_start].abs_x_index + lower_size + upper_size - 1)
  end
  if @lower_end >= 0
    @lower_end.downto(@lower_start).each do |lower_pos|
      @tangs_sequence << lower_pos
    end
  end
  @tangs_count = tangs_sequence.size
end

#track_completeObject



124
125
126
# File 'lib/contrek/finder/node.rb', line 124

def track_complete
  (@track & OCOMPLETE) == OCOMPLETE
end

#track_uncompleteObject



120
121
122
# File 'lib/contrek/finder/node.rb', line 120

def track_uncomplete
  (@track & OCOMPLETE) != OCOMPLETE
end