Browse Source

[SL.Core] add multiplication and divide operators to Point

pull/1087/head
Scott Williams 9 years ago
parent
commit
90dff77ca3
  1. 34
      src/SixLabors.Core/Primitives/Point.cs
  2. 34
      src/SixLabors.Core/Primitives/PointF.cs

34
src/SixLabors.Core/Primitives/Point.cs

@ -127,6 +127,31 @@ namespace SixLabors.Primitives
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point operator -(Point point, Size size) => Subtract(point, size);
/// <summary>
/// Multiplies <see cref="Point"/> by a <see cref="int"/> producing <see cref="Point"/>.
/// </summary>
/// <param name="left">Multiplier of type <see cref="int"/>.</param>
/// <param name="right">Multiplicand of type <see cref="Point"/>.</param>
/// <returns>Product of type <see cref="Point"/>.</returns>
public static Point operator *(int left, Point right) => Multiply(right, left);
/// <summary>
/// Multiplies <see cref="Point"/> by a <see cref="int"/> producing <see cref="Point"/>.
/// </summary>
/// <param name="left">Multiplicand of type <see cref="Point"/>.</param>
/// <param name="right">Multiplier of type <see cref="int"/>.</param>
/// <returns>Product of type <see cref="Point"/>.</returns>
public static Point operator *(Point left, int right) => Multiply(left, right);
/// <summary>
/// Divides <see cref="Point"/> by a <see cref="int"/> producing <see cref="Point"/>.
/// </summary>
/// <param name="left">Dividend of type <see cref="Point"/>.</param>
/// <param name="right">Divisor of type <see cref="int"/>.</param>
/// <returns>Result of type <see cref="Point"/>.</returns>
public static Point operator /(Point left, int right)
=> new Point(left.X / right, left.Y / right);
/// <summary>
/// Compares two <see cref="Point"/> objects for equality.
/// </summary>
@ -158,6 +183,15 @@ namespace SixLabors.Primitives
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point Add(Point point, Size size) => new Point(unchecked(point.X + size.Width), unchecked(point.Y + size.Height));
/// <summary>
/// Translates a <see cref="Point"/> by the negative of a given value
/// </summary>
/// <param name="point">The point on the left hand of the operand.</param>
/// <param name="size">The size on the right hand of the operand.</param>
/// <returns>The <see cref="Point"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point Multiply(Point point, int value) => new Point(unchecked(point.X * value), unchecked(point.Y * value));
/// <summary>
/// Translates a <see cref="Point"/> by the negative of a given <see cref="Size"/>.
/// </summary>

34
src/SixLabors.Core/Primitives/PointF.cs

@ -145,6 +145,31 @@ namespace SixLabors.Primitives
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PointF operator -(PointF point, SizeF size) => Subtract(point, size);
/// <summary>
/// Multiplies <see cref="PointF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.
/// </summary>
/// <param name="left">Multiplier of type <see cref="float"/>.</param>
/// <param name="right">Multiplicand of type <see cref="SizeF"/>.</param>
/// <returns>Product of type <see cref="SizeF"/>.</returns>
public static PointF operator *(float left, PointF right) => Multiply(right, left);
/// <summary>
/// Multiplies <see cref="PointF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.
/// </summary>
/// <param name="left">Multiplicand of type <see cref="PointF"/>.</param>
/// <param name="right">Multiplier of type <see cref="float"/>.</param>
/// <returns>Product of type <see cref="SizeF"/>.</returns>
public static PointF operator *(PointF left, float right) => Multiply(left, right);
/// <summary>
/// Divides <see cref="PointF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.
/// </summary>
/// <param name="left">Dividend of type <see cref="PointF"/>.</param>
/// <param name="right">Divisor of type <see cref="int"/>.</param>
/// <returns>Result of type <see cref="PointF"/>.</returns>
public static PointF operator /(PointF left, float right)
=> new PointF(left.X / right, left.Y / right);
/// <summary>
/// Compares two <see cref="PointF"/> objects for equality.
/// </summary>
@ -212,6 +237,15 @@ namespace SixLabors.Primitives
public static PointF Subtract(PointF point, PointF pointb) => new PointF(point.X - pointb.X, point.Y - pointb.Y);
/// <summary>
/// Translates a <see cref="PointF"/> by the multiplying the X and Y by the given value.
/// </summary>
/// <param name="point">The point on the left hand of the operand.</param>
/// <param name="right">The value on the right hand of the operand.</param>
/// <returns>The <see cref="PointF"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PointF Multiply(PointF point, float right) => new PointF(point.X * right, point.Y * right);
/// <summary>PointF
/// Rotates a point around the given rotation matrix.
/// </summary>
/// <param name="point">The point to rotate</param>

Loading…
Cancel
Save