Skip to content

Commit cb78c2a

Browse files
authored
Merge pull request #196 from felixcremer/fc/extent
Add Extents.extent method for Rect2
2 parents 93362a2 + 8c85323 commit cb78c2a

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.4.7"
55

66
[deps]
77
EarCut_jll = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
8+
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
89
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
910
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -14,6 +15,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1415

1516
[compat]
1617
EarCut_jll = "2"
18+
Extents = "0.1"
1719
GeoInterface = "1.0.1"
1820
IterTools = "1.3.0"
1921
StaticArrays = "0.12, 1.0"

src/GeometryBasics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module GeometryBasics
22

33
using StaticArrays, Tables, StructArrays, IterTools, LinearAlgebra
44
using GeoInterface
5+
import Extents
56
using EarCut_jll
67

78
using Base: @propagate_inbounds

src/geointerface.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,8 @@ function GeoInterface.convert(::Type{MultiPolygon}, type::MultiPolygonTrait, geo
149149
t = PolygonTrait()
150150
return MultiPolygon(map(poly -> GeoInterface.convert(Polygon, t, poly), getgeom(geom)))
151151
end
152+
153+
function Extents.extent(rect::Rect2)
154+
(xmin, ymin), (xmax, ymax) = extrema(rect)
155+
return Extents.Extent(X=(xmin, xmax), Y=(ymin, ymax))
156+
end

test/geointerface.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,10 @@ end
115115
@test length(multipolygon_hole_gb[1].interiors) == 0
116116
@test length(multipolygon_hole_gb[2].interiors) == 1
117117
end
118+
119+
@testset "Extent" begin
120+
rect = Rect2f(Vec2f(0), Vec2f(1.0))
121+
ext = extent(rect)
122+
@test ext.X == (0.0f0, 1.0f0)
123+
@test ext.Y == (0.0f0, 1.0f0)
124+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using LinearAlgebra
44
using GeometryBasics: attributes
55
using GeoInterface
66
using GeoJSON
7+
using Extents
78

89
@testset "GeometryBasics" begin
910

0 commit comments

Comments
 (0)