-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…10884) # Objective Implement `TryFrom<Vec2>`/`TryFrom<Vec3>` for direction primitives as considered in #10857. ## Solution Implement `TryFrom` for the direction primitives. These are all equivalent: ```rust let dir2d = Direction2d::try_from(Vec2::new(0.5, 0.5)).unwrap(); let dir2d = Vec2::new(0.5, 0.5).try_into().unwrap(); // (assumes that the type is inferred) let dir2d = Direction2d::new(Vec2::new(0.5, 0.5)).unwrap(); ``` For error cases, an `Err(InvalidDirectionError)` is returned. It contains the type of failure: ```rust /// An error indicating that a direction is invalid. #[derive(Debug, PartialEq)] pub enum InvalidDirectionError { /// The length of the direction vector is zero or very close to zero. Zero, /// The length of the direction vector is `std::f32::INFINITY`. Infinite, /// The length of the direction vector is `NaN`. NaN, } ```
- Loading branch information
Showing
3 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters