-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Camera2D render target size bug & improve durability (#2050)
* Fix Camera2D.__init__ ignoring render target size * Use final render_target.size instead of window size * Clean up . accesses for shorter code + tiny speed boost * Fix Camera2D.from_raw_data ignoring target size * Get render_target earlier * Use render_target.size to define width and height * Make code cleaner +_ a tiny bit faster with less . access * Add tests for using render_target size * Use durable keyword args in Camera2D.__init__ * Use more durable keyword arguments in Camera2D.from_raw_data * Make Camera2D.from_raw_data a class method * Make it a class method with a typing_extensions.Self return type * Add a test for subclassing safety * Fix type issue * Correct Camera2D.viewport docstring per Discord discussion with Dragon * Correct the Camera2D tests to check viewport property * Move Camera2D tests to their own file * Move orthographic projector tests to better named file * Add missing newline at end of file
- Loading branch information
Showing
3 changed files
with
92 additions
and
32 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,55 @@ | ||
import pytest as pytest | ||
|
||
from arcade import Window | ||
from arcade.camera import Camera2D | ||
|
||
|
||
def test_camera2d_from_raw_data_inheritance_safety(window: Window): | ||
class MyCamera2D(Camera2D): | ||
... | ||
|
||
subclassed = MyCamera2D.from_raw_data(zoom=10.0) | ||
assert isinstance(subclassed, MyCamera2D) | ||
|
||
|
||
RENDER_TARGET_SIZES = [ | ||
(800, 600), # Normal window size | ||
(1280, 720), # Bigger | ||
(16, 16) # Tiny | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("width, height", RENDER_TARGET_SIZES) | ||
def test_camera2d_init_uses_render_target_size(window: Window, width, height): | ||
|
||
size = (width, height) | ||
texture = window.ctx.texture(size, components=4) | ||
framebuffer = window.ctx.framebuffer(color_attachments=[texture]) | ||
|
||
ortho_camera = Camera2D(render_target=framebuffer) | ||
assert ortho_camera.viewport_width == width | ||
assert ortho_camera.viewport_height == height | ||
|
||
assert ortho_camera.viewport == (0, 0, width, height) | ||
assert ortho_camera.viewport_left == 0 | ||
assert ortho_camera.viewport_right == width | ||
assert ortho_camera.viewport_bottom == 0 | ||
assert ortho_camera.viewport_top == height | ||
|
||
|
||
@pytest.mark.parametrize("width, height", RENDER_TARGET_SIZES) | ||
def test_camera2d_from_raw_data_uses_render_target_size(window: Window, width, height): | ||
|
||
size = (width, height) | ||
texture = window.ctx.texture(size, components=4) | ||
framebuffer = window.ctx.framebuffer(color_attachments=[texture]) | ||
|
||
ortho_camera = Camera2D.from_raw_data(render_target=framebuffer) | ||
assert ortho_camera.viewport_width == width | ||
assert ortho_camera.viewport_height == height | ||
|
||
assert ortho_camera.viewport == (0, 0, width, height) | ||
assert ortho_camera.viewport_left == 0 | ||
assert ortho_camera.viewport_right == width | ||
assert ortho_camera.viewport_bottom == 0 | ||
assert ortho_camera.viewport_top == height |
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