use bevy::prelude::*;

#[derive(Component, Default)]
#[require(Transform)]
pub struct SphereCollider {
    pub radius: f32,
}

impl SphereCollider {
    pub fn new(radius: f32) -> Self {
        SphereCollider { radius: radius }
    }
    pub fn point_inside(&self, self_pos: Vec3, point: Vec3) -> bool {
        (self_pos - point).length_squared() < self.radius * self.radius
    }
    pub fn collides(&self, self_pos: Vec3, other: &SphereCollider, other_pos: Vec3) -> bool {
        let radius_sum = self.radius + other.radius;
        (self_pos - other_pos).length_squared() < radius_sum * radius_sum
    }
}
