From 1b1aff53f1354d8fa2078b85d8ea3613e95e5751 Mon Sep 17 00:00:00 2001 From: Ilya_Rybalkin Date: Wed, 15 May 2024 17:49:59 +0300 Subject: [PATCH 1/2] remove unused class member --- math/optimal_way/obstacles.h | 22 ---------------------- math/optimal_way/optimal_way.cpp | 2 -- 2 files changed, 24 deletions(-) diff --git a/math/optimal_way/obstacles.h b/math/optimal_way/obstacles.h index 2276d8d..8354c32 100644 --- a/math/optimal_way/obstacles.h +++ b/math/optimal_way/obstacles.h @@ -71,14 +71,8 @@ class CircleObstacle { double GetRadius() const { return radius_; } - std::vector GetTangentLines() { return tangents_; } - std::vector GetTangentPoints() { return tangent_points_; } - void AddTangentLine(const LinearFunction& tangent) { - tangents_.push_back(tangent); - } - void AddTangentPoint(const Point& tangent_point) { tangent_points_.push_back(tangent_point); } @@ -98,9 +92,6 @@ class CircleObstacle { double radius_; - // Касательные - std::vector tangents_; - // Точки касания std::vector tangent_points_; }; @@ -127,18 +118,8 @@ class PolygonObstacle { std::vector GetVertexes() const { return vertexes_; } - std::vector GetTangentLines() { return tangents_; } - std::vector GetTangentPoints() { return tangent_points_; } - void DeleteTangentPoint(std::size_t index) { - tangent_points_.erase(tangent_points_.begin() + index); - } - - void AddTangentLine(const LinearFunction& tangent) { - tangents_.push_back(tangent); - } - void AddTangentPoint(const Point& tangent_point) { tangent_points_.push_back(tangent_point); } @@ -158,9 +139,6 @@ class PolygonObstacle { // Вершины std::vector vertexes_; - // Касательные - std::vector tangents_; - // Точки касания std::vector tangent_points_; }; diff --git a/math/optimal_way/optimal_way.cpp b/math/optimal_way/optimal_way.cpp index 9b7a0e6..f4a3c26 100644 --- a/math/optimal_way/optimal_way.cpp +++ b/math/optimal_way/optimal_way.cpp @@ -43,9 +43,7 @@ void OptimalWayCalculator::AddTangent(const LinearFunction& tangent, std::make_shared(tangent_points.second); tangent_points.second.another_tangent_point = std::make_shared(tangent_points.first); - obstacle1.AddTangentLine(tangent); obstacle1.AddTangentPoint(tangent_points.first); - obstacle2.AddTangentLine(tangent); obstacle2.AddTangentPoint(tangent_points.second); } From 4572b96a0f3c41436512ab6224e83c39ae2ea4dd Mon Sep 17 00:00:00 2001 From: Ilya_Rybalkin Date: Wed, 15 May 2024 17:50:10 +0300 Subject: [PATCH 2/2] fix connections between hills in graph --- math/optimal_way/optimal_way.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/math/optimal_way/optimal_way.cpp b/math/optimal_way/optimal_way.cpp index f4a3c26..e48f853 100644 --- a/math/optimal_way/optimal_way.cpp +++ b/math/optimal_way/optimal_way.cpp @@ -137,13 +137,13 @@ void OptimalWayCalculator::AddGraphTangentPoints() { DistanceBetweenPoints( graph_.nodes[graph_.nodes.size() - vertexes.size()]->point, new_node->point)); - - for (std::size_t j = 0; j < graph_.nodes.size(); ++j) { - if ((graph_.nodes[j]->point.another_tangent_point) && - (new_node->point == *graph_.nodes[j]->point.another_tangent_point)) - graph_.AddEdge( - graph_.nodes[j]->number, new_node->number, - DistanceBetweenPoints(graph_.nodes[j]->point, new_node->point)); + for (auto& tangent_point : poly.GetTangentPoints()) { + if (tangent_point != new_node->point) continue; + for (auto& node : graph_.nodes) { + if (*tangent_point.another_tangent_point != node->point) continue; + graph_.AddEdge(node->number, new_node->number, + DistanceBetweenPoints(node->point, new_node->point)); + } } } }