Method: Dse::Geometry::Polygon#initialize
- Defined in:
- lib/dse/geometry/polygon.rb
#initialize(*args) ⇒ Polygon
Returns a new instance of Polygon.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dse/geometry/polygon.rb', line 44 def initialize(*args) # The constructor has two forms: # 1. 0 or more LineString objects where the first is the exterior ring and the rest are interior rings. # 2. one String arg as the wkt representation. if args.size == 1 && args.first.is_a?(String) # subsitute eol chars in the string with a space. wkt = args.first.gsub(EOL_RE, ' ') # Consolidate whitespace before/after commas and parens. wkt.gsub!(/\s*([,\(\)])\s*/, '\1') if wkt == 'POLYGON EMPTY' @rings = [].freeze else match = wkt.match(WKT_RE) raise ArgumentError, "#{wkt.inspect} is not a valid WKT representation of a polygon" unless match @rings = parse_wkt_internal(match[1]) end else @rings = args.freeze @rings.each do |ring| Cassandra::Util.assert_instance_of(LineString, ring, "#{ring.inspect} is not a LineString") end end end |