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

Refactor the math module #294

Merged
merged 9 commits into from
Feb 4, 2025
Merged

Refactor the math module #294

merged 9 commits into from
Feb 4, 2025

Conversation

isHarryh
Copy link
Contributor

Summary

This PR has undergone comprehensive optimizations and fixes for the math module.

Breaking Changes

  1. Complete implementation for Vector2 and Vector4. (According to Vector3.)
  2. Remove the file Half.py since the only function ToHalf in this file is not used any more. (ToHalf was used in the Texture2DConvertor in the earlier version of UnityPy, but this usage has been removed in later versions.)

Common Changes

  1. Type hints.
  2. Use @dataclass decorator for all classes. (Before this PR, only Vector3 had this decorator.)
  3. Use __truediv__ (Python 3) to replace __div__ (Python2).
  4. Argument type validation.
  5. Avoid duplicate __eq__ method declarations.
  6. Remove unnecessary comments at the end of the file.

Individual Optimizations

  1. Vector3: Use Method = method to redirect duplicated method.
  2. Vector3: Use a better __eq__ method (which is also Unity's implementation).
  3. Quaternion: Remove the redundant self._data field.
  4. Color: Use a better __eq__ method.

Individual Fixes

  1. Vector3: Incorrect if-statement in __init__ method.
  2. Vector3: Incorrect else-body in normalize method.
  3. Vector3: Incorrect LengthSquare method.
  4. Quaternion: The w value of the identity quaternion (default quaternion) is 1.0, not 0.0.
  5. Matrix4x4: Corrupted __eq__ method.

Copy link
Owner

@K0lb3 K0lb3 left a comment

Choose a reason for hiding this comment

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

Just one change

@K0lb3
Copy link
Owner

K0lb3 commented Feb 3, 2025

Thanks for the PR and fixes.

I'm also rewriting and pruning these classes for the next minor patch,
so you might have ended up wasting some time, sorry for taking a bit too long with that patch.

For the version 2 update I plan to include numpy....and for that the math classes are going to get another rewrite,
subtyping them from the np.ndarray class, making them directly compatible with numpy functions.

But that's still some time off,
as I will have to focus on other things in the next months.
So thanks a lot for these changes and fixes.

@isHarryh
Copy link
Contributor Author

isHarryh commented Feb 4, 2025

No problem at all! The simple work didn’t take long, happy to help. Good luck with the UnityPy 2 updates!

@isHarryh isHarryh requested a review from K0lb3 February 4, 2025 05:17
Copy link
Owner

@K0lb3 K0lb3 left a comment

Choose a reason for hiding this comment

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

Thanks a lot 👍

@K0lb3 K0lb3 merged commit 7886686 into K0lb3:master Feb 4, 2025
3 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.

2 participants