Skip to content

Commit a9e81ad

Browse files
committed
constuct Rectangles from Intervals
1 parent 86fc11c commit a9e81ad

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1414

1515
[weakdeps]
1616
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
17+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
1718

1819
[extensions]
1920
GeometryBasicsGeoInterfaceExt = "GeoInterface"
21+
IntervalSetsExt = "IntervalSets"
2022

2123
[compat]
2224
Aqua = "0.8"
2325
EarCut_jll = "2"
2426
Extents = "0.1"
2527
GeoInterface = "1.0.1"
2628
GeoJSON = "0.7, 0.8"
29+
IntervalSets = "0.7"
2730
IterTools = "1.3.0"
2831
LinearAlgebra = "<0.0.1,1"
2932
OffsetArrays = "1"
@@ -35,11 +38,12 @@ julia = "1.10"
3538

3639
[extras]
3740
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
38-
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
3941
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
42+
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
43+
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
4044
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
4145
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4246
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4347

4448
[targets]
45-
test = ["Aqua", "GeoInterface", "GeoJSON", "OffsetArrays", "Random", "Test"]
49+
test = ["Aqua", "GeoInterface", "GeoJSON", "IntervalSets", "OffsetArrays", "Random", "Test"]

ext/IntervalSetsExt.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module IntervalSetsExt
2+
3+
using IntervalSets
4+
using GeometryBasics
5+
6+
GeometryBasics.HyperRectangle(ints::Vararg{Interval, N}) where {N} = HyperRectangle{N}(ints...)
7+
GeometryBasics.HyperRectangle{N}(ints::Vararg{Interval, N}) where {N} = HyperRectangle{N}(
8+
Vec(leftendpoint.(ints)),
9+
Vec(rightendpoint.(ints) .- leftendpoint.(ints))
10+
)
11+
GeometryBasics.HyperRectangle{N,T}(ints::Vararg{Interval, N}) where {N,T} = HyperRectangle{N,T}(
12+
Vec(leftendpoint.(ints)),
13+
Vec(rightendpoint.(ints) .- leftendpoint.(ints))
14+
)
15+
16+
end

test/geometrytypes.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Test, GeometryBasics
2+
using IntervalSets: (..)
23

34
@testset "Cylinder" begin
45
@testset "constructors" begin
@@ -180,6 +181,20 @@ end
180181
@test constructor(m) Rect3f(-1, -1, -1, 2, 2, 2)
181182
end
182183
end
184+
185+
@testset "From intervals" begin
186+
# 1D interval
187+
@test HyperRectangle(1..3) == Rect{1, Float64}(Point(1.0), Vec(2.0))
188+
# 2D intervals
189+
@test HyperRectangle(0..2, -1..1) == Rect{2, Float64}(Point(0.0, -1.0), Vec(2.0, 2.0))
190+
# different interval eltypes
191+
@test HyperRectangle(0.0..2.0, -1..1) == Rect{2, Float64}(Point(0.0, -1.0), Vec(2.0, 2.0))
192+
# N-typed constructor
193+
@test HyperRectangle{2}(0..2, -1..1) == HyperRectangle(0..2, -1..1)
194+
# Rect constructor:
195+
@test Rect(1..3, 4..5) == Rect{2, Float64}(Point(1.0, 4.0), Vec(2.0, 1.0))
196+
@test Rect{2, Float64}(1..3, 4..5) == Rect{2, Float64}(Point(1.0, 4.0), Vec(2.0, 1.0))
197+
end
183198
end
184199

185200
# TODO: consider deprecating this

0 commit comments

Comments
 (0)