-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Impl TryFrom
vector for directions and add InvalidDirectionError
#10884
Changes from 1 commit
c77af7b
97480d4
4856c3f
a784a6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,19 @@ pub trait Primitive2d {} | |
/// A marker trait for 3D primitives | ||
pub trait Primitive3d {} | ||
|
||
/// An error indicating that a direction is invalid because it is zero or not finite. | ||
#[derive(Debug)] | ||
pub struct InvalidDirectionError; | ||
|
||
impl std::fmt::Display for InvalidDirectionError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!( | ||
f, | ||
"Direction can not be zero (or very close to zero), or non-finite." | ||
) | ||
} | ||
} | ||
|
||
/// The winding order for a set of points | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum WindingOrder { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably more useful as an enum: the different failure modes are useful to bubble up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to do a custom
try_normalize
for this, but it should be easy since it's just an.is_finite()
and a comparison against zeroThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or alternatively, do the checks again, but only in error cases. I think this could be better since we can also check for NaN separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to an enum with
Zero
,Infinite
andNaN
variants and added tests to verify that it gives the correct errors.