Skip to content

Commit 656d55a

Browse files
authored
collision fix (#192)
* collision fix * lowered to 250 for actual theoretical guarantee
1 parent 4900039 commit 656d55a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

pufferlib/ocean/drive/drive.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,12 @@ def calculate_area(p1, p2, p3):
374374
# Calculate the area of the triangle using the determinant method
375375
return 0.5 * abs((p1["x"] - p3["x"]) * (p2["y"] - p1["y"]) - (p1["x"] - p2["x"]) * (p3["y"] - p1["y"]))
376376

377+
def dist(a,b):
378+
dx = a['x'] - b['x']
379+
dy = a['y'] - b['y']
380+
return dx*dx + dy*dy
377381

378-
def simplify_polyline(geometry, polyline_reduction_threshold):
382+
def simplify_polyline(geometry, polyline_reduction_threshold, max_segment_length):
379383
"""Simplify the given polyline using a method inspired by Visvalingham-Whyatt, optimized for Python."""
380384
num_points = len(geometry)
381385
if num_points < 3:
@@ -404,8 +408,7 @@ def simplify_polyline(geometry, polyline_reduction_threshold):
404408
point2 = geometry[k_1]
405409
point3 = geometry[k_2]
406410
area = calculate_area(point1, point2, point3)
407-
408-
if area < polyline_reduction_threshold:
411+
if area < polyline_reduction_threshold and dist(point1,point3) <= max_segment_length:
409412
skip[k_1] = True
410413
skip_changed = True
411414
k = k_2
@@ -515,7 +518,7 @@ def save_map_binary(map_data, output_file, unique_map_id):
515518
road_type = 15
516519
# breakpoint()
517520
if len(geometry) > 10 and road_type <= 16:
518-
geometry = simplify_polyline(geometry, 0.1)
521+
geometry = simplify_polyline(geometry, 0.1, 250)
519522
size = len(geometry)
520523
# breakpoint()
521524
if road_type >= 0 and road_type <= 3:

0 commit comments

Comments
 (0)