diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77487a29..16ade19d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: version: - - '1.6' + - '1.10' - '1' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index 459f5b57..84eca27d 100644 --- a/Project.toml +++ b/Project.toml @@ -6,13 +6,18 @@ version = "0.5.9" [deps] EarCut_jll = "5ae413db-bbd1-5e63-b57d-d24a61df00f5" Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910" -GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +[weakdeps] +GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" + +[extensions] +GeometryBasicsGeoInterfaceExt = "GeoInterface" + [compat] Aqua = "0.8" EarCut_jll = "2" @@ -26,14 +31,15 @@ PrecompileTools = "1.0" Random = "<0.0.1,1" StaticArrays = "0.6, 1" Test = "<0.0.1,1" -julia = "1.6" +julia = "1.10" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9" +GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "GeoJSON", "Test", "Random", "OffsetArrays"] +test = ["Aqua", "GeoInterface", "GeoJSON", "OffsetArrays", "Random", "Test"] diff --git a/src/geointerface.jl b/ext/GeometryBasicsGeoInterfaceExt.jl similarity index 97% rename from src/geointerface.jl rename to ext/GeometryBasicsGeoInterfaceExt.jl index f806fc27..ed5da70b 100644 --- a/src/geointerface.jl +++ b/ext/GeometryBasicsGeoInterfaceExt.jl @@ -1,3 +1,10 @@ +module GeometryBasicsGeoInterfaceExt + +using GeoInterface, GeometryBasics + +import GeometryBasics: geointerface_geomtype +using GeometryBasics: Ngon + # Implementation of trait based interface from https://github.com/JuliaGeo/GeoInterface.jl/ GeoInterface.isgeometry(::Type{<:AbstractGeometry}) = true @@ -104,12 +111,6 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom) return Point{2,T}(x, y) end end - -# without a function barrier you get a lot of allocations from runtime types -function _collect_with_type(::Type{PT}, geom) where {PT <: Point{2}} - return [PT(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)] -end - function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom) g1 = getgeom(geom, 1) x, y = GeoInterface.x(g1), GeoInterface.y(g1) @@ -122,7 +123,6 @@ function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom) return LineString(_collect_with_type(Point{2, T}, geom)) end end - function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom) t = LineStringTrait() exterior = GeoInterface.convert(LineString, t, GeoInterface.getexterior(geom)) @@ -133,7 +133,6 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom) return Polygon(exterior, interiors) end end - function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom) g1 = getgeom(geom, 1) x, y = GeoInterface.x(g1), GeoInterface.y(g1) @@ -146,18 +145,18 @@ function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom) return MultiPoint([Point{2,T}(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)]) end end - function GeoInterface.convert(::Type{MultiLineString}, type::MultiLineStringTrait, geom) t = LineStringTrait() return MultiLineString(map(l -> GeoInterface.convert(LineString, t, l), getgeom(geom))) end - function GeoInterface.convert(::Type{MultiPolygon}, type::MultiPolygonTrait, geom) t = PolygonTrait() return MultiPolygon(map(poly -> GeoInterface.convert(Polygon, t, poly), getgeom(geom))) end -function Extents.extent(rect::Rect2) - (xmin, ymin), (xmax, ymax) = extrema(rect) - return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax)) -end \ No newline at end of file +# without a function barrier you get a lot of allocations from runtime types +function _collect_with_type(::Type{PT}, geom) where {PT <: Point{2}} + return [PT(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)] +end + +end diff --git a/src/GeometryBasics.jl b/src/GeometryBasics.jl index 887e691c..d01865ae 100644 --- a/src/GeometryBasics.jl +++ b/src/GeometryBasics.jl @@ -1,7 +1,6 @@ module GeometryBasics using IterTools, LinearAlgebra, StaticArrays -using GeoInterface import Extents using EarCut_jll import Base: * @@ -27,8 +26,6 @@ include("triangulation.jl") include("lines.jl") include("boundingboxes.jl") -include("geointerface.jl") - export AbstractGeometry, GeometryPrimitive export Mat, Point, Vec export LineFace, Polytope, Line, NgonFace, convert_simplex @@ -71,4 +68,8 @@ if Base.VERSION >= v"1.8" include("precompiles.jl") end +# Needed for GeometryBasicsGeoInterfaceExt. +# In future this can go away as can use Module dispatch. +function geointerface_geomtype end + end # module diff --git a/src/primitives/rectangles.jl b/src/primitives/rectangles.jl index fa51a216..912161a4 100644 --- a/src/primitives/rectangles.jl +++ b/src/primitives/rectangles.jl @@ -582,3 +582,12 @@ function faces(::Rect3) (3, 4, 8, 7), (1, 3, 7, 5), (6, 8, 4, 2) ] end + +function Extents.extent(rect::Rect2) + (xmin, ymin), (xmax, ymax) = extrema(rect) + return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax)) +end +function Extents.extent(rect::Rect3) + (xmin, ymin, zmin), (xmax, ymax, zmax) = extrema(rect) + return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax), Z=(zmin, zmax)) +end diff --git a/test/geointerface.jl b/test/geointerface.jl index 31c7de38..1c62aee7 100644 --- a/test/geointerface.jl +++ b/test/geointerface.jl @@ -123,4 +123,9 @@ end ext = extent(rect) @test ext.X == (0.0f0, 1.0f0) @test ext.Y == (0.0f0, 1.0f0) -end \ No newline at end of file + rect = Rect3f(Vec3f(0), Vec3f(1.0)) + ext = extent(rect) + @test ext.X == (0.0f0, 1.0f0) + @test ext.Y == (0.0f0, 1.0f0) + @test ext.Z == (0.0f0, 1.0f0) +end