| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "romanov_m_jarvis_prohod/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "romanov_m_jarvis_prohod/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace romanov_m_jarvis_prohod { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | RomanovMJarvisProhodSEQ::RomanovMJarvisProhodSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetInput() = in; |
| 14 | GetOutput().clear(); | ||
| 15 | 32 | } | |
| 16 | |||
| 17 | 32 | bool RomanovMJarvisProhodSEQ::ValidationImpl() { | |
| 18 | 32 | return GetInput().size() >= 3; | |
| 19 | } | ||
| 20 | |||
| 21 | 32 | bool RomanovMJarvisProhodSEQ::PreProcessingImpl() { | |
| 22 | 32 | return true; | |
| 23 | } | ||
| 24 | |||
| 25 | namespace { | ||
| 26 | |||
| 27 | 32 | int LeftPoint(const std::vector<Point> &points) { | |
| 28 | int idx = 0; | ||
| 29 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 32 times.
|
136 | for (std::size_t i = 1; i < points.size(); ++i) { |
| 30 |
4/6✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 96 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
|
104 | if (points[i].x < points[idx].x || (points[i].x == points[idx].x && points[i].y < points[idx].y)) { |
| 31 | ✗ | idx = static_cast<int>(i); | |
| 32 | } | ||
| 33 | } | ||
| 34 | 32 | return idx; | |
| 35 | } | ||
| 36 | |||
| 37 | 104 | int ChooseNextBoundaryPoint(const std::vector<Point> &points, int p) { | |
| 38 | 104 | const int n = static_cast<int>(points.size()); | |
| 39 | 104 | int q = (p + 1) % n; | |
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 456 times.
✓ Branch 1 taken 104 times.
|
560 | for (int i = 0; i < n; ++i) { |
| 42 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 392 times.
|
456 | const int64_t cross = CrossCalculate(points[p], points[i], points[q]); |
| 43 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 392 times.
|
456 | if (cross > 0) { |
| 44 | q = i; | ||
| 45 |
2/2✓ Branch 0 taken 208 times.
✓ Branch 1 taken 184 times.
|
392 | } else if (cross == 0) { |
| 46 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 192 times.
|
208 | if (SqDistance(points[p], points[i]) > SqDistance(points[p], points[q])) { |
| 47 | q = i; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | 104 | return q; | |
| 52 | } | ||
| 53 | |||
| 54 | } // namespace | ||
| 55 | |||
| 56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | std::vector<Point> RomanovMJarvisProhodSEQ::JarvisMarch(std::vector<Point> points) { |
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | if (points.size() < 3) { |
| 58 | return points; | ||
| 59 | } | ||
| 60 | |||
| 61 | 32 | std::vector<Point> hull; | |
| 62 | 32 | const int start = LeftPoint(points); | |
| 63 | |||
| 64 | int p = start; | ||
| 65 | while (true) { | ||
| 66 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 88 times.
|
104 | hull.push_back(points[p]); |
| 67 | 104 | p = ChooseNextBoundaryPoint(points, p); | |
| 68 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 32 times.
|
104 | if (p == start) { |
| 69 | break; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | return hull; | ||
| 74 | } | ||
| 75 | |||
| 76 | 32 | bool RomanovMJarvisProhodSEQ::RunImpl() { | |
| 77 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | GetOutput() = JarvisMarch(GetInput()); |
| 78 | 32 | return true; | |
| 79 | } | ||
| 80 | |||
| 81 | 32 | bool RomanovMJarvisProhodSEQ::PostProcessingImpl() { | |
| 82 | 32 | return true; | |
| 83 | } | ||
| 84 | |||
| 85 | } // namespace romanov_m_jarvis_prohod | ||
| 86 |