From f40b750ccab627d66570086fa2fd3a86c91b90d7 Mon Sep 17 00:00:00 2001 From: jsbyysheng Date: Sun, 7 Aug 2022 13:19:47 +0800 Subject: [PATCH] fix bugs in check a position inside the polygon (#701) * fix bugs in check a position inside the polygon It is possible that the position `(iox, ioy)` to be checked with `iox == min_x`. This will cause a incorrect inside check. * add a boundary condition for gridmap --- Mapping/grid_map_lib/grid_map_lib.py | 6 +++--- tests/test_grid_map_lib.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Mapping/grid_map_lib/grid_map_lib.py b/Mapping/grid_map_lib/grid_map_lib.py index a93ea309..85dd76e7 100644 --- a/Mapping/grid_map_lib/grid_map_lib.py +++ b/Mapping/grid_map_lib/grid_map_lib.py @@ -194,7 +194,7 @@ class GridMap: min_x, max_x = x[i2], x[i1] else: min_x, max_x = x[i1], x[i2] - if not min_x < iox < max_x: + if not min_x <= iox < max_x: continue tmp1 = (y[i2] - y[i1]) / (x[i2] - x[i1]) @@ -226,8 +226,8 @@ class GridMap: def test_polygon_set(): - ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0] - oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0] + ox = [0.0, 4.35, 20.0, 50.0, 100.0, 130.0, 40.0] + oy = [0.0, -4.15, -20.0, 0.0, 30.0, 60.0, 80.0] grid_map = GridMap(600, 290, 0.7, 60.0, 30.5) diff --git a/tests/test_grid_map_lib.py b/tests/test_grid_map_lib.py index ed4303d4..8ae142b0 100644 --- a/tests/test_grid_map_lib.py +++ b/tests/test_grid_map_lib.py @@ -14,8 +14,8 @@ def test_position_set(): def test_polygon_set(): - ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0] - oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0] + ox = [0.0, 4.35, 20.0, 50.0, 100.0, 130.0, 40.0] + oy = [0.0, -4.15, -20.0, 0.0, 30.0, 60.0, 80.0] grid_map = GridMap(600, 290, 0.7, 60.0, 30.5)