Browse Source

[SL.Core] Merge branch 'master' of https://github.com/SixLabors/Primitives

pull/1087/head
Scott Williams 9 years ago
parent
commit
214215bd9d
  1. 30
      src/SixLabors.Primitives/Matrix3x2Extensions.cs
  2. 4
      tests/SixLabors.Primitives.Tests/PointFTests.cs
  3. 4
      tests/SixLabors.Primitives.Tests/PointTests.cs

30
src/SixLabors.Primitives/Matrix3x2Extentions.cs → src/SixLabors.Primitives/Matrix3x2Extensions.cs

@ -1,25 +1,23 @@
// <copyright file="Matrix.cs" company="Six Labors">
// <copyright file="Matrix3x2Extensions.cs" company="Six Labors">
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.Primitives
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// A Matrix object for applying matrix transforms to primitives.
/// Extension methods for the <see cref="Matrix3x2"/> struct.
/// </summary>
public static class Matrix3x2Extentions
public static class Matrix3x2Extensions
{
/// <summary>
/// Creates a translation matrix from the given vector.
/// </summary>
/// <param name="position">The translation position.</param>
/// <returns>A translation matrix.</returns>
public static Matrix3x2 CreateTranslation(PointF position) => System.Numerics.Matrix3x2.CreateTranslation(position);
public static Matrix3x2 CreateTranslation(PointF position) => Matrix3x2.CreateTranslation(position);
/// <summary>
/// Creates a scale matrix that is offset by a given center point.
@ -28,14 +26,14 @@ namespace SixLabors.Primitives
/// <param name="yScale">Value to scale by on the Y-axis.</param>
/// <param name="centerPoint">The center point.</param>
/// <returns>A scaling matrix.</returns>
public static Matrix3x2 CreateScale(float xScale, float yScale, PointF centerPoint) => System.Numerics.Matrix3x2.CreateScale(xScale, yScale, centerPoint);
public static Matrix3x2 CreateScale(float xScale, float yScale, PointF centerPoint) => Matrix3x2.CreateScale(xScale, yScale, centerPoint);
/// <summary>
/// Creates a scale matrix from the given vector scale.
/// </summary>
/// <param name="scales">The scale to use.</param>
/// <returns>A scaling matrix.</returns>
public static Matrix3x2 CreateScale(SizeF scales) => System.Numerics.Matrix3x2.CreateScale(scales);
public static Matrix3x2 CreateScale(SizeF scales) => Matrix3x2.CreateScale(scales);
/// <summary>
/// Creates a scale matrix from the given vector scale with an offset from the given center point.
@ -43,7 +41,7 @@ namespace SixLabors.Primitives
/// <param name="scales">The scale to use.</param>
/// <param name="centerPoint">The center offset.</param>
/// <returns>A scaling matrix.</returns>
public static Matrix3x2 CreateScale(SizeF scales, PointF centerPoint) => System.Numerics.Matrix3x2.CreateScale(scales, centerPoint);
public static Matrix3x2 CreateScale(SizeF scales, PointF centerPoint) => Matrix3x2.CreateScale(scales, centerPoint);
/// <summary>
/// Creates a scale matrix that scales uniformly with the given scale with an offset from the given center.
@ -51,7 +49,7 @@ namespace SixLabors.Primitives
/// <param name="scale">The uniform scale to use.</param>
/// <param name="centerPoint">The center offset.</param>
/// <returns>A scaling matrix.</returns>
public static Matrix3x2 CreateScale(float scale, PointF centerPoint) => System.Numerics.Matrix3x2.CreateScale(scale, centerPoint);
public static Matrix3x2 CreateScale(float scale, PointF centerPoint) => Matrix3x2.CreateScale(scale, centerPoint);
/// <summary>
/// Creates a skew matrix from the given angles in radians.
@ -59,7 +57,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) => System.Numerics.Matrix3x2.CreateSkew(MathF.ToRadians(degreesX), MathF.ToRadians(degreesY));
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(MathF.ToRadians(degreesX), MathF.ToRadians(degreesY));
/// <summary>
/// Creates a skew matrix from the given angles in radians and a center point.
@ -68,7 +66,7 @@ namespace SixLabors.Primitives
/// <param name="radiansY">The Y angle, in radians.</param>
/// <param name="centerPoint">The center point.</param>
/// <returns>A skew matrix.</returns>
public static Matrix3x2 CreateSkew(float radiansX, float radiansY, PointF centerPoint) => System.Numerics.Matrix3x2.CreateSkew(radiansX, radiansY, centerPoint);
public static Matrix3x2 CreateSkew(float radiansX, float radiansY, PointF centerPoint) => Matrix3x2.CreateSkew(radiansX, radiansY, centerPoint);
/// <summary>
/// Creates a skew matrix from the given angles in radians and a center point.
@ -77,14 +75,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) => System.Numerics.Matrix3x2.CreateSkew(MathF.ToRadians(degreesX), MathF.ToRadians(degreesY), centerPoint);
public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(MathF.ToRadians(degreesX), MathF.ToRadians(degreesY), centerPoint);
/// <summary>
/// Creates a rotation matrix using the given rotation in radians.
/// </summary>
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <returns>A rotation matrix.</returns>
public static Matrix3x2 CreateRotationDegrees(float degrees) => System.Numerics.Matrix3x2.CreateRotation(MathF.ToRadians(degrees));
public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(MathF.ToRadians(degrees));
/// <summary>
/// Creates a rotation matrix using the given rotation in radians and a center point.
@ -92,7 +90,7 @@ namespace SixLabors.Primitives
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="centerPoint">The center point.</param>
/// <returns>A rotation matrix.</returns>
public static Matrix3x2 CreateRotation(float radians, PointF centerPoint) => System.Numerics.Matrix3x2.CreateRotation(radians, centerPoint);
public static Matrix3x2 CreateRotation(float radians, PointF centerPoint) => Matrix3x2.CreateRotation(radians, centerPoint);
/// <summary>
/// Creates a rotation matrix using the given rotation in radians and a center point.
@ -100,6 +98,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) => System.Numerics.Matrix3x2.CreateRotation(MathF.ToRadians(degrees), centerPoint);
public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(MathF.ToRadians(degrees), centerPoint);
}
}

