Sha256: bee6933a2ce7aedf299169910974083e97aef5feab7e5b17c1afc734f6c9c063

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module NSWTopo
  module Labels
    class Barrier
      class Segment
        def initialize(segment, barrier)
          @segment, @barrier = segment, barrier
          @bounds = @segment.transpose.map(&:minmax).map do |min, max|
            [min - barrier.buffer, max + barrier.buffer]
          end
        end
        attr_reader :barrier, :bounds

        def conflicts_with?(segment, buffer: 0)
          [@segment, segment].overlap?(@barrier.buffer + buffer)
        end
      end

      def initialize(feature, buffer)
        @feature, @buffer = feature, buffer
      end
      attr_reader :buffer

      def segments
        case @feature
        when GeoJSON::Point
          [[@feature.coordinates] * 2]
        when GeoJSON::LineString
          @feature.coordinates.segments
        when GeoJSON::Polygon
          @feature.coordinates.flat_map do |coordinates|
            coordinates.segments
          end
        end.map do |segment|
          Segment.new segment, self
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nswtopo-3.0.1 lib/nswtopo/layer/labels/barrier.rb
nswtopo-3.0 lib/nswtopo/layer/labels/barrier.rb