Skip to content

Commit

Permalink
perf: ⚡ In ThermalEventInstance.from_polygon, do not perform polygon …
Browse files Browse the repository at this point in the history
…simplification if polygon is short enough
  • Loading branch information
egrelier committed Aug 10, 2023
1 parent eba3b17 commit 44ea599
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions thermal_events/thermal_event_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,12 @@ def from_polygon(
instance = cls(timestamp_ns=timestamp_ns)

# If needed, simplify the polygon
nb_points = len(polygon) - 1
simplifier = VWSimplifier(np.array(polygon, dtype=float))
while len(polygon_to_string(polygon)) > max_polygon_string_length:
polygon = simplifier.from_number(nb_points).astype(int)
nb_points -= 1
if len(polygon_to_string(polygon)) > max_polygon_string_length:
nb_points = len(polygon) - 1
simplifier = VWSimplifier(np.array(polygon, dtype=float))
while len(polygon_to_string(polygon)) > max_polygon_string_length:
polygon = simplifier.from_number(nb_points).astype(int)
nb_points -= 1

polygon = np.array(np.round(polygon), dtype=np.int32)

Expand Down

0 comments on commit 44ea599

Please sign in to comment.