-
Notifications
You must be signed in to change notification settings - Fork 4
Add a zoom API for CameraController #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,9 @@ def orthographic(width: float = 1, height: float = 1, depth: float = 1) -> Trans | |||||
| width = width if width else 1e-6 | ||||||
| height = height if height else 1e-6 | ||||||
| depth = depth if depth else 1e-6 | ||||||
| # NOTE: In a right-handned coordinate system, the camera looks down -Z, so we need | ||||||
|
||||||
| # NOTE: In a right-handned coordinate system, the camera looks down -Z, so we need | |
| # NOTE: In a right-handed coordinate system, the camera looks down -Z, so we need |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,7 +73,7 @@ def _validate_ray(maybe_ray: Ray | None) -> Ray: | |||||||||||||||||||||||||||||||||||||||||||||||||
| return maybe_ray | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_pan() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_mouse() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Tests panning behavior of PanZoom.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction = snx.PanZoom() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cam = snx.Camera(interactive=True, controller=interaction) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,7 +96,7 @@ def test_panzoom_pan() -> None: | |||||||||||||||||||||||||||||||||||||||||||||||||
| np.testing.assert_allclose(cam.transform.root, expected.root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_zoom() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_scroll() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Tests zooming behavior of PanZoom.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction = snx.PanZoom() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cam = snx.Camera(interactive=True, controller=interaction) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -115,7 +115,70 @@ def test_panzoom_zoom() -> None: | |||||||||||||||||||||||||||||||||||||||||||||||||
| np.testing.assert_allclose(cam.projection.root, expected.root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_orbit_orbiting() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_zoom() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Tests zooming via the public zoom() API without a center.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction = snx.PanZoom() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cam = snx.Camera(interactive=True, controller=interaction) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| factor = 0.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| before = cam.projection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction.zoom(cam, factor) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| expected = before.scaled((factor, factor, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| np.testing.assert_allclose(cam.projection.root, expected.root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # No center provided — transform should be unchanged | ||||||||||||||||||||||||||||||||||||||||||||||||||
| np.testing.assert_allclose(cam.transform.root, snx.Transform().root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_panzoom_zoom_with_center() -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Tests that zoom() applies a compensating translation to keep center fixed.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction = snx.PanZoom() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| cam = snx.Camera(interactive=True, controller=interaction) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| factor = 0.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| center = (0.5, 0.3, 0.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction.zoom(cam, factor, center=center) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # Projection should be scaled | ||||||||||||||||||||||||||||||||||||||||||||||||||
| expected_proj = snx.Transform().scaled((factor, factor, -1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| np.testing.assert_allclose(cam.projection.root, expected_proj.root) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # Transform should have been panned by the compensating amount | ||||||||||||||||||||||||||||||||||||||||||||||||||
| zoom_center = np.array(center[:2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| camera_center = np.zeros(2) # camera was at origin before zoom | ||||||||||||||||||||||||||||||||||||||||||||||||||
| delta_screen1 = zoom_center - camera_center | ||||||||||||||||||||||||||||||||||||||||||||||||||
| delta_screen2 = delta_screen1 * factor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pan = (delta_screen2 - delta_screen1) / factor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| expected_transform = snx.Transform().translated((pan[0], pan[1])) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+137
to
+147
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| interaction.zoom(cam, factor, center=center) | |
| # Projection should be scaled | |
| expected_proj = snx.Transform().scaled((factor, factor, -1)) | |
| np.testing.assert_allclose(cam.projection.root, expected_proj.root) | |
| # Transform should have been panned by the compensating amount | |
| zoom_center = np.array(center[:2]) | |
| camera_center = np.zeros(2) # camera was at origin before zoom | |
| delta_screen1 = zoom_center - camera_center | |
| delta_screen2 = delta_screen1 * factor | |
| pan = (delta_screen2 - delta_screen1) / factor | |
| expected_transform = snx.Transform().translated((pan[0], pan[1])) | |
| before_proj = cam.projection | |
| before_transform = cam.transform | |
| interaction.zoom(cam, factor, center=center) | |
| # Projection should be scaled relative to the camera's prior projection | |
| expected_proj = before_proj.scaled((factor, factor, 1)) | |
| np.testing.assert_allclose(cam.projection.root, expected_proj.root) | |
| # Transform should have been panned by the compensating amount | |
| zoom_center = np.array(center[:2]) | |
| camera_center = before_transform.root[3, :2] | |
| delta_screen1 = zoom_center - camera_center | |
| delta_screen2 = delta_screen1 * factor | |
| pan = (delta_screen2 - delta_screen1) / factor | |
| expected_transform = before_transform.translated((pan[0], pan[1])) |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assignments create unused variables (zoom and desired_tform). Ruff enables F rules for tests, so this will fail linting. Remove the unused variables or use them in the assertion.
| zoom = interaction._zoom_factor(delta) | |
| desired_tform = snx.Transform().translated((0, 0, starting_dist)) |
Uh oh!
There was an error while loading. Please reload this page.