Skip to content

Commit

Permalink
add substitute method for LinearFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
Stargazer2005 committed Apr 23, 2024
1 parent 8147623 commit d7d257e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 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

0 comments on commit d7d257e

Please sign in to comment.