Skip to content

Commit

Permalink
Update '_pboxes' function
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Nov 28, 2024
1 parent 257f5fc commit eb480cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
44 changes: 33 additions & 11 deletions src/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,42 @@ _bboxes(boxes) = _pboxes(point for box in boxes for point in extrema(box))

_pboxes(points) = _pboxes(manifold(first(points)), points)

function _pboxes(::Type{𝔼{N}}, points) where {N}
p = first(points)
= lentype(p)
cmin = fill(typemax(ℒ), N)
cmax = fill(typemin(ℒ), N)
@generated function _pboxes(::Type{𝔼{N}}, points) where {N}
minvars = ntuple(i -> Symbol(:cmin, i), N)
maxvars = ntuple(i -> Symbol(:cmax, i), N)

for p in points
c = CoordRefSystems.values(convert(Cartesian, coords(p)))
for i in 1:N
cmin[i] = min(c[i], cmin[i])
cmax[i] = max(c[i], cmax[i])
mininit = ntuple(N) do i
minvar = minvars[i]
:($minvar = typemax(ℒ))
end
maxinit = ntuple(N) do i
maxvar = maxvars[i]
:($maxvar = typemin(ℒ))
end

minupdate = ntuple(N) do i
minvar = minvars[i]
:($minvar = min(c[$i], $minvar))
end
maxupdate = ntuple(N) do i
maxvar = maxvars[i]
:($maxvar = max(c[$i], $maxvar))
end

quote
p = first(points)
= lentype(p)
$(mininit...)
$(maxinit...)

for p in points
c = CoordRefSystems.values(convert(Cartesian, coords(p)))
$(minupdate...)
$(maxupdate...)
end

Box(withcrs(p, ($(minvars...),)), withcrs(p, ($(maxvars...),)))
end
Box(withcrs(p, Tuple(cmin)), withcrs(p, Tuple(cmax)))
end

function _pboxes(::Type{🌐}, points)
Expand Down
16 changes: 8 additions & 8 deletions test/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
@test @allocated(boundingbox(m)) < 4100
@test @allocated(boundingbox(d)) < 4100
else
@test @allocated(boundingbox(m)) < 3200
@test @allocated(boundingbox(d)) < 3200
@test @allocated(boundingbox(m)) < 2700
@test @allocated(boundingbox(d)) < 2700
end

b1 = Box(cart(0, 0), cart(1, 1))
Expand All @@ -70,15 +70,15 @@
d = GeometrySet([b1, b2])
@test boundingbox(m) == Box(cart(-1, -1), cart(1, 1))
@test boundingbox(d) == Box(cart(-1, -1), cart(1, 1))
@test @allocated(boundingbox(m)) < 500
@test @allocated(boundingbox(d)) < 500
@test @allocated(boundingbox(m)) < 50
@test @allocated(boundingbox(d)) < 50

d = PointSet(cart(0, 0), cart(1, 2), cart(2, 1))
@test boundingbox(d) == Box(cart(0, 0), cart(2, 2))
@test @allocated(boundingbox(d)) < 500
@test @allocated(boundingbox(d)) < 50
d = PointSet(cart(1, 2), cart(2, 1))
@test boundingbox(d) == Box(cart(1, 1), cart(2, 2))
@test @allocated(boundingbox(d)) < 500
@test @allocated(boundingbox(d)) < 50

d = cartgrid(10, 10)
@test boundingbox(d) == Box(cart(0, 0), cart(10, 10))
Expand All @@ -93,7 +93,7 @@
d = PointSet(cart(0, 0), cart(1, 2), cart(2, 1))
v = view(d, 1:2)
@test boundingbox(v) == Box(cart(0, 0), cart(1, 2))
@test @allocated(boundingbox(v)) < 500
@test @allocated(boundingbox(v)) < 50

d = cartgrid(10, 10)
v = view(d, 1:2)
Expand All @@ -119,7 +119,7 @@
g = cartgrid(10, 10)
m = convert(SimpleMesh, g)
@test boundingbox(m) == Box(cart(0, 0), cart(10, 10))
@test @allocated(boundingbox(m)) < 500
@test @allocated(boundingbox(m)) < 50

p = ParaboloidSurface(cart(1, 2, 3), T(5), T(4))
@test boundingbox(p) Box(cart(-4, -3, 3), cart(6, 7, 73 / 16))
Expand Down

0 comments on commit eb480cc

Please sign in to comment.