glam-rs icon indicating copy to clipboard operation
glam-rs copied to clipboard

`within` method for `Vec2` and `Vec3`

Open whimbur-total opened this issue 1 year ago • 1 comments

A method to check if a point self is somewhere inside the area of a rectangle with point a being the top-left corner and point b being the bottom-right corner.

pub fn within(&self, a: &Vec2, b: &Vec2) -> bool

example:

let a = Vec2::ZERO;
let b = Vec2::ONE;

assert!(Vec2::(0.5, 0.5).within(&a, &b))
assert!(Vec2::ONE.within(&a, &b))
assert!(Vec2::(1.5, 0.25).within(&a, &b)) // Assertion fails because `1.5 > 1.0`

whimbur-total avatar Dec 24 '24 05:12 whimbur-total

I'm a bit undecided on this one. It feels like something that might be better supported in some kind of 2D bounding box type, put for now that is out of scope for glam.

bitshifter avatar Mar 20 '25 07:03 bitshifter