Browse Source

[SL.Core] Make deg - rad conversion public

pull/1087/head
James Jackson-South 7 years ago
parent
commit
bc0e521265
  1. 14
      src/SixLabors.Core/GeometryUtilities.cs
  2. 1
      src/SixLabors.Core/Helpers/HashHelpers.cs
  3. 8
      src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs
  4. 1
      src/SixLabors.Core/Primitives/Rectangle.cs
  5. 19
      tests/SixLabors.Core.Tests/Helpers/GeometryUtilitiesTests.cs
  6. 13
      tests/SixLabors.Core.Tests/Helpers/MathFTests.cs

14
src/SixLabors.Core/MathFExtensions.cs → src/SixLabors.Core/GeometryUtilities.cs

@ -7,9 +7,9 @@ using System.Runtime.CompilerServices;
namespace SixLabors
{
/// <summary>
/// Provides common mathematical methods.
/// Utility class for common geometric functions.
/// </summary>
internal static class MathFExtensions
public static class GeometryUtilities
{
/// <summary>
/// Converts a degree (360-periodic) angle to a radian (2*Pi-periodic) angle.
@ -19,10 +19,7 @@ namespace SixLabors
/// The <see cref="float"/> representing the degree as radians.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float DegreeToRadian(float degree)
{
return degree * (MathF.PI / 180F);
}
public static float DegreeToRadian(float degree) => degree * (MathF.PI / 180F);
/// <summary>
/// Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle.
@ -32,9 +29,6 @@ namespace SixLabors
/// The <see cref="float"/> representing the degree as radians.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float RadianToDegree(float radian)
{
return radian / (MathF.PI / 180F);
}
public static float RadianToDegree(float radian) => radian / (MathF.PI / 180F);
}
}

1
src/SixLabors.Core/Helpers/HashHelpers.cs

@ -17,7 +17,6 @@ namespace SixLabors
public static int Combine(int h1, int h2)
{
// Lifted from coreFX repo
unchecked
{
// RyuJIT optimizes this to use the ROL instruction

8
src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs

@ -55,7 +55,7 @@ namespace SixLabors.Primitives
/// <param name="degreesX">The X angle, in degrees.</param>
/// <param name="degreesY">The Y angle, in degrees.</param>
/// <returns>A skew matrix.</returns>
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY));
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY));
/// <summary>
/// Creates a skew matrix from the given angles in radians and a center point.
@ -73,14 +73,14 @@ namespace SixLabors.Primitives
/// <param name="degreesY">The Y angle, in degrees.</param>
/// <param name="centerPoint">The center point.</param>
/// <returns>A skew matrix.</returns>
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY), centerPoint);
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), centerPoint);
/// <summary>
/// Creates a rotation matrix using the given rotation in degrees.
/// </summary>
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <returns>A rotation matrix.</returns>
public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees));
public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees));
/// <summary>
/// Creates a rotation matrix using the given rotation in radians and a center point.
@ -96,6 +96,6 @@ namespace SixLabors.Primitives
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <param name="centerPoint">The center point.</param>
/// <returns>A rotation matrix.</returns>
public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees), centerPoint);
public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees), centerPoint);
}
}

1
src/SixLabors.Core/Primitives/Rectangle.cs

@ -135,7 +135,6 @@ namespace SixLabors.Primitives
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => unchecked(this.Y + this.Height);
}
/// <summary>

19
tests/SixLabors.Core.Tests/Helpers/GeometryUtilitiesTests.cs

@ -0,0 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using Xunit;
namespace SixLabors.Tests.Helpers
{
public class GeometryUtilitiesTests
{
[Fact]
public void Convert_Degree_To_Radian()
=> Assert.Equal((float)(Math.PI / 2D), GeometryUtilities.DegreeToRadian(90F), new FloatRoundingComparer(6));
[Fact]
public void Convert_Radian_To_Degree()
=> Assert.Equal(60F, GeometryUtilities.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
}
}

13
tests/SixLabors.Core.Tests/Helpers/MathFTests.cs

@ -6,7 +6,6 @@ using Xunit;
namespace SixLabors.Tests.Helpers
{
public class MathFTests
{
[Fact]
@ -92,17 +91,5 @@ namespace SixLabors.Tests.Helpers
{
Assert.Equal(MathF.Sqrt(2F), (float)Math.Sqrt(2F));
}
[Fact]
public void Convert_Degree_To_Radian()
{
Assert.Equal((float)(Math.PI / 2D), MathFExtensions.DegreeToRadian(90F), new FloatRoundingComparer(6));
}
[Fact]
public void Convert_Radian_To_Degree()
{
Assert.Equal(60F, MathFExtensions.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
}
}
}
Loading…
Cancel
Save