class Terraformer::LineString
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Terraformer::Geometry::new
# File lib/terraformer/line_string.rb, line 5 def initialize *args super *args # must be an array of coordinates unless Array === coordinates && Terraformer::Coordinate === coordinates[0] raise ArgumentError.new 'invalid coordinates for Terraformer::LineString' end end
Public Instance Methods
add_vertex(p)
click to toggle source
# File lib/terraformer/line_string.rb, line 71 def add_vertex 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/line_string.rb, line 29 def contains? obj case obj when Point lines.any? {|l| Geometry.line_contains_point? l, obj.coordinates} when LineString self == obj or coordinates.slice_exists? obj.coordinates # todo this does not case for a line string of different coordinates # that is actually contained yet when MultiLineString obj.line_strings.all? {|ls| ls.within? self} else raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}" end end
first_coordinate()
click to toggle source
# File lib/terraformer/line_string.rb, line 15 def first_coordinate coordinates[0] end
insert_vertex(idx, p)
click to toggle source
# File lib/terraformer/line_string.rb, line 78 def insert_vertex idx, p p = p.coordinates if Point === p raise ArgumentError unless Coordinate === p coordinates.insert idx, p end
linear_ring?()
click to toggle source
# File lib/terraformer/line_string.rb, line 19 def linear_ring? coordinates.length > 3 and coordinates.first == coordinates.last end
lines()
click to toggle source
# File lib/terraformer/line_string.rb, line 23 def lines ls = [] coordinates.each_cons(2) {|l| ls << l} ls end
point_at(idx)
click to toggle source
# File lib/terraformer/line_string.rb, line 66 def point_at idx coordinates[idx].to_point end
Also aliased as: vertex_at
points()
click to toggle source
# File lib/terraformer/line_string.rb, line 61 def points coordinates.map &:to_point end
Also aliased as: vertices
remove_vertex(p)
click to toggle source
# File lib/terraformer/line_string.rb, line 84 def remove_vertex p p = p.coordinates if Point === p raise ArgumentError unless Coordinate === p coordinates.delete p end
remove_vertex_at(idx)
click to toggle source
# File lib/terraformer/line_string.rb, line 90 def remove_vertex_at idx coordinates.delete_at idx end
within?(obj)
click to toggle source
# File lib/terraformer/line_string.rb, line 44 def within? obj case obj when LineString self == obj or obj.coordinates.slice_exists? coordinates # todo this does not case for a line string of different coordinates # that is actually contained yet when MultiLineString obj.line_strings.any? {|ls| ls.contains? self} when Polygon obj.contains? self when MultiPolygon obj.polygons.any? {|p| p.contains? self} else raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}" end end