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

Incorrect usage of abs_sub #120

Merged
merged 2 commits into from
Jun 22, 2017
Merged
Changes from all commits
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
18 changes: 17 additions & 1 deletion src/algorithm/intersects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<T> Intersects<Point<T>> for Line<T>
t <= T::one()
},
(Some(t_x), Some(t_y)) => { // All other lines
t_x.abs_sub(t_y) <= T::epsilon() &&
(t_x - t_y).abs() <= T::epsilon() &&
T::zero() <= t_x &&
t_x <= T::one()
}
Expand Down Expand Up @@ -448,12 +448,28 @@ mod test {
let line2 = Line::new(Point::new(0., 6.), Point::new(1.5, 4.5));
// point on line
let line3 = Line::new(Point::new(0., 6.), Point::new(3., 3.));
// point above line with positive slope
let line4 = Line::new(Point::new(1., 2.), Point::new(5., 3.));
// point below line with positive slope
let line5 = Line::new(Point::new(1., 5.), Point::new(5., 6.));
// point above line with negative slope
let line6 = Line::new(Point::new(1., 2.), Point::new(5., -3.));
// point below line with negative slope
let line7 = Line::new(Point::new(1., 6.), Point::new(5., 5.));
assert!(line1.intersects(&p0));
assert!(p0.intersects(&line1));
assert!(!line2.intersects(&p0));
assert!(!p0.intersects(&line2));
assert!(line3.intersects(&p0));
assert!(p0.intersects(&line3));
assert!(!line4.intersects(&p0));
assert!(!p0.intersects(&line4));
assert!(!line5.intersects(&p0));
assert!(!p0.intersects(&line5));
assert!(!line6.intersects(&p0));
assert!(!p0.intersects(&line6));
assert!(!line7.intersects(&p0));
assert!(!p0.intersects(&line7));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelkirk: to follow up on your previous comment, the failure occurs when the point is above a line with positive slope or below a line with negative slope. So I included examples above and below lines with positive and negative slopes. On master, lines 465-466 (line4) and lines 471-472 (line7) will fail.

}
#[test]
fn line_intersects_line_test() {
Expand Down