lesson 2
This commit is contained in:
1 parent
9986cbbb28
commit
8b63d4fd7a
6 files changed
+185
-64
No files matched your search
@@ -0,0 +1,35 @@
|
||||
pub fn mid(a: f32, b: f32) -> f32 {
|
||||
(a + b) / 2.0
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct f2d {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
impl f2d {
|
||||
pub fn new(a: f32, b: f32) -> Self {
|
||||
f2d { x: a, y: b }
|
||||
}
|
||||
pub fn def() -> Self {
|
||||
f2d { x: 0.0, y: 0.0 }
|
||||
}
|
||||
//
|
||||
pub fn len(&self) -> f32 {
|
||||
(self.x * self.x + self.y * self.y).sqrt()
|
||||
}
|
||||
|
||||
pub fn add(&mut self, b: f2d) {
|
||||
self.x += b.x;
|
||||
self.y += b.y;
|
||||
}
|
||||
|
||||
pub fn mul(&mut self, b: f2d) {
|
||||
let x: f32 = self.x * b.x - self.y * b.y;
|
||||
let y: f32 = self.x * b.y + self.y * b.x;
|
||||
|
||||
self.x = x;
|
||||
self.y = y;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user