Skip to content

Commit

Permalink
#13 Add translate_3d and scale_3d
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Sep 10, 2023
1 parent e1f4ac1 commit eefdbd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct LocalSpace {}
pub type LocalPoint = Point2D<f32, LocalSpace>;
pub type LocalVector = Vector2D<f32, LocalSpace>;
pub type LocalSize = Size2D<f32, LocalSpace>;
pub type LocalVector3D = Vector3D<f32, LocalSpace>;

pub type LocalToWorld = Transform3D<f32, LocalSpace, WorldSpace>;
pub type WorldToLocal = Transform2D<f32, WorldSpace, LocalSpace>;
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,14 @@ impl Vger {
}
}

/// Translates the coordinate system (3d version).
pub fn translate_3d<Vec: Into<LocalVector3D>>(&mut self, offset: Vec) {
if let Some(m) = self.tx_stack.last_mut() {
let off: LocalVector3D = offset.into();
*m = (*m).pre_translate(off);
}
}

/// Scales the coordinate system.
pub fn scale<Vec: Into<LocalVector>>(&mut self, scale: Vec) {
if let Some(m) = self.tx_stack.last_mut() {
Expand All @@ -823,6 +831,14 @@ impl Vger {
}
}

/// Scales the coordinate system (3d version).
pub fn scale_3d<Vec: Into<LocalVector3D>>(&mut self, scale: Vec) {
if let Some(m) = self.tx_stack.last_mut() {
let s: LocalVector3D = scale.into();
*m = (*m).pre_scale(s.x, s.y, s.z);
}
}

/// Rotates the coordinate system.
pub fn rotate(&mut self, theta: f32) {
if let Some(m) = self.tx_stack.last_mut() {
Expand Down

0 comments on commit eefdbd5

Please sign in to comment.