Allow only uniform scaling in Transformation

This commit is contained in:
Héctor Ramón Jiménez 2023-10-24 03:18:03 +02:00
parent aa41d7656e
commit a6e91d13d5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 16 additions and 21 deletions

View file

@ -26,21 +26,16 @@ impl Transformation {
Transformation(Mat4::from_translation(Vec3::new(x, y, 0.0))) Transformation(Mat4::from_translation(Vec3::new(x, y, 0.0)))
} }
/// Creates a scale transformation. /// Creates a uniform scaling transformation.
pub fn scale(x: f32, y: f32) -> Transformation { pub fn scale(scaling: f32) -> Transformation {
Transformation(Mat4::from_scale(Vec3::new(x, y, 1.0))) Transformation(Mat4::from_scale(Vec3::new(scaling, scaling, 1.0)))
} }
/// The scale factor on the X axis. /// The scale factor of the [`Transformation`].
pub fn scale_x(&self) -> f32 { pub fn scale_factor(&self) -> f32 {
self.0.x_axis.x self.0.x_axis.x
} }
/// The scale factor on the Y axis.
pub fn scale_y(&self) -> f32 {
self.0.y_axis.y
}
/// The translation on the X axis. /// The translation on the X axis.
pub fn translation_x(&self) -> f32 { pub fn translation_x(&self) -> f32 {
self.0.w_axis.x self.0.w_axis.x

View file

@ -461,7 +461,7 @@ impl Backend {
paragraph, paragraph,
*position * transformation, *position * transformation,
*color, *color,
scale_factor, scale_factor * transformation.scale_factor(),
pixels, pixels,
clip_mask, clip_mask,
); );
@ -523,7 +523,7 @@ impl Backend {
*horizontal_alignment, *horizontal_alignment,
*vertical_alignment, *vertical_alignment,
*shaping, *shaping,
scale_factor, scale_factor * transformation.scale_factor(),
pixels, pixels,
clip_mask, clip_mask,
); );
@ -770,10 +770,10 @@ fn into_color(color: Color) -> tiny_skia::Color {
fn into_transform(transformation: Transformation) -> tiny_skia::Transform { fn into_transform(transformation: Transformation) -> tiny_skia::Transform {
tiny_skia::Transform { tiny_skia::Transform {
sx: transformation.scale_x(), sx: transformation.scale_factor(),
kx: 0.0, kx: 0.0,
ky: 0.0, ky: 0.0,
sy: transformation.scale_y(), sy: transformation.scale_factor(),
tx: transformation.translation_x(), tx: transformation.translation_x(),
ty: transformation.translation_y(), ty: transformation.translation_y(),
} }

View file

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

View file

@ -133,7 +133,7 @@ impl<'a> Layer<'a> {
position: *position * transformation, position: *position * transformation,
color: *color, color: *color,
clip_bounds: *clip_bounds * transformation, clip_bounds: *clip_bounds * transformation,
scale: transformation.scale_y(), scale: transformation.scale_factor(),
}); });
} }
Primitive::Editor { Primitive::Editor {
@ -149,7 +149,7 @@ impl<'a> Layer<'a> {
position: *position * transformation, position: *position * transformation,
color: *color, color: *color,
clip_bounds: *clip_bounds * transformation, clip_bounds: *clip_bounds * transformation,
scale: transformation.scale_y(), scale: transformation.scale_factor(),
}); });
} }
Primitive::Text { Primitive::Text {
@ -169,7 +169,7 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Cached(text::Cached { layer.text.push(Text::Cached(text::Cached {
content, content,
bounds: *bounds * transformation, bounds: *bounds * transformation,
size: *size * transformation.scale_y(), size: *size * transformation.scale_factor(),
line_height: *line_height, line_height: *line_height,
color: *color, color: *color,
font: *font, font: *font,