Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve merge(meshes) #199

Merged
merged 1 commit into from
Jul 18, 2023
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 @@
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]))

Check warning on line 234 in src/meshes.jl

View check run for this annotation

Codecov / codecov/patch

src/meshes.jl#L231-L234

Added lines #L231 - L234 were not covered by tests
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))

Check warning on line 241 in src/meshes.jl

View check run for this annotation

Codecov / codecov/patch

src/meshes.jl#L236-L241

Added lines #L236 - L241 were not covered by tests
end
return Mesh(ps, fs)
end
end


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

Expand Down