24 lines
380 B
Rust
24 lines
380 B
Rust
|
use std::ops::Mul;
|
||
|
|
||
|
pub struct Vec2<T = f64> {
|
||
|
pub x: T,
|
||
|
pub y: T,
|
||
|
}
|
||
|
|
||
|
impl<T> Vec2<T> {
|
||
|
pub fn new(x: T, y: T) -> Self {
|
||
|
Self { x, y }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<S: Copy, T: Mul<S>> Mul<S> for Vec2<T> {
|
||
|
type Output = Vec2<T::Output>;
|
||
|
|
||
|
fn mul(self, rhs: S) -> Self::Output {
|
||
|
Vec2 {
|
||
|
x: self.x * rhs,
|
||
|
y: self.y * rhs,
|
||
|
}
|
||
|
}
|
||
|
}
|