Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bring back integer rounding
  • Loading branch information
ffreyer committed Feb 19, 2025
commit 2d83e6c06a7bdea48a1227c42f6047d427757cf0
7 changes: 7 additions & 0 deletions src/primitives/rectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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{N, T1}, w::VecTypes{N, T2}) where {N, T, T1, T2}
return new{N, T}(Vec{N, T}(o...), Vec{N, T}(w...))
end
function HyperRectangle{N, T}(o::VecTypes{N, T1}, w::VecTypes{N, T2}) where {N, T <: Integer, T1, T2}
return new{N, T}(Vec{N, T}(round.(T, o)...), Vec{N, T}(round.(T, w)...))
end
end

##
Expand Down
7 changes: 7 additions & 0 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading