Class: Underpass::WayChain
- Inherits:
-
Object
- Object
- Underpass::WayChain
- Defined in:
- lib/underpass/way_chain.rb
Overview
Chains way node sequences that share endpoints into complete rings.
Used internally by Shape.multipolygon_from_relation to merge multiple way segments into closed linear rings.
Constant Summary collapse
- MERGE_STRATEGIES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ ->(cur, seq) { cur.last == seq.first ? cur + seq[1..] : nil }, ->(cur, seq) { cur.last == seq.last ? cur + seq.reverse[1..] : nil }, ->(cur, seq) { cur.first == seq.last ? seq + cur[1..] : nil }, ->(cur, seq) { cur.first == seq.first ? seq.reverse + cur[1..] : nil } ].freeze
Instance Method Summary collapse
-
#initialize(way_ids, ways) ⇒ WayChain
constructor
Creates a new WayChain from way IDs and a way lookup table.
-
#merged_sequences ⇒ Array<Array<Integer>>
Merges node sequences that share endpoints into continuous rings.
Constructor Details
#initialize(way_ids, ways) ⇒ WayChain
Creates a new WayChain from way IDs and a way lookup table.
21 22 23 24 25 26 27 28 |
# File 'lib/underpass/way_chain.rb', line 21 def initialize(way_ids, ways) @sequences = way_ids.filter_map do |way_id| way = ways[way_id] next unless way way[:nodes].dup end end |
Instance Method Details
#merged_sequences ⇒ Array<Array<Integer>>
Merges node sequences that share endpoints into continuous rings.
33 34 35 36 37 38 39 40 |
# File 'lib/underpass/way_chain.rb', line 33 def merged_sequences return @sequences if @sequences.empty? remaining = @sequences.dup current = remaining.shift current, remaining = merge_all(current, remaining) [current, *remaining] end |