-
Notifications
You must be signed in to change notification settings - Fork 21
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
Precise vector test #4
Conversation
added file for edge clipping
* implemented shape * removed private interface * updated * implemented shape * removed spaces, kept eq impl
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.
Thanks for the PR! The code tooks great, and almost all reviews are about API conventions/idioms. Please feel free to give a feedback for the review.
} | ||
|
||
// PreciseVectorFromVector creates a high precision vector from the given Vector. | ||
pub fn precise_vector_from_vector(v: r3::vector::Vector) -> PreciseVector { |
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.
Could we use impl From<r3::vector::Vector> for PriciseVector
?
} | ||
|
||
// NewPreciseVector creates a high precision vector from the given floating point values. | ||
pub fn new_precise_vector(x: f64, y: f64, z: f64) -> PreciseVector { |
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.
How about
impl PreciesVector {
fn new(x: f64, y: f64, z: f64) -> Self { ... }
}
impl PreciseVector { | ||
|
||
// Vector returns this precise vector converted to a Vector. | ||
pub fn vector(&self) -> r3::vector::Vector { |
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.
How about impl From
here?
} | ||
|
||
// Equal reports whether v and ov are equal. | ||
pub fn equal(&self, ov: PreciseVector) -> bool { |
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.
How about std::cmp::Eq
trait? (or PartialEq
?)
} | ||
|
||
// Add returns the standard vector sum of v and ov. | ||
pub fn add(&self, ov: PreciseVector) -> PreciseVector { |
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.
Could we use std::ops::Add
and friends?
} | ||
|
||
// Sub returns the standard vector difference of v and ov. | ||
pub fn sub(&self, ov: PreciseVector) -> PreciseVector { |
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.
same here
} | ||
|
||
// Mul returns the standard scalar product of v and f. | ||
pub fn mul(&self, f: bigdecimal::BigDecimal) -> PreciseVector { |
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.
same here
} | ||
|
||
#[cfg(test)] | ||
mod tests { |
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.
Great!
|
||
|
||
// sortEdges sorts the slice of Edges in place. | ||
pub fn sort_edges(mut e: Vec<Edge>) { |
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.
How about pub fn sort_edges(e: &mut [Edge])
? The function takes Vec<Edge>
and drops the vector after sort, so there's no way to get a sorted result.
// OriginReferencePoint returns a ReferencePoint with the given value for | ||
// contained and the origin point. It should be used when all points or no | ||
// points are contained. | ||
pub fn origin_reference_point(contained: bool) -> ReferencePoint { |
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.
Could we put this function into impl ReferencePoint { ... }
?
@haynes1 Any feedback so far? May I merge the PR and apply feedbacks by myself? I'm a bit worried that it might break your code as it changes API. |
All but one test pass.
The test that doesn't pass is test_precise_round_trip(). This test converts a f64 vector to a precise vector, then converts it back to an f64 vector and normalizes it. The result should be equivalent to just normalizing the original f64 vector but it isn't.
The problem is that after conversion, the post-conversion normalized vector is accurate to one more decimal place than the pre-conversion normalized vector.
pre: 0.2672612419124244 post: 0.26726124191242434
Potential Research:
rust-lang/rust#24557
https://stackoverflow.com/questions/50361151/how-to-deal-with-inexact-floating-point-arithmetic-results-in-rust