Fix affine transform logic

このコミットが含まれているのは:
Sergio Pedri committed 2022-09-06 02:32:57 +02:00
1 親 46828b62da
コミット a152f9322e
2ファイル変更
+19 -11

検索条件に一致するファイルはありません

+14 -8
ファイルの表示
@@ -88,16 +88,22 @@ internal sealed class D2D1AffineTransformMapperFactory<T> : D2D1TransformMapperF
Point64 bottomRight = new(rectangle.Right, rectangle.Bottom);
// Transform them with the current matrix
topLeft.Transform(in matrix);
topRight.Transform(in matrix);
bottomLeft.Transform(in matrix);
bottomRight.Transform(in matrix);
var transformedTopLeft = topLeft.Transform(in matrix);
var transformedTopRight = topRight.Transform(in matrix);
var transformedBottomLeft = bottomLeft.Transform(in matrix);
var transformedBottomRight = bottomRight.Transform(in matrix);
// Calculate the bounding box of the transformed points
long x = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
long y = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
long width = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X)) - rectangle.Left;
long height = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y)) - rectangle.Top;
double left = Math.Min(Math.Min(transformedTopLeft.X, transformedTopRight.X), Math.Min(transformedBottomLeft.X, transformedBottomRight.X));
double top = Math.Min(Math.Min(transformedTopLeft.Y, transformedTopRight.Y), Math.Min(transformedBottomLeft.Y, transformedBottomRight.Y));
double right = Math.Max(Math.Max(transformedTopLeft.X, transformedTopRight.X), Math.Max(transformedBottomLeft.X, transformedBottomRight.X));
double bottom = Math.Max(Math.Max(transformedTopLeft.Y, transformedTopRight.Y), Math.Max(transformedBottomLeft.Y, transformedBottomRight.Y));
// Round each coordinate as needed and compute the rectangle bounds
long x = (long)Math.Floor(left);
long y = (long)Math.Floor(top);
long width = (long)Math.Ceiling(right) - x;
long height = (long)Math.Ceiling(bottom) - y;
rectangle = new(x, y, width, height);
}
+5 -3
ファイルの表示
@@ -53,7 +53,8 @@ internal struct Point64
/// Transforms the current point using an input matrix.
/// </summary>
/// <param name="matrix">The transformation matrix to use.</param>
public void Transform(in Matrix3x2 matrix)
/// <returns>The transformed points, with no rounding.</returns>
public (double X, double Y) Transform(in Matrix3x2 matrix)
{
// A 3x2 transformation matrix can be thought of a 2x2 matrix with an extra
// 1x2 row representing absolute offsets. As such, these do not compute into
@@ -75,7 +76,8 @@ internal struct Point64
// [ M11, M12 ]
// [ M21, M22 ]
// [ x, y] [ M31, M32 ] = [ x * M11 + y * M21 + M31, x * M12 + y * M22 + m32]
this.x = (long)Math.Round(this.x * matrix.M11 + this.y * matrix.M21 + matrix.M31);
this.y = (long)Math.Round(this.x * matrix.M12 + this.y * matrix.M22 + matrix.M32);
return (
Math.Round((double)this.x * matrix.M11 + (double)this.y * matrix.M21 + matrix.M31),
Math.Round((double)this.x * matrix.M12 + (double)this.y * matrix.M22 + matrix.M32));
}
}