From 2c767dee9fe34ef9a084c31f2a3657a1b31f0870 Mon Sep 17 00:00:00 2001 From: LasNikas Date: Fri, 19 Jul 2024 12:14:36 +0200 Subject: [PATCH] `for` instead of `while` --- src/preprocessing/shapes/triangle_mesh.jl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/preprocessing/shapes/triangle_mesh.jl b/src/preprocessing/shapes/triangle_mesh.jl index 6557e6ea6..60049e676 100644 --- a/src/preprocessing/shapes/triangle_mesh.jl +++ b/src/preprocessing/shapes/triangle_mesh.jl @@ -34,20 +34,29 @@ struct TriangleMesh{NDIMS, ELTYPE} # Since it's only sorted by the first entry, `v1` might be one of the following vertices vertex_id1 = searchsortedfirst(vertices, v1 .- 1e-14) - while vertex_id1 < length(vertices) && !isapprox(vertices[vertex_id1], v1) - vertex_id1 += 1 + @inbounds for vertex_id in eachindex(vertices)[vertex_id1:end] + if isapprox(vertices[vertex_id], v1) + vertex_id1 = vertex_id + break + end end # Since it's only sorted by the first entry, `v2` might be one of the following vertices vertex_id2 = searchsortedfirst(vertices, v2 .- 1e-14) - while vertex_id2 < length(vertices) && !isapprox(vertices[vertex_id2], v2) - vertex_id2 += 1 + @inbounds for vertex_id in eachindex(vertices)[vertex_id2:end] + if isapprox(vertices[vertex_id], v2) + vertex_id2 = vertex_id + break + end end # Since it's only sorted by the first entry, `v3` might be one of the following vertices vertex_id3 = searchsortedfirst(vertices, v3 .- 1e-14) - while vertex_id3 < length(vertices) && !isapprox(vertices[vertex_id3], v3) - vertex_id3 += 1 + @inbounds for vertex_id in eachindex(vertices)[vertex_id3:end] + if isapprox(vertices[vertex_id], v3) + vertex_id3 = vertex_id + break + end end face_vertices_ids[i] = (vertex_id1, vertex_id2, vertex_id3)