Skip to content
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

Bug in Camera.translate_to_frame #358

Open
pathunstrom opened this issue Aug 24, 2019 · 1 comment
Open

Bug in Camera.translate_to_frame #358

pathunstrom opened this issue Aug 24, 2019 · 1 comment
Labels

Comments

@pathunstrom
Copy link
Collaborator

Hypothesis found a bug in the Camera. Relevant test failure:


    @given(
>       vp_width=st.integers(min_value=1),
        vp_height=st.integers(min_value=1),
        pixel_ratio=st.floats(min_value=1, max_value=1e5, allow_nan=False, allow_infinity=False),
        cam_pos=vectors(),
        point=vectors(),
        delta=vectors(),
    )
    def test_transfromation_movement(
        vp_width, vp_height, pixel_ratio, cam_pos, point, delta,
    ):

tests\test_camera.py:131:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

vp_width = 1, vp_height = 1, pixel_ratio = 1.0, cam_pos = Vector(0.0, 7.067388259113906e+72), point = Vector(0.0, 0.0), delta = Vector(0.0, 2.2204460492503134e+59)


    @given(
        vp_width=st.integers(min_value=1),
        vp_height=st.integers(min_value=1),
        pixel_ratio=st.floats(min_value=1, max_value=1e5, allow_nan=False, allow_infinity=False),
        cam_pos=vectors(),
        point=vectors(),
        delta=vectors(),
    )
    def test_transfromation_movement(
        vp_width, vp_height, pixel_ratio, cam_pos, point, delta,
    ):
        cam = Camera(
            viewport=(0, 0, vp_width, vp_height),
            pixel_ratio=pixel_ratio,
        )
        cam.position = cam_pos
    
        assume(delta.length != 0)
    
        point_moved = point + delta
    
        assume(point_moved != point)  # This will happen when delta is too small to make an effect
    
        note(f"point moved: {point_moved}")
    
        diff = cam.translate_to_frame(point_moved) - cam.translate_to_frame(point)
        note(f"frame diff: {diff}")
>       assert isclose(delta.length, pixel_ratio * diff.length, rel_tol=1e-4)
E       assert False
E        +  where False = isclose(2.2204460492503134e+59, (1.0 * 2.212678361723805e+59), rel_tol=0.0001)
E        +    where 2.2204460492503134e+59 = Vector(0.0, 2.2204460492503134e+59).length
E        +    and   2.212678361723805e+59 = Vector(0.0, -2.212678361723805e+59).length

tests\test_camera.py:157: AssertionError
--------------------------------------------------------------------------- Hypothesis ---------------------------------------------------------------------------
Falsifying example: test_transfromation_movement(vp_width=1, vp_height=1, pixel_ratio=1.0, cam_pos=Vector(0.0, 7.067388259113906e+72), point=Vector(0.0, 0.0), delt
a=Vector(0.0, 2.2204460492503134e+59))
point moved: Vector(0.0, 2.2204460492503134e+59)
frame diff: Vector(0.0, -2.212678361723805e+59)
@AstraLuma
Copy link
Member

This looks like a bug somewhere. The magnitudes are all similar but the sign is flipped.

bors bot added a commit that referenced this issue Apr 26, 2020
439: Camera Redesign r=astronouth7303 a=pathunstrom

This is the long awaited fix to all the pain points in the Camera. So far, it's just an __init__.

This represents a breaking change in the API.

This touches on a number of issues, some solved wholly by this change, some only fixes part of the problem.

Resolves #185: pixel_ratio is now derived from the number of game units you want visible and the screen resolution. You can "zoom" by increasing or decreasing the width or height of the camera.
Resolves #310: Camera isn't added until SceneStarted event, but is fully initialized as soon as it's available.
Regarding #358: Did not deal with this directly. That test is currently nullified until we can go over it and determine what is going on.
Regarding #400:  Removes the pixel_ratio argument from BaseScene.

Co-authored-by: Piper Thunstrom <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants