csci5607/assignment-0/src/vec2.rs
2023-02-20 22:05:32 -06:00

25 lines
406 B
Rust

use std::ops::Mul;
/// A generic 2-dimensional point class.
#[derive(Copy, Clone)]
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,
}
}
}