Function gl_utils::graphics::point2d_clamp [−][src]
pub fn point2d_clamp<S: BaseNum>(aabb: &Aabb2<S>, point: &mut Point2<S>) -> bool
Clamp a 2D point to the given AABB rectangle, returns true if point was modified, or false otherwise if the point is already within the volume.
Examples
let mut point = cgmath::Point2::<i32>::new (-1, -1); assert!{ point2d_clamp ( &collision::Aabb2::<i32>::new ((0,0).into(), (10,10).into()), &mut point) } assert_eq!(point, (0,0).into()); assert!{ !point2d_clamp ( &collision::Aabb2::<i32>::new ((-5,-5).into(), (5,5).into()), &mut point) } assert_eq!(point, (0,0).into()); let mut point = cgmath::Point2::<f64>::new (-1.0, -1.0); assert!{ point2d_clamp ( &collision::Aabb2::<f64>::new ((0.0,0.0).into(), (10.0,10.0).into()), &mut point) } assert_eq!(point, (0.0,0.0).into()); assert!{ !point2d_clamp ( &collision::Aabb2::<f64>::new ((-5.0,-5.0).into(), (5.0,5.0).into()), &mut point) } assert_eq!(point, (0.0,0.0).into());