diff --git a/Project.toml b/Project.toml index dbbd5df1..651a69fd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GeometryBasics" uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" authors = ["SimonDanisch "] -version = "0.5.3" +version = "0.5.4" [deps] EarCut_jll = "5ae413db-bbd1-5e63-b57d-d24a61df00f5" diff --git a/src/primitives/rectangles.jl b/src/primitives/rectangles.jl index 0aa73f36..6e7b8b6a 100644 --- a/src/primitives/rectangles.jl +++ b/src/primitives/rectangles.jl @@ -9,6 +9,13 @@ Formally it is the Cartesian product of intervals, which is represented by the struct HyperRectangle{N,T} <: GeometryPrimitive{N,T} origin::Vec{N,T} widths::Vec{N,T} + + function HyperRectangle{N, T}(o::VecTypes, w::VecTypes) where {N, T} + return new{N, T}(convert(Vec{N, T}, o), convert(Vec{N, T}, w)) + end + function HyperRectangle{N, T}(o::VecTypes, w::VecTypes) where {N, T <: Integer} + return new{N, T}(convert(Vec{N, T}, round.(T, o)), convert(Vec{N, T}, round.(T, w))) + end end ## @@ -154,6 +161,12 @@ height(prim::Rect) = prim.widths[2] volume(prim::HyperRectangle) = prod(prim.widths) area(prim::Rect2) = volume(prim) +# function Base.round(::Type{Rect{N, T}}, x::Rect{N}, mode::RoundingMode=RoundNearest) where {N, T} +# mini = round.(T, minimum(x)) +# maxi = round.(T, maximum(x)) +# return Rect{N, T}(mini, maxi .- mini) +# end + """ split(rectangle, axis, value) diff --git a/test/geometrytypes.jl b/test/geometrytypes.jl index f4d73097..29bb9a36 100644 --- a/test/geometrytypes.jl +++ b/test/geometrytypes.jl @@ -182,6 +182,13 @@ end end end + # TODO: consider deprecating this + @testset "Integer rounding" begin + @test Rect2i(0.3, 0.4, 0.6, 0.5) == Rect2i(0,0,1,0) + @test Rect2{UInt32}(0.8, 0.1, 1.3, 1.9) == Rect2i(1,0,1,2) + @test Rect3i(0.3, 0.6, 0.9, 1.2, 1.5, 1.8) == Rect3i(0,1,1,1,2,2) + end + # TODO: These don't really make sense... r = Rect2f() @test origin(r) == Vec(Inf, Inf)