Skip to content

Commit

Permalink
Merge pull request #196 from felixcremer/fc/extent
Browse files Browse the repository at this point in the history
Add Extents.extent method for Rect2
  • Loading branch information
SimonDanisch authored Jul 18, 2023
2 parents 93362a2 + 8c85323 commit cb78c2a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.4.7"

[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"
Expand All @@ -14,6 +15,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
EarCut_jll = "2"
Extents = "0.1"
GeoInterface = "1.0.1"
IterTools = "1.3.0"
StaticArrays = "0.12, 1.0"
Expand Down
1 change: 1 addition & 0 deletions src/GeometryBasics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module GeometryBasics

using StaticArrays, Tables, StructArrays, IterTools, LinearAlgebra
using GeoInterface
import Extents
using EarCut_jll

using Base: @propagate_inbounds
Expand Down
5 changes: 5 additions & 0 deletions src/geointerface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@ function GeoInterface.convert(::Type{MultiPolygon}, type::MultiPolygonTrait, geo
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
7 changes: 7 additions & 0 deletions test/geointerface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ end
@test length(multipolygon_hole_gb[1].interiors) == 0
@test length(multipolygon_hole_gb[2].interiors) == 1
end

@testset "Extent" begin
rect = Rect2f(Vec2f(0), Vec2f(1.0))
ext = extent(rect)
@test ext.X == (0.0f0, 1.0f0)
@test ext.Y == (0.0f0, 1.0f0)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using LinearAlgebra
using GeometryBasics: attributes
using GeoInterface
using GeoJSON
using Extents

@testset "GeometryBasics" begin

Expand Down

0 comments on commit cb78c2a

Please sign in to comment.