@@ -140,11 +140,29 @@ internal static UVTransform CalculateDelta(IList<Vector2> src, IList<int> srcInd
140140 Vector2 dstSize = GetRotatedSize ( dst , dstIndices , dstCenter , - rotation ) ;
141141 Bounds2D srcBounds = srcIndices == null ? new Bounds2D ( src ) : new Bounds2D ( src , srcIndices ) ;
142142 Vector2 scale = dstSize . DivideBy ( srcBounds . size ) ;
143- Vector2 srcCenter = srcBounds . center * scale ;
143+
144+ // Calculate new bounds after rotation
145+ Vector2 min = new Vector2 ( float . MaxValue , float . MaxValue ) ;
146+ Vector2 max = new Vector2 ( float . MinValue , float . MinValue ) ;
147+
148+ int count = srcIndices ? . Count ?? src . Count ;
149+ for ( int i = 0 ; i < count ; i ++ )
150+ {
151+ int index = GetIndex ( srcIndices , i ) ;
152+ Vector2 rotated = Math . RotateAroundPoint ( src [ index ] , srcBounds . center , rotation ) ;
153+ min . x = Mathf . Min ( min . x , rotated . x ) ;
154+ min . y = Mathf . Min ( min . y , rotated . y ) ;
155+ max . x = Mathf . Max ( max . x , rotated . x ) ;
156+ max . y = Mathf . Max ( max . y , rotated . y ) ;
157+ }
158+
159+ // Calculate center of rotated bounds, and apply the calculated scale afterwards
160+ Vector2 rotatedCenter = ( min + max ) * 0.5f ;
161+ Vector2 srcTransformedCenter = rotatedCenter * scale ;
144162
145163 return new UVTransform ( )
146164 {
147- translation = dstCenter - srcCenter ,
165+ translation = dstCenter - srcTransformedCenter ,
148166 rotation = rotation ,
149167 scale = dstSize . DivideBy ( srcBounds . size )
150168 } ;
0 commit comments