|
| 1 | +import pytest |
| 2 | + |
| 3 | +from compas.geometry import Torus |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def torus(): |
| 8 | + return Torus(radius_axis=10.0, radius_pipe=2.0) |
| 9 | + |
| 10 | + |
| 11 | +def test_torus_discretization(torus): |
| 12 | + # just checking these don't break. Could not quickly find a formula that worked to test the actual values |
| 13 | + # as function of the resolution |
| 14 | + assert torus.edges |
| 15 | + assert torus.faces |
| 16 | + assert torus.vertices |
| 17 | + |
| 18 | + |
| 19 | +def test_torus_scaled(): |
| 20 | + """Test that Torus.scaled() returns a scaled copy without modifying the original.""" |
| 21 | + torus = Torus(radius_axis=10.0, radius_pipe=2.0) |
| 22 | + |
| 23 | + # Test uniform scaling |
| 24 | + scaled_torus = torus.scaled(0.5) |
| 25 | + |
| 26 | + # Original should be unchanged |
| 27 | + assert torus.radius_axis == 10.0 |
| 28 | + assert torus.radius_pipe == 2.0 |
| 29 | + |
| 30 | + # Scaled copy should have scaled dimensions |
| 31 | + assert scaled_torus.radius_axis == 5.0 |
| 32 | + assert scaled_torus.radius_pipe == 1.0 |
| 33 | + |
| 34 | + # Test scaling with factor > 1 |
| 35 | + scaled_torus_2 = torus.scaled(2.0) |
| 36 | + assert scaled_torus_2.radius_axis == 20.0 |
| 37 | + assert scaled_torus_2.radius_pipe == 4.0 |
| 38 | + assert torus.radius_axis == 10.0 # Original still unchanged |
| 39 | + assert torus.radius_pipe == 2.0 |
| 40 | + |
| 41 | + |
| 42 | +def test_torus_scale(): |
| 43 | + """Test that Torus.scale() modifies the torus in place.""" |
| 44 | + torus = Torus(radius_axis=10.0, radius_pipe=2.0) |
| 45 | + |
| 46 | + # Test uniform scaling |
| 47 | + torus.scale(0.5) |
| 48 | + |
| 49 | + # Torus should be modified |
| 50 | + assert torus.radius_axis == 5.0 |
| 51 | + assert torus.radius_pipe == 1.0 |
0 commit comments