Skip to content

Commit

Permalink
vectorize the compute_bbox function
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jun 17, 2024
1 parent eb090cc commit b9131f8
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/hyperrectangles.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
# abstract HyperRectangle{N, T}

struct HyperRectangle{V <: AbstractVector}
mins::V
maxes::V
end

# Computes a bounding box around a point cloud
function compute_bbox(data::AbstractVector{V}) where {V <: AbstractVector}
T = eltype(V)
n_dim = length(V)
maxes = zeros(MVector{n_dim, T})
mins = zeros(MVector{n_dim, T})
@inbounds for j in 1:n_dim
dim_max = typemin(T)
dim_min = typemax(T)
for k in eachindex(data)
dim_max = max(data[k][j], dim_max)
dim_min = min(data[k][j], dim_min)
end
maxes[j] = dim_max
mins[j] = dim_min
end
return HyperRectangle(SVector(mins), SVector(maxes))
mins = mapreduce(identity, (a, b) -> min.(a, b), data; init=fill(Inf,V))
maxes = mapreduce(identity, (a, b) -> max.(a, b), data; init=fill(-Inf,V))
return HyperRectangle(mins, maxes)
end


Expand Down

0 comments on commit b9131f8

Please sign in to comment.