Skip to content

Commit

Permalink
Add tests for polygon ring methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yeesian authored and visr committed Sep 4, 2022
1 parent 443006d commit 39921d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LibGEOS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export Point,
hasZ,
isClosed,
isValid,
interiorRing,
interiorRings,
exteriorRing,
numGeometries,
Expand Down
2 changes: 1 addition & 1 deletion src/geos_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ getGeometries(obj::Geometry, context::GEOSContext = _context) =
# Converts Geometry to normal form (or canonical form).
normalize!(obj::Geometry) = normalize!(obj.ptr)

interiorRing(obj::Polygon, n::Integer) = interiorRing(obj.ptr, n)
interiorRing(obj::Polygon, n::Integer) = LinearRing(interiorRing(obj.ptr, n))
interiorRings(obj::Polygon) = map(LinearRing, interiorRings(obj.ptr))
exteriorRing(obj::Polygon) = LinearRing(exteriorRing(obj.ptr))

Expand Down
13 changes: 13 additions & 0 deletions test/test_geos_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ end
# Geometry info
# -----

@testset "Polygon ring(s)" begin
poly = readgeom(
"POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))",
)
@test LibGEOS.getCoordinates(LibGEOS.getCoordSeq(exteriorRing(poly).ptr)) ==
Vector{Float64}[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]]
@test length(interiorRings(poly)) == 1
@test LibGEOS.getCoordinates(LibGEOS.getCoordSeq(interiorRing(poly, 1).ptr)) ==
Vector{Float64}[[20, 30], [35, 35], [30, 20], [20, 30]]
@test_throws ErrorException interiorRing(poly, 0)
@test_throws ErrorException interiorRing(poly, 2)
end

@testset "numGeometries" begin
@test numGeometries(readgeom("POINT(2 2)")) == 1
@test numGeometries(readgeom("MULTIPOINT(0 0, 5 0, 10 0)")) == 3
Expand Down

0 comments on commit 39921d6

Please sign in to comment.