-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated ViewportProjector to use Rect, and created unit tests (#2343)
* updated ViewportProjector to use Rect and created unit tests * linting ✨ * ⬛ * Correcting references to the viewport Thanks for pointing out the issue, @eruvanos!
- Loading branch information
1 parent
83cb72d
commit 072101f
Showing
2 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest as pytest | ||
|
||
from pyglet.math import Vec3, Vec2 | ||
|
||
from arcade import camera, Window | ||
from arcade.types import Point, LBWH, Rect | ||
|
||
@pytest.mark.parametrize("wrld_pos", [Vec2(100, 150), Vec2(1280, 720), Vec3(500, 500, -10)]) | ||
def test_viewport_projector_project(window: Window, wrld_pos: Point): | ||
cam = camera.default.ViewportProjector() | ||
assert cam.project(wrld_pos) == wrld_pos.xy | ||
|
||
@pytest.mark.parametrize("wrld_pos", [Vec2(100, 150), Vec2(1280, 720), Vec3(500, 500, -10)]) | ||
def test_viewport_projector_unproject(window: Window, wrld_pos: Point): | ||
cam = camera.default.ViewportProjector() | ||
x, y, *z = wrld_pos | ||
|
||
assert cam.unproject(wrld_pos) == Vec3(x, y, 0.0 if not z else z[0]) | ||
|
||
@pytest.mark.parametrize("viewport", [LBWH(0.0, 0.0, 100, 200), LBWH(100, 100, 20, 40), LBWH(300, 20, 20, 700)]) | ||
def test_viewport_projector_viewport(window: Window, viewport: Rect): | ||
cam = camera.default.ViewportProjector() | ||
assert cam.viewport.viewport == window.ctx.viewport | ||
cam.viewport = viewport | ||
assert cam.viewport == viewport |