Converts 3d point to a 2d drawable point >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) (7.6923076923076925, 15.384615384615385) >>> convert_to_2d(1, 2, 3, 10, 10) (7.6923076923076925, 15.384615384615385) >>> convert_to_2d("1", 2, 3, 10, 10) # '1' is str Traceback (mos
(
x: float, y: float, z: float, scale: float, distance: float
)
| 11 | |
| 12 | |
| 13 | def convert_to_2d( |
| 14 | x: float, y: float, z: float, scale: float, distance: float |
| 15 | ) -> tuple[float, float]: |
| 16 | """ |
| 17 | Converts 3d point to a 2d drawable point |
| 18 | |
| 19 | >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) |
| 20 | (7.6923076923076925, 15.384615384615385) |
| 21 | |
| 22 | >>> convert_to_2d(1, 2, 3, 10, 10) |
| 23 | (7.6923076923076925, 15.384615384615385) |
| 24 | |
| 25 | >>> convert_to_2d("1", 2, 3, 10, 10) # '1' is str |
| 26 | Traceback (most recent call last): |
| 27 | ... |
| 28 | TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10] |
| 29 | """ |
| 30 | if not all(isinstance(val, (float, int)) for val in locals().values()): |
| 31 | msg = f"Input values must either be float or int: {list(locals().values())}" |
| 32 | raise TypeError(msg) |
| 33 | projected_x = ((x * distance) / (z + distance)) * scale |
| 34 | projected_y = ((y * distance) / (z + distance)) * scale |
| 35 | return projected_x, projected_y |
| 36 | |
| 37 | |
| 38 | def rotate( |
no outgoing calls
no test coverage detected