src/geo2d/min_dis_ps/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../dis/pp_p/lib.hpp" | ||
| 4 | |||
| 5 | namespace tifa_libs { | ||
| 6 | |||
| 7 | //! the distance is |.|^2 if FP is not floating point | ||
| 8 | // @return indexes of the closest points | ||
| 9 | template <class FP> | ||
| 10 | 366431 | CEXP pttu min_dis_Ps(vec<point<FP>> CR vp) NE { | |
| 11 | 366431 | cu32 n = (u32)vp.size(); | |
| 12 | using T = std::pair<point<FP>, u32>; | ||
| 13 | 34677953 | auto dis1 = [](auto p1, auto p2) NE { | |
| 14 | if CEXP (std::same_as<decltype(p1), point<FP>>) { | ||
| 15 | 793420 | if CEXP (std::floating_point<FP>) return dist_PP(p1, p2); | |
| 16 | 5111093 | else return distp_PP(p1, p2); | |
| 17 | } else { | ||
| 18 | 2904503 | if CEXP (std::floating_point<FP>) return abs(p1 - p2); | |
| 19 | 25868937 | else return (p1 - p2) * (p1 - p2); | |
| 20 | } | ||
| 21 | }; | ||
| 22 | 366431 | vec<T> vpi; | |
| 23 | 366431 | vpi.reserve(n); | |
| 24 |
4/4std::pair<unsigned int, unsigned int> tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&):
✓ Branch 2 taken 1356331 times.
✓ Branch 3 taken 32 times.
std::pair<unsigned int, unsigned int> tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&):
✓ Branch 2 taken 13997433 times.
✓ Branch 3 taken 366399 times.
|
15720195 | flt_ (u32, i, 0, n) vpi.emplace_back(vp[i], i); |
| 25 | 366431 | sort(vpi); | |
| 26 | 366431 | FP d = std::numeric_limits<FP>::max(); | |
| 27 | 366431 | u32 a = -1_u32, b = -1_u32; | |
| 28 | 12175457 | auto upd = [&](T CR x, T CR y) NE { | |
| 29 |
4/4tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#1}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 2 taken 225 times.
✓ Branch 3 taken 793195 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#1}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 2 taken 997257 times.
✓ Branch 3 taken 4113836 times.
|
5904513 | if (FP _ = dis1(x.first, y.first); is_lt(_, d)) d = _, a = x.second, b = y.second; |
| 30 | }; | ||
| 31 | 43611595 | std::multiset<T, decltype([](T CR l, T CR r) NE { return is_lt(l.first.y, r.first.y); })> st; | |
| 32 | 366431 | std::vector<TPN decltype(st)::const_iterator> qt(n); | |
| 33 |
4/4tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 0 taken 1356331 times.
✓ Branch 1 taken 32 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 0 taken 13997433 times.
✓ Branch 1 taken 366399 times.
|
15720195 | for (u32 i = 0, r = 0; i < n; ++i) { |
| 34 | 15353764 | auto& p = vpi[i]; | |
| 35 |
12/12tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 2 taken 2177308 times.
✓ Branch 3 taken 454778 times.
✓ Branch 7 taken 1275755 times.
✓ Branch 8 taken 901553 times.
✓ Branch 9 taken 1275755 times.
✓ Branch 10 taken 1356331 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 2 taken 19004071 times.
✓ Branch 3 taken 8397125 times.
✓ Branch 7 taken 13403763 times.
✓ Branch 8 taken 5600308 times.
✓ Branch 9 taken 13403763 times.
✓ Branch 10 taken 13997433 times.
|
30033282 | while (r < i && !is_lt(dis1(vpi[r].first.x, p.first.x), d)) st.erase(qt[r++]); |
| 36 | 15353764 | auto it2 = st.upper_bound(p), it = it2; | |
| 37 |
4/4tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 2 taken 789768 times.
✓ Branch 3 taken 566563 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 2 taken 4591060 times.
✓ Branch 3 taken 9406373 times.
|
15353764 | if (it != begin(st)) |
| 38 |
12/12tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 5 taken 523178 times.
✓ Branch 6 taken 270122 times.
✓ Branch 10 taken 3532 times.
✓ Branch 11 taken 519646 times.
✓ Branch 12 taken 3532 times.
✓ Branch 13 taken 789768 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 5 taken 3056778 times.
✓ Branch 6 taken 1687729 times.
✓ Branch 10 taken 153447 times.
✓ Branch 11 taken 2903331 times.
✓ Branch 12 taken 153447 times.
✓ Branch 13 taken 4591060 times.
|
5537807 | for (auto _ = std::prev(it); upd(*_, p), (_ != begin(st) && is_lt(dis1(p.first.y, _->first.y), d)); --_); |
| 39 |
12/12tifa_libs::min_dis_Ps<double>(std::vector<tifa_libs::point<double>, std::allocator<tifa_libs::point<double> > > const&)::{lambda(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<double>, unsigned int> const&, std::pair<tifa_libs::point<double>, unsigned int> const&) const:
✓ Branch 5 taken 204017 times.
✓ Branch 6 taken 1152434 times.
✓ Branch 10 taken 120 times.
✓ Branch 11 taken 203897 times.
✓ Branch 12 taken 120 times.
✓ Branch 13 taken 1356331 times.
tifa_libs::min_dis_Ps<long>(std::vector<tifa_libs::point<long>, std::allocator<tifa_libs::point<long> > > const&)::{lambda(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&)#2}::operator()(std::pair<tifa_libs::point<long>, unsigned int> const&, std::pair<tifa_libs::point<long>, unsigned int> const&) const:
✓ Branch 5 taken 3808088 times.
✓ Branch 6 taken 10555931 times.
✓ Branch 10 taken 366586 times.
✓ Branch 11 taken 3441502 times.
✓ Branch 12 taken 366586 times.
✓ Branch 13 taken 13997433 times.
|
15720470 | for (; it != end(st) && is_lt(dis1(it->first.y, p.first.y), d); upd(*it++, p)); |
| 40 | 15353764 | qt[i] = st.emplace_hint(it2, p); | |
| 41 | } | ||
| 42 | 366431 | return {a, b}; | |
| 43 | 366431 | } | |
| 44 | |||
| 45 | } // namespace tifa_libs | ||
| 46 |