from __future__ import annotations import sys import tempfile import unittest from pathlib import Path from build123d import import_step ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "backend" / "engine")) import cdsl_engine # noqa: E402 class SphereAddTests(unittest.TestCase): def test_cdsl_only_rebuilds_a_sphere_at_the_requested_center(self) -> None: cdsl = { "schema": "cad.cdsl.llm.v1", "schema_version": "1.0.0", "kind": "part", "part_id": "sphere_test", "meta": {"unit": "mm"}, "geometry": {"sketches": []}, "features": [{ "id": "sphere", "atomic_id": "sphere_add", "depends_on": [], "name": "Test sphere", "params": {"radius_mm": 2.5, "center_mm": [3.0, -4.0, 5.0]}, }], } with tempfile.TemporaryDirectory() as directory: out_step = Path(directory) / "sphere.step" result = cdsl_engine.run_rebuild(cdsl, out_step) shape = import_step(str(out_step)) bbox = shape.bounding_box() self.assertEqual(result["engine"], "cdsl_only") self.assertAlmostEqual(shape.volume, 4 / 3 * 3.141592653589793 * 2.5 ** 3, places=5) self.assertEqual((bbox.min.X, bbox.min.Y, bbox.min.Z), (0.5, -6.5, 2.5)) self.assertEqual((bbox.max.X, bbox.max.Y, bbox.max.Z), (5.5, -1.5, 7.5)) if __name__ == "__main__": unittest.main()