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

Add cross and dot for Vector2d and Vector3d #112

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

sunsided
Copy link
Contributor

@sunsided sunsided commented Jul 9, 2024

This may go a bit against your philosophy judging from the comments on the to_array function(s). Here's what I did:

  • I added the cross and dot functions to Vector2d and Vector3d explicitly; they still remain part of the trait, but the trait impl forwards to the concrete implementations.
  • Since for Vector2d the cross-product lies outside of the plane, it promotes to Vector3d internally. This is still useful when determining which side of a line a point lies on, for example, as the Z component indicates that direction and distance.
  • The perpendicular_dot function performs the same but directly calculates the Z component since the others would be zero in "2D" space.

All in all, just a bit more symmetry between a types and a bit of convenience for a common 2D calculation.

@tarcieri
Copy link
Owner

@sunsided this has merge conflicts

@sunsided
Copy link
Contributor Author

@tarcieri Rebased it.

Comment on lines 44 to 47
/// Initializes a new instance of the `Vector2d` struct.
pub fn new(x: C, y: C) -> Self {
Self { x, y }
}
Copy link
Owner

Choose a reason for hiding this comment

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

Its members are all public. It doesn't need a constructor.

If anything, it's clearer to have explicit x: ..., y: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! - removed it. I had originally added it for symmetry with other crates such as nalgebra. Personally I find it more concise to create typical vectors like this, but ultimately I don't mind.

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe PR it separately

@tarcieri tarcieri merged commit 2e01dcc into tarcieri:main Jul 17, 2024
11 checks passed
@sunsided sunsided deleted the feature/cross branch July 17, 2024 14:24
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