32 lines
571 B
Rust
32 lines
571 B
Rust
#[derive(Clone)]
|
|
pub struct f2d {
|
|
x: f64,
|
|
y: f64,
|
|
}
|
|
|
|
impl f2d {
|
|
pub fn new(a: f64, b: f64) -> Self {
|
|
f2d { x: a, y: b }
|
|
}
|
|
pub fn def() -> Self {
|
|
f2d { x: 0.0, y: 0.0 }
|
|
}
|
|
//
|
|
pub fn len(&self) -> f64 {
|
|
self.x * self.x + self.y * self.y
|
|
}
|
|
|
|
pub fn add(&mut self, b: f2d) {
|
|
self.x += b.x;
|
|
self.y += b.y;
|
|
}
|
|
|
|
pub fn mul(&mut self, b: f2d) {
|
|
let x: f64 = self.x * b.x - self.y * b.y;
|
|
let y: f64 = self.x * b.y + self.y * b.x;
|
|
|
|
self.x = x;
|
|
self.y = y;
|
|
}
|
|
}
|