Skip to content

Commit 2582a8c

Browse files
committed
add round() method and fix ambiguity
1 parent 2d83e6c commit 2582a8c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/primitives/rectangles.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ struct HyperRectangle{N,T} <: GeometryPrimitive{N,T}
1010
origin::Vec{N,T}
1111
widths::Vec{N,T}
1212

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...))
13+
function HyperRectangle{N, T}(o::VecTypes, w::VecTypes) where {N, T}
14+
return new{N, T}(convert(Vec{N, T}, o), convert(Vec{N, T}, w))
1515
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)...))
16+
function HyperRectangle{N, T}(o::VecTypes, w::VecTypes) where {N, T <: Integer}
17+
return new{N, T}(convert(Vec{N, T}, round.(T, o)), convert(Vec{N, T}, round.(T, w)))
1818
end
1919
end
2020

@@ -161,6 +161,12 @@ height(prim::Rect) = prim.widths[2]
161161
volume(prim::HyperRectangle) = prod(prim.widths)
162162
area(prim::Rect2) = volume(prim)
163163

164+
function Base.round(::Type{Rect{N, T}}, x::Rect{N}, mode::RoundingMode=RoundNearest) where {N, T}
165+
mini = round.(T, minimum(x))
166+
maxi = round.(T, maximum(x))
167+
return Rect{N, T}(mini, maxi .- mini)
168+
end
169+
164170
"""
165171
split(rectangle, axis, value)
166172

0 commit comments

Comments
 (0)