Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.

Commit 8fa14df

Browse files
Make deg - rad conversion public
1 parent 5c32425 commit 8fa14df

6 files changed

Lines changed: 27 additions & 29 deletions

File tree

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace SixLabors
88
{
99
/// <summary>
10-
/// Provides common mathematical methods.
10+
/// Utility class for common geometric functions.
1111
/// </summary>
12-
internal static class MathFExtensions
12+
public static class GeometryUtilities
1313
{
1414
/// <summary>
1515
/// Converts a degree (360-periodic) angle to a radian (2*Pi-periodic) angle.
@@ -19,10 +19,7 @@ internal static class MathFExtensions
1919
/// The <see cref="float"/> representing the degree as radians.
2020
/// </returns>
2121
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22-
public static float DegreeToRadian(float degree)
23-
{
24-
return degree * (MathF.PI / 180F);
25-
}
22+
public static float DegreeToRadian(float degree) => degree * (MathF.PI / 180F);
2623

2724
/// <summary>
2825
/// Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle.
@@ -32,9 +29,6 @@ public static float DegreeToRadian(float degree)
3229
/// The <see cref="float"/> representing the degree as radians.
3330
/// </returns>
3431
[MethodImpl(MethodImplOptions.AggressiveInlining)]
35-
public static float RadianToDegree(float radian)
36-
{
37-
return radian / (MathF.PI / 180F);
38-
}
32+
public static float RadianToDegree(float radian) => radian / (MathF.PI / 180F);
3933
}
4034
}

src/SixLabors.Core/Helpers/HashHelpers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal static class HashHelpers
1717
public static int Combine(int h1, int h2)
1818
{
1919
// Lifted from coreFX repo
20-
2120
unchecked
2221
{
2322
// RyuJIT optimizes this to use the ROL instruction

src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static class Matrix3x2Extensions
5555
/// <param name="degreesX">The X angle, in degrees.</param>
5656
/// <param name="degreesY">The Y angle, in degrees.</param>
5757
/// <returns>A skew matrix.</returns>
58-
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY));
58+
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY));
5959

6060
/// <summary>
6161
/// Creates a skew matrix from the given angles in radians and a center point.
@@ -73,14 +73,14 @@ public static class Matrix3x2Extensions
7373
/// <param name="degreesY">The Y angle, in degrees.</param>
7474
/// <param name="centerPoint">The center point.</param>
7575
/// <returns>A skew matrix.</returns>
76-
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(MathFExtensions.DegreeToRadian(degreesX), MathFExtensions.DegreeToRadian(degreesY), centerPoint);
76+
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), centerPoint);
7777

7878
/// <summary>
7979
/// Creates a rotation matrix using the given rotation in degrees.
8080
/// </summary>
8181
/// <param name="degrees">The amount of rotation, in degrees.</param>
8282
/// <returns>A rotation matrix.</returns>
83-
public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees));
83+
public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees));
8484

8585
/// <summary>
8686
/// Creates a rotation matrix using the given rotation in radians and a center point.
@@ -96,6 +96,6 @@ public static class Matrix3x2Extensions
9696
/// <param name="degrees">The amount of rotation, in degrees.</param>
9797
/// <param name="centerPoint">The center point.</param>
9898
/// <returns>A rotation matrix.</returns>
99-
public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(MathFExtensions.DegreeToRadian(degrees), centerPoint);
99+
public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees), centerPoint);
100100
}
101101
}

src/SixLabors.Core/Primitives/Rectangle.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public int Bottom
135135
{
136136
[MethodImpl(MethodImplOptions.AggressiveInlining)]
137137
get => unchecked(this.Y + this.Height);
138-
139138
}
140139

141140
/// <summary>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using Xunit;
6+
7+
namespace SixLabors.Tests.Helpers
8+
{
9+
public class GeometryUtilitiesTests
10+
{
11+
[Fact]
12+
public void Convert_Degree_To_Radian()
13+
=> Assert.Equal((float)(Math.PI / 2D), GeometryUtilities.DegreeToRadian(90F), new FloatRoundingComparer(6));
14+
15+
[Fact]
16+
public void Convert_Radian_To_Degree()
17+
=> Assert.Equal(60F, GeometryUtilities.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
18+
}
19+
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace SixLabors.Tests.Helpers
88
{
9-
109
public class MathFTests
1110
{
1211
[Fact]
@@ -92,17 +91,5 @@ public void MathF_Sqrt_Is_Equal()
9291
{
9392
Assert.Equal(MathF.Sqrt(2F), (float)Math.Sqrt(2F));
9493
}
95-
96-
[Fact]
97-
public void Convert_Degree_To_Radian()
98-
{
99-
Assert.Equal((float)(Math.PI / 2D), MathFExtensions.DegreeToRadian(90F), new FloatRoundingComparer(6));
100-
}
101-
102-
[Fact]
103-
public void Convert_Radian_To_Degree()
104-
{
105-
Assert.Equal(60F, MathFExtensions.RadianToDegree((float)(Math.PI / 3D)), new FloatRoundingComparer(5));
106-
}
10794
}
10895
}

0 commit comments

Comments
 (0)