Browse Source

Added AspectRatio and division operator to Size.

pull/915/head
Steven Kirk 9 years ago
parent
commit
609c571424
  1. 16
      src/Avalonia.Visuals/Size.cs
  2. 1
      tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj
  3. 26
      tests/Avalonia.Visuals.UnitTests/SizeTests.cs

16
src/Avalonia.Visuals/Size.cs

@ -43,6 +43,11 @@ namespace Avalonia
_height = height;
}
/// <summary>
/// Gets the aspect ratio of the size.
/// </summary>
public double AspectRatio => _width / _height;
/// <summary>
/// Gets the width.
/// </summary>
@ -97,6 +102,17 @@ namespace Avalonia
return new Size(size._width / scale.X, size._height / scale.Y);
}
/// <summary>
/// Divides a size by another size to produce a scaling factor.
/// </summary>
/// <param name="left">The first size</param>
/// <param name="right">The second size.</param>
/// <returns>The scaled size.</returns>
public static Vector operator /(Size left, Size right)
{
return new Vector(left._width / right._width, left._height / right._height);
}
/// <summary>
/// Scales a size.
/// </summary>

1
tests/Avalonia.Visuals.UnitTests/Avalonia.Visuals.UnitTests.csproj

@ -80,6 +80,7 @@
<Compile Include="Media\FormattedTextTests.cs" />
<Compile Include="Media\PathMarkupParserTests.cs" />
<Compile Include="RelativeRectComparer.cs" />
<Compile Include="SizeTests.cs" />
<Compile Include="RelativeRectTests.cs" />
<Compile Include="ThicknessTests.cs" />
<Compile Include="Media\BrushTests.cs" />

26
tests/Avalonia.Visuals.UnitTests/SizeTests.cs

@ -0,0 +1,26 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Xunit;
namespace Avalonia.Visuals.UnitTests
{
public class SizeTests
{
[Fact]
public void Should_Produce_Correct_Aspect_Ratio()
{
var result = new Size(3, 2).AspectRatio;
Assert.Equal(1.5, result);
}
[Fact]
public void Dividing_Should_Produce_Scaling_Factor()
{
var result = new Size(15, 10) / new Size(5, 5);
Assert.Equal(new Vector(3, 2), result);
}
}
}
Loading…
Cancel
Save