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

Remove From implementations from the direction types #10857

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/bevy_math/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use crate::Vec2;
#[derive(Clone, Copy, Debug)]
pub struct Direction2d(Vec2);

impl From<Vec2> for Direction2d {
fn from(value: Vec2) -> Self {
Self(value.normalize())
impl Direction2d {
/// Create a direction from a finite, nonzero [`Vec2`].
///
/// Returns `None` if the input is zero (or very close to zero), or non-finite.
pub fn new(value: Vec2) -> Option<Self> {
tim-blackbird marked this conversation as resolved.
Show resolved Hide resolved
value.try_normalize().map(Self)
}
}

impl Direction2d {
/// Create a direction from a [`Vec2`] that is already normalized
pub fn from_normalized(value: Vec2) -> Self {
debug_assert!(value.is_normalized());
Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_math/src/primitives/dim3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use crate::Vec3;
#[derive(Clone, Copy, Debug)]
pub struct Direction3d(Vec3);

impl From<Vec3> for Direction3d {
fn from(value: Vec3) -> Self {
Self(value.normalize())
impl Direction3d {
/// Create a direction from a finite, nonzero [`Vec3`].
///
/// Returns `None` if the input is zero (or very close to zero), or non-finite.
pub fn new(value: Vec3) -> Option<Self> {
value.try_normalize().map(Self)
}
}

impl Direction3d {
/// Create a direction from a [`Vec3`] that is already normalized
pub fn from_normalized(value: Vec3) -> Self {
debug_assert!(value.is_normalized());
Expand Down