Skip to content

flip camera2D init and from_raw_data #2072

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

Merged
merged 9 commits into from
Apr 27, 2024

Conversation

alejcas
Copy link
Member

@alejcas alejcas commented Apr 24, 2024

This is the camera init/from_raw_data code flip we talk on discord.

Nota that from_raw_data cameras won't reference the same data objects but create new ones using data from the provided objects.

I have also fixed examples and tests.

I tested using the example codes and all worked

from_raw_data cameras won't reference the same data objects but create new ones
fix examples and tests
@DragonMoffon
Copy link
Collaborator

While I understand why it was done the way it was, this fundamentally breaks a core assumption of the Cameras. The CameraData and OrthographicProjectionData objects have to be shared between objects.
It would be better to create the camera with default values and then override the attributes later

@alejcas
Copy link
Member Author

alejcas commented Apr 24, 2024

I can rewrite from_raw_data to build a camera with the arguments (c data and p data).

but i think it should be called “from_camera”:

Camera2D.from_camera(camera: Camera2D)

or “from_camera_data” with same arguments as “from_raw_data” but reusing the internal data objects.

what do you think?

rewrite done on fb025ec

@MiCurry
Copy link
Contributor

MiCurry commented Apr 25, 2024

I'm wondering if we might run into some shallow vs deep copy issues with from_camera_data. Specifically if someone tries to use the camera data from one camera to initialize another:

camera1 = Camera(...)
camera2 = Camera.from_camera_data(camera1.view_data, camera1.projection_data)

In that case I think adjusting either camera would affect the other, since they both contain references to each other. We should be able to easily test this in a unit test, which I'll make if I get some freetime today.

@alejcas
Copy link
Member Author

alejcas commented Apr 25, 2024

I'm wondering if we might run into some shallow vs deep copy issues with from_camera_data. Specifically if someone tries to use the camera data from one camera to initialize another:

camera1 = Camera(...)
camera2 = Camera.from_camera_data(camera1.view_data, camera1.projection_data)

In that case I think adjusting either camera would affect the other, since they both contain references to each other. We should be able to easily test this in a unit test, which I'll make if I get some freetime today.

I think this is the intended purpose.

Copy link
Member

@pushfoo pushfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: The docstring change to clarify the shared data object behavior is the most we should do in this PR.

@MiCurry the shared behavior is intended, but I agree we need to document it better and think about the CameraAPI a bit more.

However, this PR isn't the place for those changes. We can add a minimal docstring fix since @DragonMoffon and @DigiDuncan are finishing up prototyping improvements which will likely cause merge conflicts with further API changes.

Copy link
Member

@pushfoo pushfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A bunch of changes are coming, so we'll fix lingering API & doc issues in subsequent PRs.

@Cleptomania Cleptomania merged commit ae42cf1 into pythonarcade:development Apr 27, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants