def test_swap_axis_full_ellipse(): ellipse = ConstructionEllipse( major_axis=(5, 0, 0), ratio=2, ) assert ellipse.minor_axis.isclose((0, 10, 0)) ellipse.swap_axis() assert ellipse.ratio == 0.5 assert ellipse.major_axis == (0, 10, 0) assert ellipse.minor_axis == (-5, 0, 0) assert ellipse.start_param == 0 assert ellipse.end_param == math.pi * 2
def test_swap_axis_arbitrary_params(): random_tests_count = 100 random.seed(0) for _ in range(random_tests_count): ellipse = ConstructionEllipse( # avoid (0, 0, 0) as major axis major_axis=(non_zero_random(), non_zero_random(), 0), ratio=2, start_param=random.uniform(0, math.tau), end_param=random.uniform(0, math.tau), extrusion=(0, 0, random.choice((1, -1))), ) # Test if coordinates of start- and end point stay at the same location # before and after swapping axis. start_point = ellipse.start_point end_point = ellipse.end_point minor_axis = ellipse.minor_axis ellipse.swap_axis() assert ellipse.major_axis.isclose(minor_axis, abs_tol=1e-9) assert ellipse.start_point.isclose(start_point, abs_tol=1e-9) assert ellipse.end_point.isclose(end_point, abs_tol=1e-9)