From 90dff77ca3a0112dc47eb6e2355555054bdc00a5 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Fri, 9 Jun 2017 20:18:25 +0100 Subject: [PATCH] [SL.Core] add multiplication and divide operators to Point --- src/SixLabors.Core/Primitives/Point.cs | 34 +++++++++++++++++++++++++ src/SixLabors.Core/Primitives/PointF.cs | 34 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index 5d37d01a6..f922711aa 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/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); + /// + /// Multiplies by a producing . + /// + /// Multiplier of type . + /// Multiplicand of type . + /// Product of type . + public static Point operator *(int left, Point right) => Multiply(right, left); + + /// + /// Multiplies by a producing . + /// + /// Multiplicand of type . + /// Multiplier of type . + /// Product of type . + public static Point operator *(Point left, int right) => Multiply(left, right); + + /// + /// Divides by a producing . + /// + /// Dividend of type . + /// Divisor of type . + /// Result of type . + public static Point operator /(Point left, int right) + => new Point(left.X / right, left.Y / right); + /// /// Compares two objects for equality. /// @@ -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)); + /// + /// Translates a by the negative of a given value + /// + /// The point on the left hand of the operand. + /// The size on the right hand of the operand. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Point Multiply(Point point, int value) => new Point(unchecked(point.X * value), unchecked(point.Y * value)); + /// /// Translates a by the negative of a given . /// diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index ca011483e..032ba6726 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/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); + /// + /// Multiplies by a producing . + /// + /// Multiplier of type . + /// Multiplicand of type . + /// Product of type . + public static PointF operator *(float left, PointF right) => Multiply(right, left); + + /// + /// Multiplies by a producing . + /// + /// Multiplicand of type . + /// Multiplier of type . + /// Product of type . + public static PointF operator *(PointF left, float right) => Multiply(left, right); + + /// + /// Divides by a producing . + /// + /// Dividend of type . + /// Divisor of type . + /// Result of type . + public static PointF operator /(PointF left, float right) + => new PointF(left.X / right, left.Y / right); + /// /// Compares two objects for equality. /// @@ -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); /// + /// Translates a by the multiplying the X and Y by the given value. + /// + /// The point on the left hand of the operand. + /// The value on the right hand of the operand. + /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static PointF Multiply(PointF point, float right) => new PointF(point.X * right, point.Y * right); + + /// PointF /// Rotates a point around the given rotation matrix. /// /// The point to rotate