Skip to content

Commit

Permalink
Single branch check for approximate result in orient2d.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinko92 committed May 23, 2023
1 parent 6cead7c commit 2c5ea79
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,10 @@ pub fn orient2d<T: Into<f64>>(pa: Coord<T>, pb: Coord<T>, pc: Coord<T>) -> f64 {
let detright = (pa.y - pc.y) * (pb.x - pc.x);
let det = detleft - detright;

let detsum = if detleft > 0.0 {
if detright <= 0.0 {
return det;
} else {
detleft + detright
}
} else if detleft < 0.0 {
if detright >= 0.0 {
return det;
} else {
-detleft - detright
}
} else {
return det;
};
// The detsum calculation was changed to require only one branch on the likely execution path.
// This improves performance on modern processors as discussed by Ozaki et al in
// https://doi.org/10.1007/s10543-015-0574-9
let detsum = abs(detleft) + abs(detright);
let errbound = CCWERRBOUND_A * detsum;
if det >= errbound || -det >= errbound {
det
Expand Down

0 comments on commit 2c5ea79

Please sign in to comment.