Hide handle overlays too close to the parent anchor (#951)

Hide handle overlay

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2023-01-09 03:32:26 +00:00
committed by Keavon Chambers
parent 2a27471363
commit 741e61a59d
4 changed files with 66 additions and 33 deletions

View File

@@ -78,12 +78,23 @@ impl ManipulatorGroup {
}
/// Finds the closest [ManipulatorPoint] owned by this [ManipulatorGroup]. This may return the anchor or either handle.
pub fn closest_point(&self, transform_space: &DAffine2, target: glam::DVec2) -> usize {
pub fn closest_point(&self, transform_space: &DAffine2, target: glam::DVec2, hide_handle_distance: f64) -> usize {
let mut closest_index: usize = 0;
let mut closest_distance_squared: f64 = f64::MAX; // Not ideal
for (index, point) in self.points.iter().enumerate() {
if let Some(point) = point {
let distance_squared = transform_space.transform_point2(point.position).distance_squared(target);
let transfomed_point = transform_space.transform_point2(point.position);
// Don't check handles under the anchor
if index != ManipulatorType::Anchor as usize {
if let Some(anchor) = &self.points[ManipulatorType::Anchor] {
if transfomed_point.distance_squared(transform_space.transform_point2(anchor.position)) < hide_handle_distance * hide_handle_distance {
continue;
}
}
}
let distance_squared = transfomed_point.distance_squared(target);
if distance_squared < closest_distance_squared {
closest_distance_squared = distance_squared;
closest_index = index;