Repository: JuliaGeo/LibGEOS.jl
Pull request #125 (2022-07-24 20:19:26)

add Aqua testing
Some aftercare after merging #117, @evetion could you review?

Since we are about to have a breaking release, let's remove the old deprecated functions.
Adding https://github.com/JuliaTesting/Aqua.jl testing helped found some method ambiguities that are now resolved.

evetion: I'm ok with merging this if it makes Aqua happy.

However, I'd say it's unnecessary to define `GeoInterface.ngeom(::AbstractPointTrait, geom::Polygon) = 0` (and other geometries) after `GeoInterface.ngeom(::AbstractPointTrait, geom::AbstractGeometry) = 0 has been defined`. And these ambiguities would only trigger if we made a mistake in deriving the correct trait for LibGEOS geometries.
visr: > And these ambiguities would only trigger if we made a mistake in deriving the correct trait for LibGEOS geometries.

That's right. Not sure if there are additional benefits to resolving these if they are not a problem in practice. We could also exclude certain measures. https://juliatesting.github.io/Aqua.jl/dev/#Aqua.test_ambiguities-Tuple{Any}
But for now I'll go ahead and release this.

Patch:
diff --git a/Project.toml b/Project.toml
index b0fcec9..f41a4d0 100644
--- a/Project.toml
+++ b/Project.toml
@@ -17,7 +17,8 @@ GeoInterface = "1"
 julia = "1.6"
 
 [extras]
+Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
 Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
 
 [targets]
-test = ["Test"]
+test = ["Aqua", "Test"]
diff --git a/src/LibGEOS.jl b/src/LibGEOS.jl
index 67ab56a..5faf195 100644
--- a/src/LibGEOS.jl
+++ b/src/LibGEOS.jl
@@ -13,9 +13,6 @@ export Point,
     Polygon,
     MultiPolygon,
     GeometryCollection,
-    parseWKT,
-    geomFromWKT,
-    geomToWKT,
     readgeom,
     writegeom,
     project,
@@ -194,5 +191,5 @@ include("geos_types.jl")
 include("geos_operations.jl")
 include("geo_interface.jl")
 include("strtree.jl")
