Skip to content

Commit 2d83e6c

Browse files
committed
bring back integer rounding
1 parent c0da282 commit 2d83e6c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/primitives/rectangles.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Formally it is the Cartesian product of intervals, which is represented by the
99
struct HyperRectangle{N,T} <: GeometryPrimitive{N,T}
1010
origin::Vec{N,T}
1111
widths::Vec{N,T}
12+
13+
function HyperRectangle{N, T}(o::VecTypes{N, T1}, w::VecTypes{N, T2}) where {N, T, T1, T2}
14+
return new{N, T}(Vec{N, T}(o...), Vec{N, T}(w...))
15+
end
16+
function HyperRectangle{N, T}(o::VecTypes{N, T1}, w::VecTypes{N, T2}) where {N, T <: Integer, T1, T2}
17+
return new{N, T}(Vec{N, T}(round.(T, o)...), Vec{N, T}(round.(T, w)...))
18+
end
1219
end
1320

1421
##

test/geometrytypes.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ end
182182
end
183183
end
184184

185+
# TODO: consider deprecating this
186+
@testset "Integer rounding" begin
187+
@test Rect2i(0.3, 0.4, 0.6, 0.5) == Rect2i(0,0,1,0)
188+
@test Rect2{UInt32}(0.8, 0.1, 1.3, 1.9) == Rect2i(1,0,1,2)
189+
@test Rect3i(0.3, 0.6, 0.9, 1.2, 1.5, 1.8) == Rect3i(0,1,1,1,2,2)
190+
end
191+
185192
# TODO: These don't really make sense...
186193
r = Rect2f()
187194
@test origin(r) == Vec(Inf, Inf)

0 commit comments

Comments
 (0)