Files
2026-09-24 10:40:57 +08:00

41 lines
2.4 KiB
Python

"""Independent geometry evidence must distinguish smooth roots from sharp valleys."""
import math, unittest
from unittest.mock import patch
from build123d import Plane, Vector, Wire, Pos, Rot, section, Cylinder
from capabilities.impl import bevel_gear
from engine.root_sections import root_band_measurements
from engine.radial_sections import measure_radial_sections
class RootSectionTests(unittest.TestCase):
def test_failed_curvature_does_not_hide_other_measurements(self):
with patch('engine.radial_sections.root_band_measurements',side_effect=ValueError('singular derivative')):
row=measure_radial_sections(Cylinder(6,4),[0,0,0],[0,0,1],[0])['sections'][0]
self.assertIn('unavailable',row['root_band'])
self.assertEqual(row['outer_lobe_count'],0)
self.assertAlmostEqual(row['outer_radius_range_mm'][1],6,places=4)
def test_sharp_star_valleys_are_not_round(self):
points=[Vector((5 if i%2 else 8)*math.cos(i*math.pi/10),(5 if i%2 else 8)*math.sin(i*math.pi/10),0) for i in range(20)]
wire=Wire.make_polygon(points,close=True)
result=root_band_measurements(wire,Vector(),Vector(1,0,0),Vector(0,1,0),5,8)
self.assertEqual(result['junction_count'],10)
self.assertEqual(result['unpaired_endpoints'],0)
self.assertGreater(result['max_tangent_jump_deg'],60)
self.assertIsNone(result['curvature_radius_sample_range_mm'])
self.assertGreater(result['straight_samples'],0)
def test_actual_smooth_root_curvature_survives_rigid_transform(self):
shape=bevel_gear.run({},None,dict(large_tip_diameter=24,small_tip_diameter=17,height=8,tooth_count=22,twist_angle=7))
original=measure_radial_sections(shape,[0,0,0],[0,0,1],[4])['sections'][0]['root_band']
tr=Pos(3,-7,4)*Rot(23,17,41);plane=Plane.XY.moved(tr)
moved=measure_radial_sections(tr*shape,plane.origin,plane.z_dir,[4])['sections'][0]['root_band']
for result in (original,moved):
self.assertGreater(result['junction_count'],22)
self.assertEqual(result['unpaired_endpoints'],0)
self.assertLess(result['max_tangent_jump_deg'],.1)
self.assertGreater(result['curved_samples'],22)
self.assertAlmostEqual(result['curvature_radius_sample_range_mm'][0],.1025,delta=.002)
self.assertAlmostEqual(original['max_tangent_jump_deg'],moved['max_tangent_jump_deg'],delta=.01)
if __name__=='__main__':unittest.main()