GCC Code Coverage Report


Directory: ./
File: tasks/orehov_n_jarvis_pass/seq/src/ops_seq.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 37 41 90.2%
Functions: 7 9 77.8%
Branches: 27 44 61.4%

Line Branch Exec Source
1 #include "orehov_n_jarvis_pass/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <set>
5 #include <vector>
6
7 #include "orehov_n_jarvis_pass/common/include/common.hpp"
8
9 namespace orehov_n_jarvis_pass {
10
11
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 OrehovNJarvisPassSEQ::OrehovNJarvisPassSEQ(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
14 24 GetOutput() = std::vector<Point>();
15 24 }
16
17 24 bool OrehovNJarvisPassSEQ::ValidationImpl() {
18 24 return (!GetInput().empty());
19 }
20
21 24 bool OrehovNJarvisPassSEQ::PreProcessingImpl() {
22 24 std::set<Point> tmp(GetInput().begin(), GetInput().end());
23
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 input_.assign(tmp.begin(), tmp.end());
24 24 return true;
25 }
26
27
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
24 bool OrehovNJarvisPassSEQ::RunImpl() {
28
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
24 if (input_.size() == 1 || input_.size() == 2) {
29 16 res_ = input_;
30 16 return true;
31 }
32
33 8 Point current = FindFirstElem();
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 res_.push_back(current);
35
36 while (true) {
37 40 Point next = FindNext(current);
38 if (next == res_[0]) {
39 break;
40 }
41
42
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 24 times.
32 current = next;
43 res_.push_back(next);
44 32 }
45
46 8 return true;
47 }
48
49
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 24 times.
40 Point OrehovNJarvisPassSEQ::FindNext(Point current) const {
50 40 Point next = current == input_[0] ? input_[1] : input_[0];
51
4/4
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 280 times.
✓ Branch 3 taken 40 times.
320 for (auto p : input_) {
52 80 if (current == p || next == p) {
53 80 continue;
54 }
55 double orient = CheckLeft(current, next, p);
56 200 if (orient > 0) {
57 next = p;
58 }
59
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 8 times.
200 if (orient == 0) {
60
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (Distance(current, next) < Distance(current, p)) {
61 next = p;
62 }
63 }
64 }
65 40 return next;
66 }
67
68 double OrehovNJarvisPassSEQ::CheckLeft(Point a, Point b, Point c) {
69
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 128 times.
200 return ((b.x - a.x) * (c.y - a.y)) - ((b.y - a.y) * (c.x - a.x));
70 }
71
72 Point OrehovNJarvisPassSEQ::FindFirstElem() const {
73 Point current = input_[0];
74
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 8 times.
64 for (auto f : input_) {
75
2/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 56 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 56 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
56 if (f.x < current.x || (f.y < current.y && f.x == current.x)) {
76 current = f;
77 }
78 }
79 return current;
80 }
81
82 16 double OrehovNJarvisPassSEQ::Distance(Point a, Point b) {
83 16 return std::sqrt(pow(a.y - b.y, 2) + pow(a.x - b.x, 2));
84 }
85
86 24 bool OrehovNJarvisPassSEQ::PostProcessingImpl() {
87 24 GetOutput() = res_;
88 24 return true;
89 }
90
91 } // namespace orehov_n_jarvis_pass
92