Class: Contrek::Finder::Node
- Inherits:
-
Object
- Object
- Contrek::Finder::Node
- 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
-
#abs_x_index ⇒ Object
Returns the value of attribute abs_x_index.
-
#data_pointer ⇒ Object
readonly
Returns the value of attribute data_pointer.
-
#inner_index ⇒ Object
Returns the value of attribute inner_index.
-
#inner_left_index ⇒ Object
Returns the value of attribute inner_left_index.
-
#inner_right_index ⇒ Object
Returns the value of attribute inner_right_index.
-
#lower_end ⇒ Object
readonly
Returns the value of attribute lower_end.
-
#lower_start ⇒ Object
readonly
Returns the value of attribute lower_start.
-
#max_x ⇒ Object
readonly
Returns the value of attribute max_x.
-
#min_x ⇒ Object
readonly
Returns the value of attribute min_x.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outer_index ⇒ Object
Returns the value of attribute outer_index.
-
#tangs_count ⇒ Object
readonly
Returns the value of attribute tangs_count.
-
#tangs_sequence ⇒ Object
readonly
Returns the value of attribute tangs_sequence.
-
#track ⇒ Object
Returns the value of attribute track.
-
#upper_end ⇒ Object
readonly
Returns the value of attribute upper_end.
-
#upper_start ⇒ Object
readonly
Returns the value of attribute upper_start.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #add_intersection(other_node, other_node_index) ⇒ Object
- #coords_entering_to(enter_to, enter_mode, tracking) ⇒ Object
- #get_tangent_node_by_virtual_index(virtual_index) ⇒ Object
-
#initialize(cluster, min_x, max_x, y, name, connectivity_offset = 0) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #my_next(last, versus, mode) ⇒ Object
- #ne_point ⇒ Object
- #nw_point ⇒ Object
- #precalc_tangs_sequences(cluster:) ⇒ Object
- #se_point ⇒ Object
- #sw_point ⇒ Object
- #track_complete ⇒ Object
- #track_uncomplete ⇒ Object
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 |
# 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 + 1 @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 @cluster = cluster cluster.add_node(self, connectivity_offset) end |
Instance Attribute Details
#abs_x_index ⇒ Object
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_pointer ⇒ Object (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 |
#inner_index ⇒ Object
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_index ⇒ Object
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_index ⇒ Object
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_end ⇒ Object (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_start ⇒ Object (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_x ⇒ Object (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_x ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def name @name end |
#outer_index ⇒ Object
Returns the value of attribute outer_index.
10 11 12 |
# File 'lib/contrek/finder/node.rb', line 10 def outer_index @outer_index end |
#tangs_count ⇒ Object (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_sequence ⇒ Object (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 |
#track ⇒ Object
Returns the value of attribute track.
10 11 12 |
# File 'lib/contrek/finder/node.rb', line 10 def track @track end |
#upper_end ⇒ Object (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_start ⇒ Object (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 |
#y ⇒ Object (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
146 147 148 149 150 151 152 153 154 |
# File 'lib/contrek/finder/node.rb', line 146 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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/contrek/finder/node.rb', line 108 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.se_point else enter_to.track |= TURNER[tracking][OMIN - 1] point = node_up.sw_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.nw_point else enter_to.track |= TURNER[tracking][OMAX - 1] point = node_down.ne_point end end point end |
#get_tangent_node_by_virtual_index(virtual_index) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/contrek/finder/node.rb', line 58 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 |
#inspect ⇒ Object
54 55 56 |
# File 'lib/contrek/finder/node.rb', line 54 def inspect "#<#{self.class} id:#{@id} name:\"#{@name}\">" end |
#my_next(last, versus, mode) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/contrek/finder/node.rb', line 83 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 |
#ne_point ⇒ Object
71 72 73 |
# File 'lib/contrek/finder/node.rb', line 71 def ne_point {x: max_x, y: y} end |
#nw_point ⇒ Object
67 68 69 |
# File 'lib/contrek/finder/node.rb', line 67 def nw_point {x: min_x, y: y} end |
#precalc_tangs_sequences(cluster:) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/contrek/finder/node.rb', line 156 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 |
#se_point ⇒ Object
75 76 77 |
# File 'lib/contrek/finder/node.rb', line 75 def se_point {x: max_x, y: y + 1} end |
#sw_point ⇒ Object
79 80 81 |
# File 'lib/contrek/finder/node.rb', line 79 def sw_point {x: min_x, y: y + 1} end |