GCC Code Coverage Report


Directory: ./
File: tasks/orehov_n_jarvis_pass_seq/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 0 41 0.0%
Functions: 0 9 0.0%
Branches: 0 44 0.0%

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