diff options
author | Howard Trickey <howard.trickey@gmail.com> | 2020-08-20 00:48:28 +0300 |
---|---|---|
committer | Howard Trickey <howard.trickey@gmail.com> | 2020-08-20 00:48:28 +0300 |
commit | fa9a630b29539a9f388bfda7ee3433e2bb37625d (patch) | |
tree | 8dcb56470b97391b0dbb937cf2712bcff76eaebe /source/blender/blenlib | |
parent | f5c7a6d3b6bbd1f67f66994173a2b5ab875b6053 (diff) |
Use std::lower_bound instead of custom binary search.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/mesh_intersect.cc | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index 98eedbd7edb..d0def5c06a2 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -17,6 +17,7 @@ /* The blender::meshintersect API needs GMP. */ #ifdef WITH_GMP +# include <algorithm> # include <fstream> # include <iostream> @@ -2673,19 +2674,13 @@ static int find_first_overlap_index(const TriOverlaps &ov, int t) if (span.size() == 0) { return -1; } - int min = 0; - int max = static_cast<int>(span.size()) - 1; - while (min < max) { - int mid = (min + max) / 2; - if (t <= span[mid].indexA) { - max = mid; - } - else { - min = mid + 1; - } - } - if (span[min].indexA == t) { - return min; + BVHTreeOverlap bo{t, -1}; + const BVHTreeOverlap *p = std::lower_bound( + span.begin(), span.end(), bo, [](const BVHTreeOverlap &o1, const BVHTreeOverlap &o2) { + return o1.indexA < o2.indexA; + }); + if (p != span.end()) { + return p - span.begin(); } return -1; } |