Skip to content

Commit 1802ef0

Browse files
committed
make Rect widths strictly positive
1 parent 1c3c42b commit 1802ef0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/primitives/rectangles.jl

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ 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}(origin::VecTypes, widths::VecTypes) where {N, T}
14+
return new{N, T}(Vec{N, T}(min.(origin, origin .+ widths)), Vec{N, T}(abs.(widths)))
15+
end
1216
end
1317

1418
##
@@ -288,12 +292,7 @@ end
288292
# return vmin, vmax
289293
# end
290294

291-
function positive_widths(rect::Rect{N,T}) where {N,T}
292-
mini, maxi = minimum(rect), maximum(rect)
293-
realmin = min.(mini, maxi)
294-
realmax = max.(mini, maxi)
295-
return Rect{N,T}(realmin, realmax .- realmin)
296-
end
295+
positive_widths(rect::Rect{N,T}) where {N,T} = rect
297296

298297
###
299298
# set operations

test/geometrytypes.jl

+5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ end
190190
@test constructor(m) Rect3f(-1, -1, -1, 2, 2, 2)
191191
end
192192
end
193+
194+
r = Rect2f(10, 10, -5, -5)
195+
@test origin(r) == Point2f(5)
196+
@test widths(r) == Vec2f(5)
197+
@test maximum(r) == Point2f(10)
193198
end
194199

195200
r = Rect2f()

0 commit comments

Comments
 (0)