| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "redkina_a_graham_approach/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <utility> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "redkina_a_graham_approach/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace redkina_a_graham_approach { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | RedkinaAGrahamApproachSEQ::RedkinaAGrahamApproachSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | GetInput() = in; |
| 14 | GetOutput().clear(); | ||
| 15 | 96 | } | |
| 16 | |||
| 17 | 96 | bool RedkinaAGrahamApproachSEQ::ValidationImpl() { | |
| 18 | 96 | return GetInput().size() >= 3; | |
| 19 | } | ||
| 20 | |||
| 21 | 96 | bool RedkinaAGrahamApproachSEQ::PreProcessingImpl() { | |
| 22 | 96 | return true; | |
| 23 | } | ||
| 24 | |||
| 25 | namespace { | ||
| 26 | |||
| 27 | 240 | constexpr bool ComparePolarAngles(const Point &pivot, const Point &a, const Point &b) noexcept { | |
| 28 | 240 | const int cross = ((a.x - pivot.x) * (b.y - pivot.y)) - ((a.y - pivot.y) * (b.x - pivot.x)); | |
| 29 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 176 times.
|
240 | if (cross == 0) { |
| 30 | const int dx1 = a.x - pivot.x; | ||
| 31 | const int dy1 = a.y - pivot.y; | ||
| 32 | const int dx2 = b.x - pivot.x; | ||
| 33 | const int dy2 = b.y - pivot.y; | ||
| 34 | 64 | return ((dx1 * dx1) + (dy1 * dy1)) < ((dx2 * dx2) + (dy2 * dy2)); | |
| 35 | } | ||
| 36 | 176 | return cross > 0; | |
| 37 | } | ||
| 38 | |||
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | std::vector<Point> GrahamScanSeq(std::vector<Point> points) { |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (points.size() < 3) { |
| 41 | return points; | ||
| 42 | } | ||
| 43 | |||
| 44 | const auto pivot_it = std::ranges::min_element( | ||
| 45 |
5/6✓ Branch 0 taken 208 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 144 times.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
|
224 | points, [](const Point &a, const Point &b) { return a.y < b.y || (a.y == b.y && a.x < b.x); }); |
| 46 | std::swap(points.front(), *pivot_it); | ||
| 47 | 96 | const Point pivot = points.front(); | |
| 48 | |||
| 49 | 96 | std::ranges::sort(points.begin() + 1, points.end(), | |
| 50 |
3/24✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 112 times.
|
240 | [&pivot](const Point &a, const Point &b) { return ComparePolarAngles(pivot, a, b); }); |
| 51 | |||
| 52 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | std::vector<Point> hull; |
| 53 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | hull.reserve(points.size()); |
| 54 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 96 times.
|
416 | for (const auto &p : points) { |
| 55 |
4/4✓ Branch 0 taken 128 times.
✓ Branch 1 taken 224 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 96 times.
|
352 | while (hull.size() >= 2 && CalcCross(hull[hull.size() - 2], hull.back(), p) <= 0) { |
| 56 | hull.pop_back(); | ||
| 57 | } | ||
| 58 | hull.push_back(p); | ||
| 59 | } | ||
| 60 | return hull; | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace | ||
| 64 | |||
| 65 | 96 | bool RedkinaAGrahamApproachSEQ::RunImpl() { | |
| 66 | 96 | auto pts = GetInput(); | |
| 67 |
2/4✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 96 times.
|
192 | auto res = GrahamScanSeq(std::move(pts)); |
| 68 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
96 | if (res.empty() && !GetInput().empty()) { |
| 69 | res.push_back(GetInput().front()); | ||
| 70 | } | ||
| 71 | GetOutput() = std::move(res); | ||
| 72 | 96 | return true; | |
| 73 | } | ||
| 74 | |||
| 75 | 96 | bool RedkinaAGrahamApproachSEQ::PostProcessingImpl() { | |
| 76 | 96 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | } // namespace redkina_a_graham_approach | ||
| 80 |