Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,23 @@ function Base.merge(meshes::AbstractVector{<:Mesh})
elseif length(meshes) == 1
return meshes[1]
else
m1 = meshes[1]
ps = copy(coordinates(m1))
fs = copy(faces(m1))
ps = reduce(vcat, coordinates.(meshes))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't this all be written with a single allocated vector for ps and fs, and writing to that in the loop? We should know all lengths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It surely could.
This was just faster than the more elaborate allocate+loop versions I tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that an acceptable answer to merge this ? ;)

fs = reduce(vcat, faces.(meshes))
idx = length(faces(meshes[1]))
offset = length(coordinates(meshes[1]))
for mesh in Iterators.drop(meshes, 1)
append!(fs, map(f -> f .+ length(ps), faces(mesh)))
append!(ps, coordinates(mesh))
N = length(faces(mesh))
for i = idx .+ (1:N)
fs[i] = fs[i] .+ offset
end
idx += N
offset += length(coordinates(mesh))
end
return Mesh(ps, fs)
end
end


"""
pointmeta(mesh::Mesh; meta_data...)

Expand Down