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.
-
#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 ⇒ Object
readonly
Returns the value of attribute tangs.
-
#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.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #add_intersection(other_node) ⇒ Object
- #coords_entering_to(enter_to, enter_mode, tracking) ⇒ Object
-
#initialize(cluster, min_x, max_x, y, name) ⇒ Node
constructor
A new instance of Node.
- #my_next(last, versus, mode) ⇒ Object
- #precalc_tangs_sequences ⇒ Object
- #tangs?(node) ⇒ Boolean
- #tangs_with_x?(x) ⇒ Boolean
- #track_complete ⇒ Object
- #track_uncomplete ⇒ Object
Constructor Details
#initialize(cluster, min_x, max_x, y, name) ⇒ Node
Returns a new instance of Node.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/contrek/finder/node.rb', line 27 def initialize(cluster, min_x, max_x, y, name) @name = name @min_x = min_x @max_x = max_x @y = y @tangs = {T_UP => [], T_DOWN => []} @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 cluster.add_node(self) end |
Instance Attribute Details
#abs_x_index ⇒ Object
Returns the value of attribute abs_x_index.
7 8 9 |
# File 'lib/contrek/finder/node.rb', line 7 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 |
#inner_index ⇒ Object
Returns the value of attribute inner_index.
7 8 9 |
# File 'lib/contrek/finder/node.rb', line 7 def inner_index @inner_index 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.
7 8 9 |
# File 'lib/contrek/finder/node.rb', line 7 def outer_index @outer_index end |
#tangs ⇒ Object (readonly)
Returns the value of attribute tangs.
6 7 8 |
# File 'lib/contrek/finder/node.rb', line 6 def tangs @tangs 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.
7 8 9 |
# File 'lib/contrek/finder/node.rb', line 7 def track @track 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) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/contrek/finder/node.rb', line 100 def add_intersection(other_node) if other_node.y < y @tangs[T_UP] << other_node else @tangs[T_DOWN] << other_node end end |
#coords_entering_to(enter_to, enter_mode, tracking) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/contrek/finder/node.rb', line 76 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 ds = tangs_sequence[enter_to_index] coords_source = ds.send(enter_mode) enter_to.track |= TURNER[tracking][coords_source[:m] - 1] coords_source[:point] end |
#my_next(last, versus, mode) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/contrek/finder/node.rb', line 49 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 tangs_sequence.at(last_node_index) end |
#precalc_tangs_sequences ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/contrek/finder/node.rb', line 108 def precalc_tangs_sequences @tangs_sequence = Array.new(tangs[T_UP].size + tangs[T_DOWN].size) tangs = self.tangs[T_UP].sort_by(&:min_x) n = -1 @up_indexer = -tangs[0].abs_x_index if tangs.size > 0 tangs.each do |t_node| nd = Contrek::Finder::PolygonFinder::NodeDescriptor.new(t_node, {point: {x: t_node.max_x, y: t_node.y}, m: OMAX}, {point: {x: t_node.min_x, y: t_node.y}, m: OMIN}) tangs_sequence[n += 1] = nd end tangs = self.tangs[T_DOWN].sort_by(&:min_x).reverse @down_indexer = (tangs.last.abs_x_index + self.tangs[T_DOWN].size + self.tangs[T_UP].size - 1) if tangs.size > 0 tangs.each do |t_node| nd = Contrek::Finder::PolygonFinder::NodeDescriptor.new(t_node, {point: {x: t_node.min_x, y: t_node.y}, m: OMIN}, {point: {x: t_node.max_x, y: t_node.y}, m: OMAX}) tangs_sequence[n += 1] = nd end @tangs_count = tangs_sequence.size end |
#tangs?(node) ⇒ Boolean
45 46 47 |
# File 'lib/contrek/finder/node.rb', line 45 def tangs?(node) @min_x <= node.max_x && node.min_x <= @max_x end |
#tangs_with_x?(x) ⇒ Boolean
88 89 90 |
# File 'lib/contrek/finder/node.rb', line 88 def tangs_with_x?(x) x.between?(@min_x, @max_x) end |
#track_complete ⇒ Object
96 97 98 |
# File 'lib/contrek/finder/node.rb', line 96 def track_complete (@track & OCOMPLETE) == OCOMPLETE end |
#track_uncomplete ⇒ Object
92 93 94 |
# File 'lib/contrek/finder/node.rb', line 92 def track_uncomplete (@track & OCOMPLETE) != OCOMPLETE end |