-include("deprecated.jl")
-end
+
+end  # module
diff --git a/src/deprecated.jl b/src/deprecated.jl
deleted file mode 100644
index 02b7c38..0000000
--- a/src/deprecated.jl
+++ /dev/null
@@ -1,10 +0,0 @@
-Base.@deprecate parseWKT(geom::String) readgeom(geom)
-Base.@deprecate geomFromWKT(geom::String) _readgeom(geom)
-Base.@deprecate geomToWKT(geom::Ptr{GEOSGeometry}) writegeom(geom)
-
-Base.@deprecate_binding CAP_ROUND GEOSBUF_CAP_ROUND
-Base.@deprecate_binding CAP_FLAT GEOSBUF_CAP_FLAT
-Base.@deprecate_binding CAP_SQUARE GEOSBUF_CAP_SQUARE
-Base.@deprecate_binding JOIN_ROUND GEOSBUF_JOIN_ROUND
-Base.@deprecate_binding JOIN_MITRE GEOSBUF_JOIN_MITRE
-Base.@deprecate_binding JOIN_BEVEL GEOSBUF_JOIN_BEVEL
diff --git a/src/geo_interface.jl b/src/geo_interface.jl
index 43f93b2..f8ecf9f 100644
--- a/src/geo_interface.jl
+++ b/src/geo_interface.jl
@@ -12,18 +12,25 @@ GeoInterface.geomtrait(geom::PreparedGeometry) = GeoInterface.geomtrait(geom.own
 
 GeoInterface.ngeom(::AbstractGeometryTrait, geom::AbstractGeometry) =
     isEmpty(geom.ptr) ? 0 : numGeometries(geom.ptr)
+GeoInterface.ngeom(::AbstractPointTrait, geom::AbstractGeometry) = 0
+
 function GeoInterface.getgeom(::AbstractGeometryTrait, geom::AbstractGeometry, i)
     clone = getGeometry(geom.ptr, i)
     id = geomTypeId(clone) + 1
     0 < id <= length(geomtypes) || error("Unknown geometry type id $id")
     geomtypes[id](clone)
 end
+
+GeoInterface.getgeom(::AbstractPointTrait, geom::AbstractGeometry, i) = nothing
 GeoInterface.ngeom(::AbstractGeometryTrait, geom::Union{LineString,LinearRing}) =
     numPoints(geom.ptr)
+GeoInterface.ngeom(t::AbstractPointTrait, geom::Union{LineString,LinearRing}) = 0
 GeoInterface.getgeom(::AbstractGeometryTrait, geom::Union{LineString,LinearRing}, i) =
     Point(getPoint(geom.ptr, i))
+GeoInterface.getgeom(::AbstractPointTrait, geom::Union{LineString,LinearRing}, i) = nothing
 
 GeoInterface.ngeom(::AbstractGeometryTrait, geom::Polygon) = numInteriorRings(geom.ptr) + 1
+GeoInterface.ngeom(::AbstractPointTrait, geom::Polygon) = 0
 function GeoInterface.getgeom(::AbstractGeometryTrait, geom::Polygon, i)
     if i == 1
         LinearRing(exteriorRing(geom.ptr))
@@ -31,22 +38,29 @@ function GeoInterface.getgeom(::AbstractGeometryTrait, geom::Polygon, i)
         LinearRing(interiorRing(geom.ptr, i - 1))
     end
 end
+GeoInterface.getgeom(::AbstractPointTrait, geom::Polygon, i) = nothing
 
-GeoInterface.ngeom(t::AbstractGeometryTrait, geom::PreparedGeometry) = GeoInterface.ngeom(t, geom.ownedby)
-GeoInterface.getgeom(t::AbstractGeometryTrait, geom::PreparedGeometry, i) = GeoInterface.getgeom(t, geom.ownedby, i)
+GeoInterface.ngeom(t::AbstractGeometryTrait, geom::PreparedGeometry) =
+    GeoInterface.ngeom(t, geom.ownedby)
+GeoInterface.ngeom(t::AbstractPointTrait, geom::PreparedGeometry) = 0
+GeoInterface.getgeom(t::AbstractGeometryTrait, geom::PreparedGeometry, i) =
+    GeoInterface.getgeom(t, geom.ownedby, i)
+GeoInterface.getgeom(t::AbstractPointTrait, geom::PreparedGeometry, i) = 0
 
 GeoInterface.ncoord(::AbstractGeometryTrait, geom::AbstractGeometry) =
     isEmpty(geom.ptr) ? 0 : getCoordinateDimension(geom.ptr)
 GeoInterface.getcoord(::AbstractGeometryTrait, geom::AbstractGeometry, i) =
     getCoordinates(getCoordSeq(geom.ptr), 1)[i]
 
-GeoInterface.ncoord(t::AbstractGeometryTrait, geom::PreparedGeometry) = GeoInterface.ncoord(t, geom.ownedby)
-GeoInterface.getcoord(t::AbstractGeometryTrait, geom::PreparedGeometry, i) = GeoInterface.getcoord(t, geom.ownedby, i)
+GeoInterface.ncoord(t::AbstractGeometryTrait, geom::PreparedGeometry) =
+    GeoInterface.ncoord(t, geom.ownedby)
+GeoInterface.getcoord(t::AbstractGeometryTrait, geom::PreparedGeometry, i) =
+    GeoInterface.getcoord(t, geom.ownedby, i)
 
 function GeoInterface.extent(::AbstractGeometryTrait, geom::AbstractGeometry)
     # minx, miny, maxx, maxy = getExtent(geom)
     env = envelope(geom)
-    return Extent(X=(getXMin(env), getXMax(env)), Y=(getYMin(env), getYMax(env)))
+    return Extent(X = (getXMin(env), getXMax(env)), Y = (getYMin(env), getYMax(env)))
 end
 
 function Base.convert(::Type{T}, geom::T) where {T<:AbstractGeometry}
@@ -76,32 +90,94 @@ function Base.convert(::Type{MultiPolygon}, type::MultiPolygonTrait, geom)
     return MultiPolygon(GeoInterface.coordinates(geom))
 end
 
-function Base.convert(
-    t::Type{<:AbstractGeometry},
-    type::AbstractGeometryTrait,
-    geom,
-)
+function Base.convert(t::Type{<:AbstractGeometry}, type::AbstractGeometryTrait, geom)
     error(
         "Cannot convert an object of $(typeof(geom)) with the $(typeof(type)) trait to a $t (yet). Please report an issue.",
     )
     return f(GeoInterface.coordinates(geom))
 end
 
-GeoInterface.distance(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = distance(a, b)
-GeoInterface.buffer(::AbstractGeometryTrait, geom::AbstractGeometry, distance) = buffer(geom, distance)
+GeoInterface.distance(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = distance(a, b)
+GeoInterface.buffer(::AbstractGeometryTrait, geom::AbstractGeometry, distance) =
+    buffer(geom, distance)
 GeoInterface.convexhull(::AbstractGeometryTrait, geom::AbstractGeometry) = convexhull(geom)
 
-GeoInterface.equals(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = equals(a, b)
-GeoInterface.disjoint(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = disjoint(a, b)
-GeoInterface.intersects(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = intersects(a, b)
-GeoInterface.touches(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = touches(a, b)
-GeoInterface.within(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = within(a, b)
-GeoInterface.contains(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = contains(a, b)
-GeoInterface.overlaps(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = overlaps(a, b)
-GeoInterface.crosses(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = crosses(a, b)
+GeoInterface.equals(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = equals(a, b)
+GeoInterface.disjoint(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = disjoint(a, b)
+GeoInterface.intersects(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = intersects(a, b)
+GeoInterface.touches(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = touches(a, b)
+GeoInterface.within(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = within(a, b)
+GeoInterface.contains(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = contains(a, b)
+GeoInterface.overlaps(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = overlaps(a, b)
+GeoInterface.crosses(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = crosses(a, b)
 # GeoInterface.relate(::AbstractGeometryTrait, ::AbstractGeometryTrait, a, b, relationmatrix) = relate(a, b)  # not yet implemented
 
-GeoInterface.symdifference(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = symmetricDifference(a, b)
-GeoInterface.difference(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = difference(a, b)
-GeoInterface.intersection(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = intersection(a, b)
-GeoInterface.union(::AbstractGeometryTrait, ::AbstractGeometryTrait, a::AbstractGeometry, b::AbstractGeometry) = union(a, b)
+GeoInterface.symdifference(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = symmetricDifference(a, b)
+GeoInterface.difference(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = difference(a, b)
+GeoInterface.intersection(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = intersection(a, b)
+GeoInterface.union(
+    ::AbstractGeometryTrait,
+    ::AbstractGeometryTrait,
+    a::AbstractGeometry,
+    b::AbstractGeometry,
+) = union(a, b)


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 2f4b0f4..de895bd 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -1,5 +1,6 @@
 using GeoInterface, Extents
 using Test, LibGEOS
+import Aqua
 
 version = LibGEOS.GEOSversion()
 @info "GEOS version $version"
@@ -19,4 +20,5 @@ end
     include("test_regressions.jl")
     include("test_invalid_geometry.jl")
     include("test_strtree.jl")
+    Aqua.test_all(LibGEOS)
 end
diff --git a/test/test_geo_interface.jl b/test/test_geo_interface.jl
index ca779b2..7a093b4 100644
--- a/test/test_geo_interface.jl
+++ b/test/test_geo_interface.jl
@@ -5,7 +5,7 @@
     @test GeoInterface.ncoord(pt) == 2
     @test GeoInterface.getcoord(pt, 1) ≈ 1.0
     @test GeoInterface.testgeometry(pt)
-    @test GeoInterface.extent(pt) == Extent(X=(1.0, 1.0), Y=(2.0, 2.0))
+    @test GeoInterface.extent(pt) == Extent(X = (1.0, 1.0), Y = (2.0, 2.0))
 
     pt = LibGEOS.Point(1, 2)
     @test GeoInterface.coordinates(pt) ≈ [1, 2] atol = 1e-5
@@ -89,12 +89,12 @@
     ]]]
     @test GeoInterface.geomtrait(multipolygon) == MultiPolygonTrait()
     @test GeoInterface.testgeometry(multipolygon)
-    @test GeoInterface.extent(multipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
+    @test GeoInterface.extent(multipolygon) == Extent(X = (0.0, 10.0), Y = (0.0, 10.0))
 
     pmultipolygon = LibGEOS.prepareGeom(multipolygon)
     @test GeoInterface.geomtrait(pmultipolygon) == MultiPolygonTrait()
     @test GeoInterface.testgeometry(pmultipolygon)
-    @test GeoInterface.extent(pmultipolygon) == Extent(X=(0.0, 10.0), Y=(0.0, 10.0))
+    @test GeoInterface.extent(pmultipolygon) == Extent(X = (0.0, 10.0), Y = (0.0, 10.0))
     LibGEOS.destroyGeom(pmultipolygon)
 
     geomcollection = LibGEOS.readgeom(
diff --git a/test/test_geos_operations.jl b/test/test_geos_operations.jl
index daee74c..2f5ac1d 100644
--- a/test/test_geos_operations.jl
+++ b/test/test_geos_operations.jl
@@ -385,14 +385,15 @@ end
     @test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 0.1) isa
           LibGEOS.MultiPolygon
     @test buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa LibGEOS.Polygon
-    @test GeoInterface.buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa LibGEOS.Polygon
+    @test GeoInterface.buffer(MultiPoint([[1.0, 1.0], [2.0, 2.0], [2.0, 0.0]]), 10) isa
+          LibGEOS.Polygon
 
     # bufferWithStyle
     g1 = bufferWithStyle(
         readgeom("LINESTRING(0 0,0 1,1 1)"),
         0.1,
-        endCapStyle=LibGEOS.GEOSBUF_CAP_FLAT,
-        joinStyle=LibGEOS.GEOSBUF_JOIN_BEVEL,
+        endCapStyle = LibGEOS.GEOSBUF_CAP_FLAT,
+        joinStyle = LibGEOS.GEOSBUF_JOIN_BEVEL,
     )
     g2 = readgeom(
         "POLYGON((-0.1 0.0,-0.1 1.0,0.0 1.1,1.0 1.1,1.0 0.9,0.1 0.9,0.1 0.0,-0.1 0.0))",
@@ -403,8 +404,8 @@ end
     g1 = bufferWithStyle(
         readgeom("LINESTRING(0 0,0 1,1 1)"),
         0.1,
-        endCapStyle=LibGEOS.GEOSBUF_CAP_SQUARE,
-        joinStyle=LibGEOS.GEOSBUF_JOIN_MITRE,
+        endCapStyle = LibGEOS.GEOSBUF_CAP_SQUARE,
+        joinStyle = LibGEOS.GEOSBUF_JOIN_MITRE,
     )
     g2 =
         readgeom("POLYGON((-0.1 -0.1,-0.1 1.1,1.1 1.1,1.1 0.9,0.1 0.9,0.1 -0.1,-0.1 -0.1))")
@@ -413,7 +414,7 @@ end
     g1 = bufferWithStyle(
         readgeom("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"),
         0.2,
-        joinStyle=LibGEOS.GEOSBUF_JOIN_MITRE,
+        joinStyle = LibGEOS.GEOSBUF_JOIN_MITRE,
     )
     g2 = readgeom("POLYGON((-1.2 1.2,1.2 1.2,1.2 -1.2,-1.2 -1.2,-1.2 1.2))")
     @test equals(g1, g2)