This simplifies a lot of code, and will make experimenting with other things a lot more straightforward.
31 lines
622 B
Rust
31 lines
622 B
Rust
use crate::math::Xform;
|
|
|
|
pub struct TransformStack {
|
|
stack: Vec<Xform>,
|
|
}
|
|
|
|
impl TransformStack {
|
|
pub fn new() -> TransformStack {
|
|
TransformStack { stack: Vec::new() }
|
|
}
|
|
|
|
pub fn clear(&mut self) {
|
|
self.stack.clear();
|
|
}
|
|
|
|
pub fn push(&mut self, xform: Xform) {
|
|
match self.stack.last() {
|
|
None => self.stack.push(xform),
|
|
Some(prev_xform) => self.stack.push(xform.compose(prev_xform)),
|
|
}
|
|
}
|
|
|
|
pub fn pop(&mut self) -> Option<Xform> {
|
|
self.stack.pop()
|
|
}
|
|
|
|
pub fn top(&self) -> Option<&Xform> {
|
|
self.stack.last()
|
|
}
|
|
}
|