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

Polygon-Line euclidean distance fix #226

Merged
merged 5 commits into from
May 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Line-Line euclidean distance
Closes #229
  • Loading branch information
urschrei committed May 16, 2018
commit 3b6c87956bd6ae785bd76ad470164401814267c1
15 changes: 15 additions & 0 deletions geo/src/algorithm/euclidean_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ where
}
}

impl<T> EuclideanDistance<T, Line<T>> for Line<T>
where
T: Float + FloatConst + Signed + SpadeFloat,
{
fn euclidean_distance(&self, other: &Line<T>) -> T {
if self.intersects(other) || self.contains(other) {
return T::zero();
}
// minimum of two Point-Line distances
self.start
.euclidean_distance(other)
.min(self.end.euclidean_distance(other))
}
}

// Line to Polygon distance
impl<T> EuclideanDistance<T, Polygon<T>> for Line<T>
where
Expand Down