lesson 3
This commit is contained in:
1 parent
5f038f9bfa
commit
a4185970d9
4 files changed
+214
-158
No files matched your search
@@ -1,23 +1,19 @@
|
||||
pub fn mid(a: f32, b: f32) -> f32 {
|
||||
(a + b) / 2.0
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct f2d {
|
||||
x: f32,
|
||||
y: f32,
|
||||
x: f64,
|
||||
y: f64,
|
||||
}
|
||||
|
||||
impl f2d {
|
||||
pub fn new(a: f32, b: f32) -> Self {
|
||||
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) -> f32 {
|
||||
(self.x * self.x + self.y * self.y).sqrt()
|
||||
pub fn len(&self) -> f64 {
|
||||
self.x * self.x + self.y * self.y
|
||||
}
|
||||
|
||||
pub fn add(&mut self, b: f2d) {
|
||||
@@ -26,8 +22,8 @@ impl f2d {
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user