import unittest import numpy as np from NodeSlicer.core.pdf_exporter.sizing import ( compute_grid_steps, compute_effective_stroke_and_font, LegendSizing, SA2Sizing, MM_TO_PT, ) class TestSizingLogic(unittest.TestCase): def test_compute_grid_steps_small_object(self): # 20mm x 15mm object main_step, minor_step = compute_grid_steps(20.0, 15.0) self.assertEqual(main_step, 1.0) self.assertEqual(minor_step, 0.1) def test_compute_grid_steps_medium_object(self): # 120mm x 80mm object main_step, minor_step = compute_grid_steps(120.0, 80.0) self.assertEqual(main_step, 10.0) self.assertEqual(minor_step, 1.0) def test_compute_effective_stroke_and_font_defaults(self): # 2mm object with minor_step = 0.01mm line_w_pt, font_size_pt = compute_effective_stroke_and_font(0.0, 0.0, 0.01) # Should scale line width down proportionally for millimetric scale self.assertAlmostEqual(line_w_pt, 0.01 * 0.05 * MM_TO_PT, places=6) self.assertAlmostEqual(font_size_pt, 0.01 * MM_TO_PT, places=6) def test_legend_sizing_scaling(self): leg = LegendSizing(10.0, 1.0, 1.0, 8.0) self.assertGreater(leg.y_axis_height_mm, leg.major_tick_mm) self.assertGreater(leg.arrow_len_pt, 0) self.assertGreater(leg.arrow_half_w_pt, 0) def test_sa2_sizing_millimetric_scale(self): # 2mm x 1.5mm millimetric scale object sa2 = SA2Sizing(2.0, 1.5, 0.0014, 0.028) # For a 1.5mm/2mm millimetric object, offset should be fine (0.15mm) self.assertAlmostEqual(sa2.offset_mm, 0.15, places=3) self.assertAlmostEqual(sa2.ext_overhang_mm, 0.03, places=3) slant, leader = sa2.get_hole_callout_lengths(0.5) self.assertAlmostEqual(slant, 0.15, places=3) self.assertAlmostEqual(leader, 0.20, places=3)