Class: NSWTopo::Labels::Barriers

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nswtopo/layer/labels/barriers.rb

Instance Method Summary collapse

Constructor Details

#initializeBarriers

Returns a new instance of Barriers.



4
5
6
# File 'lib/nswtopo/layer/labels/barriers.rb', line 4

def initialize
  @barriers, @cache = [], Hash[]
end

Instance Method Details

#to_procObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/nswtopo/layer/labels/barriers.rb', line 11

def to_proc
  @index ||= RTree.load(@barriers.flat_map(&:explode), &:bounds)
  @proc ||= lambda do |label_hull, buffer|
    @cache[[buffer, label_hull.coordinates]] ||= @index.search(label_hull.bounds, buffer).with_object Set[] do |barrier_hull, barriers|
      next if barriers === barrier_hull.source
      next unless ConvexHulls.overlap?(barrier_hull, label_hull, buffer)
      barriers << barrier_hull.source
    end
  end
end