Function simplicity::orient_2d[][src]

pub fn orient_2d<T: ?Sized, Idx: Ord + Copy>(
    list: &T,
    index_fn: impl Fn(&T, Idx) -> Vector2<f64>,
    i: Idx,
    j: Idx,
    k: Idx
) -> bool

Returns whether the orientation of 3 points in 2-dimensional space is positive after perturbing them; that is, if the 3 points form a left turn when visited in order.

Takes a list of all the points in consideration, an indexing function, and 3 indexes to the points to calculate the orientation of.

Example

let points = vec![
    Vector2::new(0.0, 0.0),
    Vector2::new(1.0, 0.0),
    Vector2::new(1.0, 1.0),
    Vector2::new(2.0, 2.0),
];
let positive = orient_2d(&points, |l, i| l[i], 0, 1, 2);
assert!(positive);
let positive = orient_2d(&points, |l, i| l[i], 0, 3, 2);
assert!(!positive);