Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readonly to members in Rect #10156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -565,7 +565,7 @@ private void AddBounds(ref Rect bounds)
// So, we need to transform the Rect to world to bound it
if (!_transform.IsIdentity)
{
MatrixUtil.TransformRect(ref bounds, ref _transform);
Rect.TransformRect(ref bounds, ref _transform);
}

AddTransformedBounds(ref bounds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -104,7 +104,7 @@ internal override string ConvertToString(string format, IFormatProvider provider
internal override void TransformRect(ref Rect rect)
{
Matrix matrix = Matrix;
MatrixUtil.TransformRect(ref rect, ref matrix);
Rect.TransformRect(ref rect, ref matrix);
}

internal override void MultiplyValueByMatrix(ref Matrix result, ref Matrix matrixToMultiplyBy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -66,7 +66,7 @@ private static Transform MakeIdentityTransform()
internal virtual void TransformRect(ref Rect rect)
{
Matrix matrix = Value;
MatrixUtil.TransformRect(ref rect, ref matrix);
Rect.TransformRect(ref rect, ref matrix);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -577,7 +577,7 @@ private Rect CalculateSubgraphBoundsOuterSpace(bool renderBounds)
if ((transform != null) && (!transform.IsIdentity))
{
Matrix m = transform.Value;
MatrixUtil.TransformRect(ref bboxSubgraph, ref m);
Rect.TransformRect(ref bboxSubgraph, ref m);
}

// Apply Offset.
Expand Down Expand Up @@ -1109,7 +1109,7 @@ internal void PrecomputeRecursive(out Rect bboxSubgraph)
if ((transform != null) && (!transform.IsIdentity))
{
Matrix m = transform.Value;
MatrixUtil.TransformRect(ref bboxSubgraph, ref m);
Rect.TransformRect(ref bboxSubgraph, ref m);
}

if (!bboxSubgraph.IsEmpty)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -577,7 +577,7 @@ internal override Rect CalculateSubgraphBoundsInnerSpace(bool renderBounds)
Matrix3D viewProjMatrix = camera.GetViewMatrix() * camera.GetProjectionMatrix(aspectRatio);
Rect projectedBounds2D = MILUtilities.ProjectBounds(ref viewProjMatrix, ref _bboxChildrenSubgraph3D);
Matrix homoToLocal = M3DUtil.GetHomogeneousToViewportTransform(viewport);
MatrixUtil.TransformRect(ref projectedBounds2D, ref homoToLocal);
Rect.TransformRect(ref projectedBounds2D, ref homoToLocal);

return projectedBounds2D;
}
Expand Down
74 changes: 1 addition & 73 deletions src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/MatrixUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -22,78 +22,6 @@ internal enum MatrixTypes

internal static class MatrixUtil
{
/// <summary>
/// TransformRect - Internal helper for perf
/// </summary>
/// <param name="rect"> The Rect to transform. </param>
/// <param name="matrix"> The Matrix with which to transform the Rect. </param>
internal static void TransformRect(ref Rect rect, ref Matrix matrix)
{
if (rect.IsEmpty)
{
return;
}

MatrixTypes matrixType = matrix._type;

// If the matrix is identity, don't worry.
if (matrixType == MatrixTypes.TRANSFORM_IS_IDENTITY)
{
return;
}

// Scaling
if (0 != (matrixType & MatrixTypes.TRANSFORM_IS_SCALING))
{
rect._x *= matrix._m11;
rect._y *= matrix._m22;
rect._width *= matrix._m11;
rect._height *= matrix._m22;

// Ensure the width is always positive. For example, if there was a reflection about the
// y axis followed by a translation into the visual area, the width could be negative.
if (rect._width < 0.0)
{
rect._x += rect._width;
rect._width = -rect._width;
}

// Ensure the height is always positive. For example, if there was a reflection about the
// x axis followed by a translation into the visual area, the height could be negative.
if (rect._height < 0.0)
{
rect._y += rect._height;
rect._height = -rect._height;
}
}

// Translation
if (0 != (matrixType & MatrixTypes.TRANSFORM_IS_TRANSLATION))
{
// X
rect._x += matrix._offsetX;

// Y
rect._y += matrix._offsetY;
}

if (matrixType == MatrixTypes.TRANSFORM_IS_UNKNOWN)
{
// Al Bunny implementation.
Point point0 = matrix.Transform(rect.TopLeft);
Point point1 = matrix.Transform(rect.TopRight);
Point point2 = matrix.Transform(rect.BottomRight);
Point point3 = matrix.Transform(rect.BottomLeft);

// Width and height is always positive here.
rect._x = Math.Min(Math.Min(point0.X, point1.X), Math.Min(point2.X, point3.X));
rect._y = Math.Min(Math.Min(point0.Y, point1.Y), Math.Min(point2.Y, point3.Y));

rect._width = Math.Max(Math.Max(point0.X, point1.X), Math.Max(point2.X, point3.X)) - rect._x;
rect._height = Math.Max(Math.Max(point0.Y, point1.Y), Math.Max(point2.Y, point3.Y)) - rect._y;
}
}

/// <summary>
/// Multiplies two transformations, where the behavior is matrix1 *= matrix2.
/// This code exists so that we can efficient combine matrices without copying
Expand Down
Loading