class Terraformer::MultiPoint
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Terraformer::Geometry::new
# File lib/terraformer/multi_point.rb, line 5 def initialize *args case when Point === args[0] self.coordinates = args.map &:coordinates else super *args end # must be an array of coordinates unless Array === coordinates && Terraformer::Coordinate === coordinates[0] raise ArgumentError.new 'invalid coordinates for Terraformer::MultiPoint' end end
Public Instance Methods
==(obj)
click to toggle source
Calls superclass method
Terraformer::Geometry#==
# File lib/terraformer/multi_point.rb, line 28 def == obj super obj do |o| self.coordinates.sort == obj.coordinates.sort end end
add_point(p)
click to toggle source
# File lib/terraformer/multi_point.rb, line 55 def add_point p p = p.coordinates if Point === p raise ArgumentError unless Coordinate === p coordinates << p end
Also aliased as: <<
contains?(obj)
click to toggle source
# File lib/terraformer/multi_point.rb, line 34 def contains? obj points.any? {|p| p.contains? obj} end
first_coordinate()
click to toggle source
# File lib/terraformer/multi_point.rb, line 20 def first_coordinate coordinates[0] end
insert_point(idx, p)
click to toggle source
# File lib/terraformer/multi_point.rb, line 62 def insert_point idx, p p = p.coordinates if Point === p raise ArgumentError unless Coordinate === p coordinates.insert idx, p end
points()
click to toggle source
# File lib/terraformer/multi_point.rb, line 24 def points coordinates.map {|p| Point.new p} end
remove_point(p)
click to toggle source
# File lib/terraformer/multi_point.rb, line 68 def remove_point p p = p.coordinates if Point === p raise ArgumentError unless Coordinate === p coordinates.delete p end
remove_point_at(idx)
click to toggle source
# File lib/terraformer/multi_point.rb, line 74 def remove_point_at idx coordinates.delete_at idx end
within?(obj)
click to toggle source
# File lib/terraformer/multi_point.rb, line 38 def within? obj case obj when MultiPoint points.all? {|p| obj.contains? p} when LineString points.all? {|p| obj.contains? p} when MultiLineString points.all? {|p| obj.contains? p} when Polygon obj.contains? self when MultiPolygon points.all? {|p| obj.polygons.any? {|polygon| polygon.contains? p}} else raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}" end end