Browse Source

fix nits.

pull/3948/head
Dan Walmsley 6 years ago
parent
commit
cbda0e9d95
  1. 14
      src/Avalonia.Visuals/Rect.cs
  2. 4
      src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs
  3. 5
      tests/Avalonia.Visuals.UnitTests/RectTests.cs

14
src/Avalonia.Visuals/Rect.cs

@ -421,7 +421,8 @@ namespace Avalonia
} }
/// <summary> /// <summary>
/// Normalizes the rectangle so both the <see cref="Width"/> and <see cref="Height"/> are positive, without changing the location of the rectangle /// Normalizes the rectangle so both the <see cref="Width"/> and <see
/// cref="Height"/> are positive, without changing the location of the rectangle
/// </summary> /// </summary>
/// <returns>Normalized Rect</returns> /// <returns>Normalized Rect</returns>
/// <remarks> /// <remarks>
@ -431,24 +432,25 @@ namespace Avalonia
{ {
Rect rect = this; Rect rect = this;
if(double.IsNaN(rect.Right) || double.IsNaN(rect.Bottom) || double.IsNaN(rect.X) || double.IsNaN(rect.Y) || double.IsNaN(Height) || double.IsNaN(Width)) if(double.IsNaN(rect.Right) || double.IsNaN(rect.Bottom) ||
double.IsNaN(rect.X) || double.IsNaN(rect.Y) ||
double.IsNaN(Height) || double.IsNaN(Width))
{ {
return Rect.Empty; return Rect.Empty;
} }
if (rect.Width < 0) if (rect.Width < 0)
{ {
var old = X;
var x = X + Width; var x = X + Width;
var width = old - x; var width = X - x;
rect = rect.WithX(x).WithWidth(width); rect = rect.WithX(x).WithWidth(width);
} }
if (rect.Height < 0) if (rect.Height < 0)
{ {
var old = Y;
var y = Y + Height; var y = Y + Height;
var height = old - y; var height = Y - y;
rect = rect.WithY(y).WithHeight(height); rect = rect.WithY(y).WithHeight(height);
} }

4
src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs

@ -11,9 +11,7 @@ namespace Avalonia.Rendering.SceneGraph
{ {
public DrawOperation(Rect bounds, Matrix transform) public DrawOperation(Rect bounds, Matrix transform)
{ {
bounds = bounds.Normalize(); bounds = bounds.Normalize().TransformToAABB(transform);
bounds = bounds.TransformToAABB(transform);
Bounds = new Rect( Bounds = new Rect(
new Point(Math.Floor(bounds.X), Math.Floor(bounds.Y)), new Point(Math.Floor(bounds.X), Math.Floor(bounds.Y)),

5
tests/Avalonia.Visuals.UnitTests/RectTests.cs

@ -47,7 +47,10 @@ namespace Avalonia.Visuals.UnitTests
[Fact] [Fact]
public void Normalize_Should_Make_Invalid_Rects_Empty() public void Normalize_Should_Make_Invalid_Rects_Empty()
{ {
var result = new Rect(double.NegativeInfinity,double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity).Normalize(); var result = new Rect(
double.NegativeInfinity, double.PositiveInfinity,
double.PositiveInfinity, double.PositiveInfinity)
.Normalize();
Assert.Equal(Rect.Empty, result); Assert.Equal(Rect.Empty, result);
} }

Loading…
Cancel
Save