@@ -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