-
Notifications
You must be signed in to change notification settings - Fork 200
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
Support generic numeric type for geometries #30
Conversation
@@ -163,13 +169,17 @@ impl Point { | |||
/// | |||
/// assert!(dist < 1e-1) | |||
/// ``` | |||
pub fn distance_to(&self, point: &Point) -> f64 { | |||
((self.x() - point.x()).powi(2) + (self.y() - point.y()).powi(2)).sqrt() | |||
pub fn distance_to(&self, point: &Point<T>) -> f64 { |
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.
If instead of using num::Num
everywhere, we used num::Float
, we could make distance_to
generic by utilizing num::Float::sqrt
.
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.
It also means you can remove the explicit Copy
trait bounds specifying everywhere since Float
is a subtype of Copy
.
I wouldn't be too worried about the |
Looks great, awesome work! In general, I think it'd be great if all the operations could be made generic. Then we could remove the |
let x1 : f64 = p1.x().to_f64().unwrap(); | ||
let x2 : f64 = p2.x().to_f64().unwrap(); | ||
let y1 : f64 = p1.y().to_f64().unwrap(); | ||
let y2 : f64 = p2.y().to_f64().unwrap(); | ||
total_length += segment_len; |
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.
If you try to make this generic, the type checker might complain. You might need to make this into total_length = total_length + segment_len;
Up ? 😄 |
Hi Kerosene2000, |
Hi @Kerosene2000 and @zarch, |
Done 😄 |
sum_x += tmp * p.lng(); | ||
sum_y += tmp * p.lat(); | ||
sum_x = sum_x + tmp * p.lng(); | ||
sum_y = sum_y + tmp * p.lat(); |
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.
You forgot this one ;-)
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.
You have to look at here 😄
Until @zarch merge with its branch
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.
My bad, didn't see the pull request on the pull request 👼
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.
Haha 😸
Wow, thank you...
Sorry, I didn't notice it, I've just accept your PR... |
I think so ! |
This looks great! Upon a quick glance, it looks like everything has been made generic. Is there anything else to do here before final reviews + merging? |
fn centroid(&self) -> Option<Point> { | ||
// TODO: consideration of inner polygons; | ||
fn centroid(&self) -> Option<Point<T>> { | ||
// TODO: consideration of inner polygons; |
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.
Nit: extra whitespace in front here
I just did a review. Besides the commented out code, which can be removed, I don't see any other changes that need to be made. Anyone else have thoughts? |
let (dx, dy) = (self.x() - p.x(), self.y() - p.y()); | ||
// (dx * dx + dy * dy)**(T::one()/(T::one() + T::one())) | ||
// ((self.x() - p.x()).powi(2) + (self.y() - p.y()).powi(2)).sqrt() | ||
(dx * dx + dy * dy).sqrt() // FIXME is it correct ??? (euclidian dist) |
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.
These comments can be removed. The logic seems fine to me.
Thank you @zarch and @Kerosene2000 for your contributions here! I'm looking forward to these changes! 🎊 I thought about squashing, but:
I'm going to merge now, but I won't plan on publishing a new version of rust-geo (version 0.2) until Sunday evening Eastern time just to give some time in-case anyone has additional concerns. |
Version 0.2.0 of geo-rust has been released which includes these changes. |
Merge georust#30 a=@frewsxcv r=@frewsxcv ________________________________________________________________________ I'm the only contributor, so this should be a straightforward license change.
Hi, here a revised version to add generics to geometries (see previous pull request #25).
I create a separate branch called: generics to make it easier to keep it sync with the official master.
I've modified the code to remove most of the Neg<Output = T> as suggested by @jdroenner , I was not able to remove Copy without compilation errors so it is still there.
As suggested by @jdroenner we can just pass the reference, in this way we can remove most of the Copy, but it required to add some clone() to pass the tests, here you can see the difference:
Other ideas to improve this? should we pass the Copy or the reference?