Skip to content

Commit e99d96f

Browse files
authored
Move GeoInterface.jl to an extension (#263)
* move code to extension * test 1.10 not 1.6 * bump minimum julia version to 1.10
1 parent 1fc23ba commit e99d96f

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
version:
18-
- '1.6'
18+
- '1.10'
1919
- '1'
2020
os:
2121
- ubuntu-latest

Project.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ version = "0.5.9"
66
[deps]
77
EarCut_jll = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
88
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
9-
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
109
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
1110
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1211
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1312
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1413
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1514

15+
[weakdeps]
16+
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
17+
18+
[extensions]
19+
GeometryBasicsGeoInterfaceExt = "GeoInterface"
20+
1621
[compat]
1722
Aqua = "0.8"
1823
EarCut_jll = "2"
@@ -26,14 +31,15 @@ PrecompileTools = "1.0"
2631
Random = "<0.0.1,1"
2732
StaticArrays = "0.6, 1"
2833
Test = "<0.0.1,1"
29-
julia = "1.6"
34+
julia = "1.10"
3035

3136
[extras]
3237
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3338
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
39+
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
3440
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3541
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3642
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3743

3844
[targets]
39-
test = ["Aqua", "GeoJSON", "Test", "Random", "OffsetArrays"]
45+
test = ["Aqua", "GeoInterface", "GeoJSON", "OffsetArrays", "Random", "Test"]

src/geointerface.jl renamed to ext/GeometryBasicsGeoInterfaceExt.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module GeometryBasicsGeoInterfaceExt
2+
3+
using GeoInterface, GeometryBasics
4+
5+
import GeometryBasics: geointerface_geomtype
6+
using GeometryBasics: Ngon
7+
18
# Implementation of trait based interface from https://github.com/JuliaGeo/GeoInterface.jl/
29

310
GeoInterface.isgeometry(::Type{<:AbstractGeometry}) = true
@@ -104,12 +111,6 @@ function GeoInterface.convert(::Type{Point}, type::PointTrait, geom)
104111
return Point{2,T}(x, y)
105112
end
106113
end
107-
108-
# without a function barrier you get a lot of allocations from runtime types
109-
function _collect_with_type(::Type{PT}, geom) where {PT <: Point{2}}
110-
return [PT(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)]
111-
end
112-
113114
function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
114115
g1 = getgeom(geom, 1)
115116
x, y = GeoInterface.x(g1), GeoInterface.y(g1)
@@ -122,7 +123,6 @@ function GeoInterface.convert(::Type{LineString}, type::LineStringTrait, geom)
122123
return LineString(_collect_with_type(Point{2, T}, geom))
123124
end
124125
end
125-
126126
function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
127127
t = LineStringTrait()
128128
exterior = GeoInterface.convert(LineString, t, GeoInterface.getexterior(geom))
@@ -133,7 +133,6 @@ function GeoInterface.convert(::Type{Polygon}, type::PolygonTrait, geom)
133133
return Polygon(exterior, interiors)
134134
end
135135
end
136-
137136
function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom)
138137
g1 = getgeom(geom, 1)
139138
x, y = GeoInterface.x(g1), GeoInterface.y(g1)
@@ -146,18 +145,18 @@ function GeoInterface.convert(::Type{MultiPoint}, type::MultiPointTrait, geom)
146145
return MultiPoint([Point{2,T}(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)])
147146
end
148147
end
149-
150148
function GeoInterface.convert(::Type{MultiLineString}, type::MultiLineStringTrait, geom)
151149
t = LineStringTrait()
152150
return MultiLineString(map(l -> GeoInterface.convert(LineString, t, l), getgeom(geom)))
153151
end
154-
155152
function GeoInterface.convert(::Type{MultiPolygon}, type::MultiPolygonTrait, geom)
156153
t = PolygonTrait()
157154
return MultiPolygon(map(poly -> GeoInterface.convert(Polygon, t, poly), getgeom(geom)))
158155
end
159156

160-
function Extents.extent(rect::Rect2)
161-
(xmin, ymin), (xmax, ymax) = extrema(rect)
162-
return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax))
163-
end
157+
# without a function barrier you get a lot of allocations from runtime types
158+
function _collect_with_type(::Type{PT}, geom) where {PT <: Point{2}}
159+
return [PT(GeoInterface.x(p), GeoInterface.y(p)) for p in getgeom(geom)]
160+
end
161+
162+
end

src/GeometryBasics.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module GeometryBasics
22

33
using IterTools, LinearAlgebra, StaticArrays
4-
using GeoInterface
54
import Extents
65
using EarCut_jll
76
import Base: *
@@ -27,8 +26,6 @@ include("triangulation.jl")
2726
include("lines.jl")
2827
include("boundingboxes.jl")
2928

30-
include("geointerface.jl")
31-
3229
export AbstractGeometry, GeometryPrimitive
3330
export Mat, Point, Vec
3431
export LineFace, Polytope, Line, NgonFace, convert_simplex
@@ -71,4 +68,8 @@ if Base.VERSION >= v"1.8"
7168
include("precompiles.jl")
7269
end
7370

71+
# Needed for GeometryBasicsGeoInterfaceExt.
72+
# In future this can go away as can use Module dispatch.
73+
function geointerface_geomtype end
74+
7475
end # module

src/primitives/rectangles.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,12 @@ function faces(::Rect3)
582582
(3, 4, 8, 7), (1, 3, 7, 5), (6, 8, 4, 2)
583583
]
584584
end
585+
586+
function Extents.extent(rect::Rect2)
587+
(xmin, ymin), (xmax, ymax) = extrema(rect)
588+
return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax))
589+
end
590+
function Extents.extent(rect::Rect3)
591+
(xmin, ymin, zmin), (xmax, ymax, zmax) = extrema(rect)
592+
return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax), Z=(zmin, zmax))
593+
end

test/geointerface.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,9 @@ end
123123
ext = extent(rect)
124124
@test ext.X == (0.0f0, 1.0f0)
125125
@test ext.Y == (0.0f0, 1.0f0)
126-
end
126+
rect = Rect3f(Vec3f(0), Vec3f(1.0))
127+
ext = extent(rect)
128+
@test ext.X == (0.0f0, 1.0f0)
129+
@test ext.Y == (0.0f0, 1.0f0)
130+
@test ext.Z == (0.0f0, 1.0f0)
131+
end

0 commit comments

Comments
 (0)