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.
-
#end_point ⇒ Object
readonly
Returns the value of attribute end_point.
-
#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.
-
#start_point ⇒ Object
readonly
Returns the value of attribute start_point.
-
#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.
- #my_next(last, versus, mode) ⇒ Object
- #precalc_tangs_sequences(cluster:) ⇒ 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.
28 29 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 28 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_index ⇒ Object
Returns the value of attribute abs_x_index.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def abs_x_index @abs_x_index end |
#data_pointer ⇒ Object (readonly)
Returns the value of attribute data_pointer.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def data_pointer @data_pointer end |
#end_point ⇒ Object (readonly)
Returns the value of attribute end_point.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def end_point @end_point end |
#inner_index ⇒ Object
Returns the value of attribute inner_index.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def inner_index @inner_index end |
#inner_left_index ⇒ Object
Returns the value of attribute inner_left_index.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def inner_left_index @inner_left_index end |
#inner_right_index ⇒ Object
Returns the value of attribute inner_right_index.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def inner_right_index @inner_right_index end |
#lower_end ⇒ Object (readonly)
Returns the value of attribute lower_end.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def lower_end @lower_end end |
#lower_start ⇒ Object (readonly)
Returns the value of attribute lower_start.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def lower_start @lower_start end |
#max_x ⇒ Object (readonly)
Returns the value of attribute max_x.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def max_x @max_x end |
#min_x ⇒ Object (readonly)
Returns the value of attribute min_x.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def min_x @min_x end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def name @name end |
#outer_index ⇒ Object
Returns the value of attribute outer_index.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def outer_index @outer_index end |
#start_point ⇒ Object (readonly)
Returns the value of attribute start_point.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def start_point @start_point end |
#tangs_count ⇒ Object (readonly)
Returns the value of attribute tangs_count.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def tangs_count @tangs_count end |
#tangs_sequence ⇒ Object (readonly)
Returns the value of attribute tangs_sequence.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def tangs_sequence @tangs_sequence end |
#track ⇒ Object
Returns the value of attribute track.
8 9 10 |
# File 'lib/contrek/finder/node.rb', line 8 def track @track end |
#upper_end ⇒ Object (readonly)
Returns the value of attribute upper_end.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def upper_end @upper_end end |
#upper_start ⇒ Object (readonly)
Returns the value of attribute upper_start.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def upper_start @upper_start end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def y @y end |
Instance Method Details
#add_intersection(other_node, other_node_index) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/contrek/finder/node.rb', line 126 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
88 89 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 |
# File 'lib/contrek/finder/node.rb', line 88 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
54 55 56 57 58 59 60 61 |
# File 'lib/contrek/finder/node.rb', line 54 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/contrek/finder/node.rb', line 63 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
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/contrek/finder/node.rb', line 136 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 |