#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vec2 {
    pub x: f32,
    pub y: f32,
}

impl Vec2 {
    pub fn new(x: f32, y: f32) -> Self {
        Self { x, y }
    }
    
    pub fn zero() -> Self {
        Self::new(0.0, 0.0)
    }
    
    pub fn one() -> Self {
        Self::new(1.0, 1.0)
    }
    
    pub fn up() -> Self {
        Self::new(0.0, 1.0)
    }
    
    pub fn right() -> Self {
        Self::new(1.0, 0.0)
    }
    
    /// 벡터의 크기(길이) 계산
    pub fn magnitude(&self) -> f32 {
        (self.x * self.x + self.y * self.y).sqrt()
    }
    
    /// 벡터의 제곱 크기 (sqrt 없이 빠른 계산)
    pub fn magnitude_squared(&self) -> f32 {
        self.x * self.x + self.y * self.y
    }
    
    /// 정규화된 벡터 (크기 1인 벡터)
    pub fn normalized(&self) -> Self {
        let mag = self.magnitude();
        if mag > 0.0 {
            Self::new(self.x / mag, self.y / mag)
        } else {
            Self::zero()
        }
    }
    
    /// 두 벡터 사이의 거리
    pub fn distance(&self, other: Vec2) -> f32 {
        (*self - other).magnitude()
    }
    
    /// 두 벡터의 내적
    pub fn dot(&self, other: Vec2) -> f32 {
        self.x * other.x + self.y * other.y
    }
}

/// Vec2 연산자 구현
impl std::ops::Add for Vec2 {
    type Output = Vec2;
    
    fn add(self, other: Vec2) -> Vec2 {
        Vec2::new(self.x + other.x, self.y + other.y)
    }
}

impl std::ops::Sub for Vec2 {
    type Output = Vec2;
    
    fn sub(self, other: Vec2) -> Vec2 {
        Vec2::new(self.x - other.x, self.y - other.y)
    }
}

impl std::ops::Mul<f32> for Vec2 {
    type Output = Vec2;
    
    fn mul(self, scalar: f32) -> Vec2 {
        Vec2::new(self.x * scalar, self.y * scalar)
    }
}

impl std::ops::Div<f32> for Vec2 {
    type Output = Vec2;
    
    fn div(self, scalar: f32) -> Vec2 {
        Vec2::new(self.x / scalar, self.y / scalar)
    }
}