Skip to content

Commit 8863b69

Browse files
committed
Revert "Botched the math last time... Fix that and add tests to make sure it works."
Since it contains breaking change to plotters-backend, revert at this time and move the commit to the next release branch This reverts commit 715dd7a.
1 parent 3719bd8 commit 8863b69

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

plotters-backend/src/text.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,10 @@ impl FontTransform {
151151
FontTransform::Rotate90 => (-y, x),
152152
FontTransform::Rotate180 => (-x, -y),
153153
FontTransform::Rotate270 => (y, -x),
154-
FontTransform::RotateAngle(angle) => {
155-
let (x, y) = (x as f32, y as f32);
156-
let (sin, cos) = angle.to_radians().sin_cos();
157-
let (x, y) = (x * cos - y * sin, x * sin + y * cos);
158-
(x.round() as i32, y.round() as i32)
159-
}
154+
FontTransform::RotateAngle(angle) => (
155+
((x as f32) * angle.cos()).round() as i32,
156+
((y as f32) * angle.sin()).round() as i32,
157+
),
160158
}
161159
}
162160
}
@@ -251,19 +249,3 @@ pub trait BackendTextStyle {
251249
draw: DrawFunc,
252250
) -> Result<Result<(), E>, Self::FontError>;
253251
}
254-
255-
#[cfg(test)]
256-
mod tests {
257-
use crate::FontTransform;
258-
259-
#[test]
260-
fn text_rotation_works() {
261-
assert_eq!(FontTransform::None.transform(1, 0), (1, 0));
262-
assert_eq!(FontTransform::Rotate90.transform(1, 0), (0, 1));
263-
assert_eq!(FontTransform::Rotate180.transform(1, 0), (-1, 0));
264-
assert_eq!(FontTransform::Rotate270.transform(1, 0), (0, -1));
265-
266-
assert_eq!(FontTransform::RotateAngle(45f32).transform(10, 0), (7, 7));
267-
assert_eq!(FontTransform::RotateAngle(45f32).transform(0, 10), (-7, 7));
268-
}
269-
}

0 commit comments

Comments
 (0)