Created
July 18, 2019 20:29
-
-
Save superdump/21fd0084a2ffe502a42b7fc364710d18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn partition_points(vertices: &Vec<Vertex2>, e: &Edge, s_opt: Option<&Vec<(usize, f32)>>) -> (Vec<(usize, f32)>, Vec<(usize, f32)>) { | |
let mut s_right = Vec::<(usize, f32)>::new(); | |
let mut s_left = Vec::<(usize, f32)>::new(); | |
// i did this... | |
let closure = |i: &usize| { | |
if *i == e.origin || *i == e.destination { | |
return; | |
} | |
if let Some(d) = e.intersect_from_ray(vertices, *i) { | |
if d >= 0f32 { | |
s_right.push((*i, d)); | |
} else { | |
s_left.push((*i, d)); | |
} | |
} | |
}; | |
if let Some(s) = s_opt { | |
s.iter().map(|(i, _)| *i).collect::<Vec<_>>().iter().for_each(closure); | |
} else { | |
(0..vertices.len()).into_iter().collect::<Vec<_>>().iter().for_each(closure); | |
} | |
// to avoid doing this... | |
if let Some(s) = s_opt { | |
for (i, _) in s { | |
if *i == e.origin || *i == e.destination { | |
continue; | |
} | |
if let Some(d) = e.intersect_from_ray(vertices, *i) { | |
if d >= 0f32 { | |
s_right.push((*i, d)); | |
} else { | |
s_left.push((*i, d)); | |
} | |
} | |
} | |
} else { | |
for i in 0..vertices.len() { | |
if i == e.origin || i == e.destination { | |
continue; | |
} | |
if let Some(d) = e.intersect_from_ray(vertices, i) { | |
if d >= 0f32 { | |
s_right.push((i, d)); | |
} else { | |
s_left.push((i, d)); | |
} | |
} | |
} | |
} | |
(s_right, s_left) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment