Files
make-cad/test/test_chamfer_angle.py
NiJingzhe 8971279494 feat: the geometry engine is C++ on OpenCASCADE, one package, prebuilt wheels
The modeling API (shapes, operators, sketches, products, queries, the reactive graph) is implemented in
C++20 on OpenCASCADE (src/cpp) and ships inside the wheel as simplecadapi._cpp.  The Python layers that stay
Python (runtime, build, artifacts, editor, inspect, exporter, translators, scene) run on it unchanged; the
previous Python test suite passes on the new engine.

Layout: src/cpp and src/simplecadapi side by side, one distribution built by scikit-build-core.
simplecadapi.core, .operators.*, .ql, .std.* and the other legacy modules are real forwarding modules; the
Python adapter layer is simplecadapi/_glue.  OCP is no longer a dependency and nothing imports it.

Release: .github/workflows/release.yml builds wheels for Linux x86_64 and aarch64, macOS arm64 and Windows
x86_64 (Python 3.10-3.13) against one static OCCT, runs the test suite on the Linux wheels and publishes to
GitHub and PyPI; ci.yml caches the static OCCT for the test jobs.

Errors: every message the library writes is English; the tag-validation and semantic-query errors render in
full with possible causes and fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 02:55:35 +08:00

114 lines
3.9 KiB
Python

"""Angled (asymmetric) chamfer tests."""
from __future__ import annotations
import math
import unittest
import simplecadapi as scad
from simplecadapi import ql
def _top_edge_selector():
return ql.edges().where(
ql.and_(
ql.curve_type("LINE"),
ql.prop("geom.center.z", ">", 9.999),
ql.prop("geom.center.y", "<", -4.999),
)
).exactly(1)
class TestAngledChamfer(unittest.TestCase):
def setUp(self):
self.box = scad.make_box_rsolid(width=10.0, height=10.0, depth=10.0)
self.edge_length = 10.0
def _removed(self, solid):
return 1000.0 - solid.get_volume()
def test_symmetric_chamfer_is_unchanged_default(self):
solid = scad.chamfer_rsolid(self.box, _top_edge_selector(), 1.0)
self.assertAlmostEqual(self._removed(solid), 0.5 * 1.0 * 1.0 * 10.0, places=6)
def test_angled_chamfer_removes_tangent_wedge(self):
for angle in (15.0, 30.0, 60.0, 75.0):
with self.subTest(angle=angle):
solid = scad.chamfer_rsolid(
self.box,
_top_edge_selector(),
1.0,
angle=angle,
reference_direction=(0.0, 0.0, 1.0),
)
expected = 0.5 * 1.0 * math.tan(math.radians(angle)) * self.edge_length
self.assertAlmostEqual(self._removed(solid), expected, places=6)
def test_distance_lands_on_reference_face(self):
from simplecadapi._cpp.occt.Bnd import Bnd_Box
from simplecadapi._cpp.occt.BRepBndLib import BRepBndLib
solid = scad.chamfer_rsolid(
self.box,
_top_edge_selector(),
1.0,
angle=30.0,
reference_direction=(0.0, 0.0, 1.0),
)
chamfer_faces = [
face
for face in ql.faces().where(ql.surface_type("PLANE")).resolve(solid)
if abs(face.get_center().z - 10.0) < 2.0
and abs(face.get_center().y + 5.0) < 2.0
and abs(face.get_center().x) < 0.1
]
self.assertEqual(len(chamfer_faces), 1)
box = Bnd_Box()
BRepBndLib.Add_s(chamfer_faces[0].wrapped, box)
xmin, ymin, zmin, xmax, ymax, zmax = box.Get()
self.assertAlmostEqual(ymax + 5.0, 1.0, places=6) # leg on reference face
self.assertAlmostEqual(10.0 - zmin, math.tan(math.radians(30.0)), places=6)
def test_angle_requires_reference_direction(self):
with self.assertRaises(Exception):
scad.chamfer_rsolid(self.box, _top_edge_selector(), 1.0, angle=30.0)
def test_angle_must_be_inside_exclusive_range(self):
for bad in (-5.0, 0.0, 90.0, 120.0):
with self.subTest(bad=bad), self.assertRaises(Exception):
scad.chamfer_rsolid(
self.box,
_top_edge_selector(),
1.0,
angle=bad,
reference_direction=(0.0, 0.0, 1.0),
)
def test_angle_params_recorded_in_graph(self):
from simplecadapi.recording.graph import GraphSession
from simplecadapi.recording.serializer import import_model_json
from simplecadapi.translator.freecad_translator.translator import (
_FreeCADCompiler,
)
with GraphSession() as session:
box = scad.make_box_rsolid(width=10.0, height=10.0, depth=10.0)
scad.chamfer_rsolid(
box,
_top_edge_selector(),
1.0,
angle=30.0,
reference_direction=(0.0, 0.0, 1.0),
)
payload = scad.export_model_json(session)
script = _FreeCADCompiler().translate_model_payload_to_script(
import_model_json(payload)
)
self.assertIn("'distance2'", script)
self.assertIn("'angle'", script)
if __name__ == "__main__":
unittest.main()