From ff0446cc120ca1f8047f3ff2df4ee27c499f7fcf Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sat, 12 Dec 2020 14:51:03 -0800 Subject: [PATCH] Fix division by zero for very close waypoints. Fixes https://github.com/Khopa/dcs_liberation/issues/557 (cherry picked from commit 08ceb57c312467c321245b91b3a6a40c04db5096) --- gen/kneeboard.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gen/kneeboard.py b/gen/kneeboard.py index b7064b97..61f0af9a 100644 --- a/gen/kneeboard.py +++ b/gen/kneeboard.py @@ -26,7 +26,7 @@ import datetime from collections import defaultdict from dataclasses import dataclass from pathlib import Path -from typing import Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import Dict, List, Optional, TYPE_CHECKING, Tuple from PIL import Image, ImageDraw, ImageFont from dcs.mission import Mission @@ -44,6 +44,8 @@ from .runways import RunwayData if TYPE_CHECKING: from game import Game + + class KneeboardPageWriter: """Creates kneeboard images.""" @@ -191,7 +193,15 @@ class FlightPlanBuilder: waypoint.position )) duration = (waypoint.tot - last_time).total_seconds() / 3600 - return f"{int(distance / duration)} kt" + try: + return f"{int(distance / duration)} kt" + except ZeroDivisionError: + # TODO: Improve resolution of unit conversions. + # When waypoints are very close to each other they can end up with + # identical TOTs because our unit conversion functions truncate to + # int. When waypoints have the same TOT the duration will be zero. + # https://github.com/Khopa/dcs_liberation/issues/557 + return "-" def build(self) -> List[List[str]]: return self.rows