Skip to content

Commit

Permalink
Merge pull request #55 from UmbrellaLeaf5/fix_codestyle
Browse files Browse the repository at this point in the history
Fix codestyle
  • Loading branch information
UmbrellaLeaf5 authored Apr 23, 2024
2 parents 0dcd557 + d7d257e commit a7cae97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
10 changes: 2 additions & 8 deletions math/optimal_way/helpers_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,8 @@ bool AreThereIntersections(const PolygonObstacle& poly_obst, const Point& pnt1,
std::vector<Point> vertexes = poly_obst.GetVertexes();
for (std::size_t i = 0; i < vertexes.size() - 1; ++i) {
LinearFunction v_line(vertexes[i], vertexes[i + 1]);
if (((line.a_coef * vertexes[i].x + line.b_coef * vertexes[i].y +
line.c_coef) *
(line.a_coef * vertexes[i + 1].x +
line.b_coef * vertexes[i + 1].y + line.c_coef) <
0) &&
((v_line.a_coef * pnt1.x + v_line.b_coef * pnt1.y + v_line.c_coef) *
(v_line.a_coef * pnt2.x + v_line.b_coef * pnt2.y + v_line.c_coef) <
0))
if ((line.Substitute(vertexes[i]) * line.Substitute(vertexes[i + 1]) < 0) &&
(v_line.Substitute(pnt1) * v_line.Substitute(pnt2) < 0))
return true;
}
return false;
Expand Down
4 changes: 4 additions & 0 deletions math/optimal_way/obstacles.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct LinearFunction {

double a_coef, b_coef, c_coef;

double Substitute(const lib::Point& p) {
return a_coef * p.x + b_coef * p.y + c_coef;
}

bool operator==(const LinearFunction& other) {
return (std::abs(a_coef - other.a_coef) < precision &&
std::abs(b_coef - other.b_coef) < precision &&
Expand Down
28 changes: 13 additions & 15 deletions math/optimal_way/path_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ void DijkstrasAlgorithm::Calculate_Min_Path() {
std::shared_ptr<PathWayNode> min_len_key;
for (auto& elem : graphs_vertex_)
if ((elem.second == min_length_) &&
(!(*path_nodes_[elem.first]).is_visited))
(!path_nodes_[elem.first]->is_visited))
min_len_key = path_nodes_[elem.first];

for (std::size_t i = 0; i < (*min_len_key).edges.size(); ++i)
if ((graphs_vertex_.find((*(*min_len_key).edges[i]).number) ==
for (std::size_t i = 0; i < min_len_key->edges.size(); ++i)
if ((graphs_vertex_.find(min_len_key->edges[i]->number) ==
graphs_vertex_.end()) ||
(graphs_vertex_[(*(*min_len_key).edges[i]).number] >
graphs_vertex_[(*min_len_key).number] +
(*min_len_key).edges_lens[i]))
graphs_vertex_[(*(*min_len_key).edges[i]).number] =
graphs_vertex_[(*min_len_key).number] +
(*min_len_key).edges_lens[i];
(graphs_vertex_[min_len_key->edges[i]->number] >
graphs_vertex_[min_len_key->number] + min_len_key->edges_lens[i]))
graphs_vertex_[min_len_key->edges[i]->number] =
graphs_vertex_[min_len_key->number] + min_len_key->edges_lens[i];
else
continue;
(*min_len_key).is_visited = true;
min_len_key->is_visited = true;

min_length_ = inf;
for (auto& elem : graphs_vertex_)
Expand All @@ -36,11 +34,11 @@ void DijkstrasAlgorithm::Calculate_Min_Path() {
std::size_t end = second_point_;
min_path_.push_back(end);
while (end != first_point_) {
for (std::size_t i = 0; i < (*path_nodes_[end]).edges.size(); ++i)
if (graphs_vertex_[(*path_nodes_[end]).number] ==
graphs_vertex_[(*(*path_nodes_[end]).edges[i]).number] +
(*path_nodes_[end]).edges_lens[i]) {
end = (*(*path_nodes_[end]).edges[i]).number;
for (std::size_t i = 0; i < path_nodes_[end]->edges.size(); ++i)
if (graphs_vertex_[path_nodes_[end]->number] ==
graphs_vertex_[path_nodes_[end]->edges[i]->number] +
path_nodes_[end]->edges_lens[i]) {
end = path_nodes_[end]->edges[i]->number;
min_path_.push_back(end);
break;
}
Expand Down

0 comments on commit a7cae97

Please sign in to comment.