diff --git a/src/ImageProcessorCore/Numerics/Point.cs b/src/ImageProcessorCore/Numerics/Point.cs
index 818002f9e..193caf176 100644
--- a/src/ImageProcessorCore/Numerics/Point.cs
+++ b/src/ImageProcessorCore/Numerics/Point.cs
@@ -2,11 +2,13 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
+
namespace ImageProcessorCore
{
using System;
using System.ComponentModel;
using System.Numerics;
+ using System.Runtime.CompilerServices;
///
/// Represents an ordered pair of integer x- and y-coordinates that defines a point in
@@ -23,11 +25,6 @@ namespace ImageProcessorCore
///
public static readonly Point Empty = default(Point);
- ///
- /// The backing vector for SIMD support.
- ///
- private Vector2 backingVector;
-
///
/// Initializes a new instance of the struct.
///
@@ -36,7 +33,8 @@ namespace ImageProcessorCore
public Point(int x, int y)
: this()
{
- this.backingVector = new Vector2(x, y);
+ this.X = x;
+ this.Y = y;
}
///
@@ -47,40 +45,19 @@ namespace ImageProcessorCore
///
public Point(Vector2 vector)
{
- this.backingVector = new Vector2(vector.X, vector.Y);
+ this.X = (int)Math.Round(vector.X);
+ this.Y = (int)Math.Round(vector.Y);
}
///
- /// The x-coordinate of this .
+ /// Gets or sets the x-coordinate of this .
///
- public int X
- {
- get
- {
- return (int)this.backingVector.X;
- }
-
- set
- {
- this.backingVector.X = value;
- }
- }
+ public int X { get; set; }
///
- /// The y-coordinate of this .
+ /// Gets or sets the y-coordinate of this .
///
- public int Y
- {
- get
- {
- return (int)this.backingVector.Y;
- }
-
- set
- {
- this.backingVector.Y = value;
- }
- }
+ public int Y { get; set; }
///
/// Gets a value indicating whether this is empty.
@@ -96,9 +73,10 @@ namespace ImageProcessorCore
///
/// The
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point operator +(Point left, Point right)
{
- return new Point(left.backingVector + right.backingVector);
+ return new Point(left.X + right.X, left.Y + right.Y);
}
///
@@ -109,9 +87,10 @@ namespace ImageProcessorCore
///
/// The
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Point operator -(Point left, Point right)
{
- return new Point(left.backingVector - right.backingVector);
+ return new Point(left.X - right.X, left.Y - right.Y);
}
///
@@ -126,6 +105,7 @@ namespace ImageProcessorCore
///
/// True if the current left is equal to the parameter; otherwise, false.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Point left, Point right)
{
return left.Equals(right);
@@ -143,20 +123,12 @@ namespace ImageProcessorCore
///
/// True if the current left is unequal to the parameter; otherwise, false.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Point left, Point right)
{
return !left.Equals(right);
}
- ///
- /// Gets a representation for this .
- ///
- /// A representation for this object.
- public Vector2 ToVector2()
- {
- return new Vector2(this.X, this.Y);
- }
-
///
/// Creates a rotation matrix for the given point and angle.
///
@@ -166,7 +138,7 @@ namespace ImageProcessorCore
public static Matrix3x2 CreateRotation(Point origin, float degrees)
{
float radians = ImageMaths.DegreesToRadians(degrees);
- return Matrix3x2.CreateRotation(radians, origin.backingVector);
+ return Matrix3x2.CreateRotation(radians, new Vector2(origin.X, origin.Y));
}
///
@@ -177,7 +149,7 @@ namespace ImageProcessorCore
/// The rotated
public static Point Rotate(Point point, Matrix3x2 rotation)
{
- return new Point(Vector2.Transform(point.backingVector, rotation));
+ return new Point(Vector2.Transform(new Vector2(point.X, point.Y), rotation));
}
///
@@ -189,7 +161,7 @@ namespace ImageProcessorCore
/// The rotated
public static Point Rotate(Point point, Point origin, float degrees)
{
- return new Point(Vector2.Transform(point.backingVector, CreateRotation(origin, degrees)));
+ return new Point(Vector2.Transform(new Vector2(point.X, point.Y), CreateRotation(origin, degrees)));
}
///
@@ -203,7 +175,7 @@ namespace ImageProcessorCore
{
float radiansX = ImageMaths.DegreesToRadians(degreesX);
float radiansY = ImageMaths.DegreesToRadians(degreesY);
- return Matrix3x2.CreateSkew(radiansX, radiansY, origin.backingVector);
+ return Matrix3x2.CreateSkew(radiansX, radiansY, new Vector2(origin.X, origin.Y));
}
///
@@ -214,7 +186,7 @@ namespace ImageProcessorCore
/// The rotated
public static Point Skew(Point point, Matrix3x2 skew)
{
- return new Point(Vector2.Transform(point.backingVector, skew));
+ return new Point(Vector2.Transform(new Vector2(point.X, point.Y), skew));
}
///
@@ -227,7 +199,36 @@ namespace ImageProcessorCore
/// The skewed
public static Point Skew(Point point, Point origin, float degreesX, float degreesY)
{
- return new Point(Vector2.Transform(point.backingVector, CreateSkew(origin, degreesX, degreesY)));
+ return new Point(Vector2.Transform(new Vector2(point.X, point.Y), CreateSkew(origin, degreesX, degreesY)));
+ }
+
+ ///
+ /// Gets a representation for this .
+ ///
+ /// A representation for this object.
+ public Vector2 ToVector2()
+ {
+ return new Vector2(this.X, this.Y);
+ }
+
+ ///
+ /// Translates this by the specified amount.
+ ///
+ /// The amount to offset the x-coordinate.
+ /// The amount to offset the y-coordinate.
+ public void Offset(int dx, int dy)
+ {
+ this.X += dx;
+ this.Y += dy;
+ }
+
+ ///
+ /// Translates this by the specified amount.
+ ///
+ /// The used offset this .
+ public void Offset(Point p)
+ {
+ this.Offset(p.X, p.Y);
}
///
@@ -261,7 +262,7 @@ namespace ImageProcessorCore
///
public bool Equals(Point other)
{
- return this.backingVector.Equals(other.backingVector);
+ return this.X == other.X && this.Y == other.Y;
}
///
@@ -275,7 +276,7 @@ namespace ImageProcessorCore
///
private int GetHashCode(Point point)
{
- return point.backingVector.GetHashCode();
+ return point.X ^ point.Y;
}
}
-}
+}
\ No newline at end of file