Skip to content

Commit 2974a68

Browse files
asinghvi17claude
andcommitted
Add test for empty polygon geometry
Tests that npoint and nring return 0 for empty polygons, verifying the init=0 fix works correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 2fa2f3b commit 2974a68

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/test_primitives.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct MyPoint end
88
struct MyEmptyPoint end
99
struct MyCurve end
1010
struct MyPolygon end
11+
struct MyEmptyPolygon end
1112
struct MyTriangle end
1213
struct MyMultiPoint end
1314
struct MyMultiCurve end
@@ -46,6 +47,12 @@ GeoInterface.ngeom(::PolygonTrait, geom::MyPolygon) = 2
4647
GeoInterface.getgeom(::PolygonTrait, geom::MyPolygon, i) = MyCurve()
4748
GeoInterface.ncoord(t::PolygonTrait, geom::MyPolygon) = 2
4849

50+
GeoInterface.isgeometry(::Type{MyEmptyPolygon}) = true
51+
GeoInterface.geomtrait(::MyEmptyPolygon) = PolygonTrait()
52+
GeoInterface.ngeom(::PolygonTrait, geom::MyEmptyPolygon) = 0
53+
GeoInterface.getgeom(::PolygonTrait, geom::MyEmptyPolygon, i) = nothing
54+
GeoInterface.isempty(::PolygonTrait, geom::MyEmptyPolygon) = true
55+
4956
GeoInterface.isgeometry(::Type{MyTriangle}) = true
5057
GeoInterface.geomtrait(::MyTriangle) = TriangleTrait()
5158
GeoInterface.ngeom(::TriangleTrait, geom::MyTriangle) = 3
@@ -173,6 +180,11 @@ GeoInterface.crs(::RasterTrait, ::Raster) = GeoFormatTypes.EPSG(4326)
173180
@test GeoInterface.nring(geom) == 1
174181
@test GeoInterface.nhole(geom) == 0
175182
@test GeoInterface.npoint(geom) == 3
183+
184+
geom = MyEmptyPolygon()
185+
@test GeoInterface.isempty(geom)
186+
@test GeoInterface.nring(geom) == 0
187+
@test GeoInterface.npoint(geom) == 0
176188
end
177189

178190
@testset "MultiPoint" begin

0 commit comments

Comments
 (0)