|
|
|
@ -3,13 +3,13 @@ |
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Numerics; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
namespace SixLabors.Primitives |
|
|
|
{ |
|
|
|
using System; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Numerics; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Stores an ordered pair of integers, which specify a height and width.
|
|
|
|
/// </summary>
|
|
|
|
@ -216,24 +216,6 @@ namespace SixLabors.Primitives |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static Size Subtract(Size left, Size right) => new Size(unchecked(left.Width - right.Width), unchecked(left.Height - right.Height)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies <see cref="Size"/> by an <see cref="int"/> producing <see cref="Size"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">Multiplicand of type <see cref="Size"/>.</param>
|
|
|
|
/// <param name="multiplier">Multiplier of type <see cref='int'>.</param>
|
|
|
|
/// <returns>Product of type <see cref="Size"/>.</returns>
|
|
|
|
private static Size Multiply(Size size, int multiplier) => |
|
|
|
new Size(unchecked(size.Width * multiplier), unchecked(size.Height * multiplier)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies <see cref="Size"/> by a <see cref="float"/> producing <see cref="SizeF"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">Multiplicand of type <see cref="Size"/>.</param>
|
|
|
|
/// <param name="multiplier">Multiplier of type <see cref="float"/>.</param>
|
|
|
|
/// <returns>Product of type SizeF.</returns>
|
|
|
|
private static SizeF Multiply(Size size, float multiplier) => |
|
|
|
new SizeF(size.Width * multiplier, size.Height * multiplier); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Converts a <see cref="SizeF"/> to a <see cref="Size"/> by performing a ceiling operation on all the dimensions.
|
|
|
|
/// </summary>
|
|
|
|
@ -250,6 +232,19 @@ namespace SixLabors.Primitives |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static Size Round(SizeF size) => new Size(unchecked((int)MathF.Round(size.Width)), unchecked((int)MathF.Round(size.Height))); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Transforms a size by the given matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The source size</param>
|
|
|
|
/// <param name="matrix">The transformation matrix.</param>
|
|
|
|
/// <returns>A transformed size.</returns>
|
|
|
|
public static SizeF Transform(Size size, Matrix3x2 matrix) |
|
|
|
{ |
|
|
|
var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); |
|
|
|
|
|
|
|
return new SizeF(v.X, v.Y); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Converts a <see cref="SizeF"/> to a <see cref="Size"/> by performing a round operation on all the dimensions.
|
|
|
|
/// </summary>
|
|
|
|
@ -274,6 +269,24 @@ namespace SixLabors.Primitives |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public bool Equals(Size other) => this.Width == other.Width && this.Height == other.Height; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies <see cref="Size"/> by an <see cref="int"/> producing <see cref="Size"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">Multiplicand of type <see cref="Size"/>.</param>
|
|
|
|
/// <param name="multiplier">Multiplier of type <see cref="int"/>.</param>
|
|
|
|
/// <returns>Product of type <see cref="Size"/>.</returns>
|
|
|
|
private static Size Multiply(Size size, int multiplier) => |
|
|
|
new Size(unchecked(size.Width * multiplier), unchecked(size.Height * multiplier)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Multiplies <see cref="Size"/> by a <see cref="float"/> producing <see cref="SizeF"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">Multiplicand of type <see cref="Size"/>.</param>
|
|
|
|
/// <param name="multiplier">Multiplier of type <see cref="float"/>.</param>
|
|
|
|
/// <returns>Product of type SizeF.</returns>
|
|
|
|
private static SizeF Multiply(Size size, float multiplier) => |
|
|
|
new SizeF(size.Width * multiplier, size.Height * multiplier); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the hash code for this instance.
|
|
|
|
/// </summary>
|
|
|
|
@ -284,18 +297,5 @@ namespace SixLabors.Primitives |
|
|
|
/// A 32-bit signed integer that is the hash code for this instance.
|
|
|
|
/// </returns>
|
|
|
|
private int GetHashCode(Size size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Transforms a size by the given matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The source size</param>
|
|
|
|
/// <param name="matrix">The transformation matrix.</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static SizeF Transform(Size size, Matrix3x2 matrix) |
|
|
|
{ |
|
|
|
var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); |
|
|
|
|
|
|
|
return new SizeF(v.X, v.Y); |
|
|
|
} |
|
|
|
} |
|
|
|
} |