Skip to content

Commit 631dfae

Browse files
committed
Clean up MultiPolygon initializer
1 parent 1683ce6 commit 631dfae

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/geoscript/geom/multipolygon.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
module GeoScript
22
module Geom
33
JTSMultiPolygon = com.vividsolutions.jts.geom.MultiPolygon
4+
JTSPolygon = com.vividsolutions.jts.geom.Polygon unless defined?(JTSPolygon)
45

56
class MultiPolygon < JTSMultiPolygon
67
include GeoScript::Geom
78

89
attr_accessor :bounds
910

1011
def initialize(*polygons)
11-
polys = []
12-
13-
if polygons.first.kind_of? JTSMultiPolygon
14-
multi_polygon = polygons.first
15-
for i in range(0...multi_polygon.num_geometries)
16-
polys << multi_polygon.get_geometry_n(i)
17-
end
18-
else
19-
polygons.each do |polygon|
20-
if polygon.kind_of? Java::ComVividsolutionsJtsGeom::Polygon
21-
polys << polygon
22-
else
23-
polys << Polygon.new(*polygon)
12+
polys =
13+
if polygons.first.kind_of? JTSMultiPolygon
14+
mp = polygons.first
15+
16+
[].tap do |p|
17+
for i in 0...mp.num_geometries
18+
p << mp.geometry_n(i)
19+
end
20+
end
21+
else
22+
[].tap do |p|
23+
polygons.each do |polygon|
24+
p << (polygon.kind_of?(JTSPolygon) ? polygon : Polygon.new(*polygon))
25+
end
2426
end
2527
end
26-
end
28+
2729
super(polys.to_java(com.vividsolutions.jts.geom.Polygon), GEOM_FACTORY)
2830
end
2931

0 commit comments

Comments
 (0)