Skip to content

Commit

Permalink
Allow only uniform scaling in Transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Oct 24, 2023
1 parent 14dcbea commit 8c7ab6d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
12 changes: 4 additions & 8 deletions graphics/src/transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ impl Transformation {
Transformation(Mat4::from_translation(Vec3::new(x, y, 0.0)))
}

/// Creates a scale transformation.
pub fn scale(x: f32, y: f32) -> Transformation {
Transformation(Mat4::from_scale(Vec3::new(x, y, 1.0)))
/// Creates a uniform scaling transformation.
pub fn scale(scaling: f32) -> Transformation {
Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
}

pub fn scale_x(&self) -> f32 {
pub fn scale_factor(&self) -> f32 {
self.0.x_axis.x
}

pub fn scale_y(&self) -> f32 {
self.0.y_axis.y
}

pub fn translation_x(&self) -> f32 {
self.0.w_axis.x
}
Expand Down
8 changes: 4 additions & 4 deletions tiny_skia/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl Backend {
paragraph,
*position * transformation,
*color,
scale_factor,
scale_factor * transformation.scale_factor(),
pixels,
clip_mask,
);
Expand Down Expand Up @@ -412,7 +412,7 @@ impl Backend {
*horizontal_alignment,
*vertical_alignment,
*shaping,
scale_factor,
scale_factor * transformation.scale_factor(),
pixels,
clip_mask,
);
Expand Down Expand Up @@ -624,10 +624,10 @@ fn into_color(color: Color) -> tiny_skia::Color {

fn into_transform(transformation: Transformation) -> tiny_skia::Transform {
tiny_skia::Transform {
sx: transformation.scale_x(),
sx: transformation.scale_factor(),
kx: 0.0,
ky: 0.0,
sy: transformation.scale_y(),
sy: transformation.scale_factor(),
tx: transformation.translation_x(),
ty: transformation.translation_y(),
}
Expand Down
8 changes: 4 additions & 4 deletions wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl Backend {
}

if !layer.meshes.is_empty() {
let scaled = transformation
* Transformation::scale(scale_factor, scale_factor);
let scaled =
transformation * Transformation::scale(scale_factor);

self.triangle_pipeline.prepare(
device,
Expand All @@ -156,8 +156,8 @@ impl Backend {
#[cfg(any(feature = "image", feature = "svg"))]
{
if !layer.images.is_empty() {
let scaled = transformation
* Transformation::scale(scale_factor, scale_factor);
let scaled =
transformation * Transformation::scale(scale_factor);

self.image_pipeline.prepare(
device,
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a> Layer<'a> {
paragraph: paragraph.clone(),
position: *position * transformation,
color: *color,
scale: transformation.scale_y(),
scale: transformation.scale_factor(),
});
}
Primitive::Text {
Expand All @@ -143,7 +143,7 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Cached(text::Cached {
content,
bounds: *bounds * transformation,
size: *size * transformation.scale_y(),
size: *size * transformation.scale_factor(),
line_height: *line_height,
color: *color,
font: *font,
Expand Down

0 comments on commit 8c7ab6d

Please sign in to comment.