From dac95fd3b6ac8a1455a9a0cb9d930fd38613a4d3 Mon Sep 17 00:00:00 2001 From: Bubu-Droid Date: Thu, 22 May 2025 13:04:15 +0530 Subject: [PATCH 1/5] Change dir to degrees --- py-scripts/export-ggb-clean-asy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py-scripts/export-ggb-clean-asy.py b/py-scripts/export-ggb-clean-asy.py index d48bc5c3..20d0eca2 100755 --- a/py-scripts/export-ggb-clean-asy.py +++ b/py-scripts/export-ggb-clean-asy.py @@ -6,6 +6,7 @@ import string import sys import traceback +import math ALLOWED_CHARS = string.ascii_letters + string.digits + "_" @@ -133,8 +134,9 @@ def replace_numbers(s): # determine the direction dx = 100 * (label_loc[0] - coords[0]) dy = 100 * (label_loc[1] - coords[1]) + vdir = round(math.degrees(math.atan2(dy, dx))) figures_output_code += ( - r'dot("%s", %s, dir((%.3f, %.3f)));' % (label, point_coords, dx, dy) + r'dot("%s", %s, dir(%s));' % (label, point_coords, vdir) + "\n" ) label_to_coords[label] = point_coords From ebeb7fa503aa4a904a8334442531ff7dabfa2d51 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 22 May 2025 13:29:15 -0400 Subject: [PATCH 2/5] ruff format --- py-scripts/export-ggb-clean-asy.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/py-scripts/export-ggb-clean-asy.py b/py-scripts/export-ggb-clean-asy.py index 20d0eca2..40603e20 100755 --- a/py-scripts/export-ggb-clean-asy.py +++ b/py-scripts/export-ggb-clean-asy.py @@ -136,8 +136,7 @@ def replace_numbers(s): dy = 100 * (label_loc[1] - coords[1]) vdir = round(math.degrees(math.atan2(dy, dx))) figures_output_code += ( - r'dot("%s", %s, dir(%s));' % (label, point_coords, vdir) - + "\n" + r'dot("%s", %s, dir(%s));' % (label, point_coords, vdir) + "\n" ) label_to_coords[label] = point_coords From ae8e4fd1edd07dc04a35bf7bcc34d6191f652aa3 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 22 May 2025 13:30:28 -0400 Subject: [PATCH 3/5] ruff sort import --- py-scripts/export-ggb-clean-asy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py-scripts/export-ggb-clean-asy.py b/py-scripts/export-ggb-clean-asy.py index 40603e20..343066ed 100755 --- a/py-scripts/export-ggb-clean-asy.py +++ b/py-scripts/export-ggb-clean-asy.py @@ -2,11 +2,11 @@ import argparse import io +import math import re import string import sys import traceback -import math ALLOWED_CHARS = string.ascii_letters + string.digits + "_" From a5d45ea52365bb069b366f31c254669e611e0063 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 22 May 2025 13:30:31 -0400 Subject: [PATCH 4/5] use f-string --- py-scripts/export-ggb-clean-asy.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/py-scripts/export-ggb-clean-asy.py b/py-scripts/export-ggb-clean-asy.py index 343066ed..6900bd7e 100755 --- a/py-scripts/export-ggb-clean-asy.py +++ b/py-scripts/export-ggb-clean-asy.py @@ -127,17 +127,13 @@ def replace_numbers(s): coords = eval(point_coords) if coords is None: - figures_output_code += ( - r'dot("%s", %s, dir(45));' % (label, point_coords) + "\n" - ) + figures_output_code += f'dot("{label}", {point_coords}, dir(45));\n' else: # determine the direction dx = 100 * (label_loc[0] - coords[0]) dy = 100 * (label_loc[1] - coords[1]) vdir = round(math.degrees(math.atan2(dy, dx))) - figures_output_code += ( - r'dot("%s", %s, dir(%s));' % (label, point_coords, vdir) + "\n" - ) + figures_output_code += f'dot("{label}", {point_coords}, dir({vdir}));\n' label_to_coords[label] = point_coords # now clean up the code if possible by replacing explicit coordinates where we can From 78e9a75f6570c95cfdc0ce6978d8aecb3d2b2bfb Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 22 May 2025 13:33:14 -0400 Subject: [PATCH 5/5] output angles between 0 and 360 --- py-scripts/export-ggb-clean-asy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py-scripts/export-ggb-clean-asy.py b/py-scripts/export-ggb-clean-asy.py index 6900bd7e..3f502c08 100755 --- a/py-scripts/export-ggb-clean-asy.py +++ b/py-scripts/export-ggb-clean-asy.py @@ -133,6 +133,8 @@ def replace_numbers(s): dx = 100 * (label_loc[0] - coords[0]) dy = 100 * (label_loc[1] - coords[1]) vdir = round(math.degrees(math.atan2(dy, dx))) + if vdir < 0: + vdir += 360 figures_output_code += f'dot("{label}", {point_coords}, dir({vdir}));\n' label_to_coords[label] = point_coords