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..e48f853 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); } @@ -139,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)); + } } } }