Skip to content

Commit 25d67ed

Browse files
dannymcgeetomcur
andauthored
Bugfix: Incorrect ordering for Affine::pre_rotate_about (#567)
Fixes #566 --------- Co-authored-by: Thomas Churchman <thomas@kepow.org>
1 parent d3398c5 commit 25d67ed

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This release has an [MSRV][] of 1.85.
3131
## Fixed
3232

3333
- Improved numerical robustness of winding numbers for paths. ([#537][] by [@jneem][])
34+
- `Affine::pre_rotate_about` calculation. ([#567][] by [@dannymcgee][])
3435

3536
## [0.13.0] (2025-11-27)
3637

@@ -185,6 +186,7 @@ Note: A changelog was not kept for or before this release
185186
[@beholdnec]: https://github.com/beholdnec
186187
[@Bombaninha]: https://github.com/Bombaninha
187188
[@cmyr]: https://github.com/cmyr
189+
[@dannymcgee]: https://github.com/dannymcgee
188190
[@DJMcNab]: https://github.com/DJMcNab
189191
[@dominikh]: https://github.com/dominikh
190192
[@ErisianArchitect]: https://github.com/ErisianArchitect
@@ -291,6 +293,7 @@ Note: A changelog was not kept for or before this release
291293
[#549]: https://github.com/linebender/kurbo/pull/549
292294
[#559]: https://github.com/linebender/kurbo/pull/559
293295
[#561]: https://github.com/linebender/kurbo/pull/561
296+
[#567]: https://github.com/linebender/kurbo/pull/567
294297

295298
[Unreleased]: https://github.com/linebender/kurbo/compare/v0.13.0...HEAD
296299
[0.13.0]: https://github.com/linebender/kurbo/releases/tag/v0.13.0

kurbo/src/affine.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Affine {
189189
#[inline]
190190
#[must_use]
191191
pub fn pre_rotate_about(self, th: f64, center: impl Into<Point>) -> Self {
192-
Affine::rotate_about(th, center) * self
192+
self * Affine::rotate_about(th, center)
193193
}
194194

195195
/// A [scale] by `scale` followed by `self`.
@@ -720,4 +720,38 @@ mod tests {
720720
"The product of the singular values {s:?} ({prod}) should be equal to the absolute determinant {det}.",
721721
);
722722
}
723+
724+
#[test]
725+
fn rotate_about_composition() {
726+
let theta = core::f64::consts::FRAC_PI_2;
727+
let center = Point::new(-1., 0.);
728+
let translation = Vec2::new(0., 1.);
729+
let probe = Point::ORIGIN;
730+
731+
let rotate_about = Affine::rotate_about(theta, center);
732+
let translate = Affine::translate(translation);
733+
734+
// Establish baselines with raw matrix composition
735+
// (also a sanity check to ensure the order of ops matters for this contrived test)
736+
let rotate_then_translate = translate * rotate_about;
737+
let translate_then_rotate = rotate_about * translate;
738+
assert_near(rotate_then_translate * probe, Point::new(-1., 2.));
739+
assert_near(translate_then_rotate * probe, Point::new(-2., 1.));
740+
741+
// Check .then_* semantics
742+
affine_assert_near(
743+
rotate_about.then_translate(translation),
744+
rotate_then_translate,
745+
);
746+
affine_assert_near(
747+
translate.then_rotate_about(theta, center),
748+
translate_then_rotate,
749+
);
750+
751+
// Check .pre_rotate_about semantics
752+
affine_assert_near(
753+
translate.pre_rotate_about(theta, center),
754+
rotate_then_translate,
755+
);
756+
}
723757
}

0 commit comments

Comments
 (0)