Add Plane::translate

This commit is contained in:
Hanno Braun 2024-12-17 20:48:53 +01:00
parent 50d5703399
commit 9985efaf40
2 changed files with 9 additions and 8 deletions

View File

@ -1,4 +1,4 @@
use super::{Bivector, Point}; use super::{Bivector, Point, Vector};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct Plane { pub struct Plane {
@ -11,4 +11,11 @@ impl Plane {
let [u, v] = point.into().coords.components; let [u, v] = point.into().coords.components;
self.origin + self.coords.a * u + self.coords.b * v self.origin + self.coords.a * u + self.coords.b * v
} }
pub fn translate(self, offset: impl Into<Vector<3>>) -> Self {
Self {
origin: self.origin + offset,
coords: self.coords,
}
}
} }

View File

@ -15,13 +15,7 @@ pub fn model(shape: &mut Shape) {
b: Vector::from([0., 1., 0.]), b: Vector::from([0., 1., 0.]),
}, },
}; };
let top = Plane { let top = bottom.translate([0., 0., 1.]);
origin: Point::from([0., 0., 0.5]),
coords: Bivector {
a: Vector::from([1., 0., 0.]),
b: Vector::from([0., 1., 0.]),
},
};
let (a, b, c, d, e, f, g, h) = shape let (a, b, c, d, e, f, g, h) = shape
.extend_with(&mut vertices) .extend_with(&mut vertices)