diff --git a/src/hyperrectangles.jl b/src/hyperrectangles.jl index 198f62c..81a88c6 100644 --- a/src/hyperrectangles.jl +++ b/src/hyperrectangles.jl @@ -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