4
tests/SixLabors.Primitives.Tests/PointFTests.cs

@ -106,7 +106,7 @@ namespace SixLabors.Primitives.Tests
public void RotateTest()
{
var p = new PointF(13, 17);
Matrix3x2 matrix = Matrix3x2Extentions.CreateRotationDegrees(45, PointF.Empty);
Matrix3x2 matrix = Matrix3x2Extensions.CreateRotationDegrees(45, PointF.Empty);
var pout = PointF.Rotate(p, matrix);
@ -117,7 +117,7 @@ namespace SixLabors.Primitives.Tests
public void SkewTest()
{
var p = new PointF(13, 17);
Matrix3x2 matrix = Matrix3x2Extentions.CreateSkewDegrees(45, 45, PointF.Empty);
Matrix3x2 matrix = Matrix3x2Extensions.CreateSkewDegrees(45, 45, PointF.Empty);
var pout = PointF.Skew(p, matrix);
Assert.Equal(new PointF(30, 30), pout);

4
tests/SixLabors.Primitives.Tests/PointTests.cs

@ -161,7 +161,7 @@ namespace SixLabors.Primitives.Tests
public void RotateTest()
{
var p = new Point(13, 17);
Matrix3x2 matrix = Matrix3x2Extentions.CreateRotationDegrees(45, Point.Empty);
Matrix3x2 matrix = Matrix3x2Extensions.CreateRotationDegrees(45, Point.Empty);
var pout = Point.Rotate(p, matrix);
@ -172,7 +172,7 @@ namespace SixLabors.Primitives.Tests
public void SkewTest()
{
var p = new Point(13, 17);
Matrix3x2 matrix = Matrix3x2Extentions.CreateSkewDegrees(45, 45, Point.Empty);
Matrix3x2 matrix = Matrix3x2Extensions.CreateSkewDegrees(45, 45, Point.Empty);
var pout = Point.Skew(p, matrix);
Assert.Equal(new Point(30, 30), pout);

Loading…
Cancel
Save