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

Precise vector test #4

Merged
merged 7 commits into from
Oct 16, 2019
Merged

Conversation

haynes1
Copy link
Contributor

@haynes1 haynes1 commented Jun 18, 2019

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

Copy link
Owner

@yjh0502 yjh0502 left a 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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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>) {
Copy link
Owner

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 {
Copy link
Owner

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 { ... }?

@yjh0502
Copy link
Owner

yjh0502 commented Jul 12, 2019

@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.

@yjh0502 yjh0502 merged commit 7ce90db into yjh0502:master Oct 16, 2019
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.

3 participants