"""Compares model.LimbBend with the Java LimbBend, point for point. .venv/bin/python check_port.py ../../core/build/classes/java/main # after ./gradlew :core:compileJava Runs CheckPort.java against the compiled core classes and fails if any result differs by 1e-3 or more. """ import subprocess import sys import numpy as np from model import LimbBend CASES = [(-2, 10, 0.5, 0, 0), (-2, 10, 1.75, 3.5, 0), (0, 12, 1.2, 2.79, 0), (0, 12, 0.7, 3.14159, 1), (0, 12, -0.9, 1.0, 1)] POINTS = np.array([[0, 0, 0], [1.5, 3, -2.25], [-2.25, 10.25, 2.25], [2, -2.25, 1], [0.5, 12.25, -1]]) classes = sys.argv[1] java = subprocess.run(["java", "-cp", classes, "CheckPort.java"], capture_output=True, text=True, check=True).stdout expected = np.array([[float(v) for v in line.split()] for line in java.strip().splitlines()]) got = [] for start, end, angle, axis, anchored in CASES: b = LimbBend(start, end, angle, axis, anchored_at_end=bool(anchored)) bent = b.bend_points(POINTS) got += [[*bent[i], b.angle_at(POINTS[i, 1])] for i in range(len(POINTS))] err = np.abs(np.array(got) - expected).max() print(f"max difference from Java: {err:.2e}") sys.exit(0 if err < 1e-3 else 1)