Sha256: df3f54dc2d91596dfa3462be547b0a57e01280dd993ec5e987c98a6a05bc633e

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

module JpmGeo
  # Bounds is a bounding box defined by two Points.
  # If the bounding box crosses the 180th meridian, there will be two sets of bounding boxes
  # defined by four Points.
  class Bounds
    attr_reader :points, :radians

    def [](index)
      to_a[index]
    end

    def to_a
      points
    end

    def size
      points.size
    end

    def to_radians
      return self if radians

      Bounds.from_points(*points.collect(&:to_radians))
    end

    def to_degrees
      return self unless radians

      Bounds.from_points(*points.collect(&:to_degrees))
    end

    def to_s
      "JpmGeo::Bounds[#{points}]"
    end

    class << self
      def from_points(*points)
        new(*points)
      end
    end

    private

    def initialize(*points)
      @points = points
      @radians = points[0].radians
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jpm_geo-0.1.1 lib/jpm_geo/bounds.rb