From c44e18556243f8bd56b7f54263f1150ba2e1f792 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 19 Sep 2016 22:28:28 +1000 Subject: [PATCH] Don't use vector for size Former-commit-id: a4b056b61f435be685095b94fb974d8d72bebabe Former-commit-id: 864f967d8b120a0292172c867f2e07a2a39799e0 Former-commit-id: d79cddcc4b6280d8f95bbf1a629c38d7f272738d --- src/ImageProcessorCore/Numerics/Size.cs | 76 ++++++------------------- 1 file changed, 17 insertions(+), 59 deletions(-) diff --git a/src/ImageProcessorCore/Numerics/Size.cs b/src/ImageProcessorCore/Numerics/Size.cs index 4b416b2182..d03dbbb9af 100644 --- a/src/ImageProcessorCore/Numerics/Size.cs +++ b/src/ImageProcessorCore/Numerics/Size.cs @@ -7,7 +7,7 @@ namespace ImageProcessorCore { using System; using System.ComponentModel; - using System.Numerics; + using System.Runtime.CompilerServices; /// /// Stores an ordered pair of integers, which specify a height and width. @@ -23,11 +23,6 @@ namespace ImageProcessorCore /// public static readonly Size Empty = default(Size); - /// - /// The backing vector for SIMD support. - /// - private Vector2 backingVector; - /// /// Initializes a new instance of the struct. /// @@ -35,51 +30,19 @@ namespace ImageProcessorCore /// The height of the size. public Size(int width, int height) { - this.backingVector = new Vector2(width, height); + this.Width = width; + this.Height = height; } /// - /// Initializes a new instance of the struct. + /// Gets or sets the width of this . /// - /// - /// The vector representing the width and height. - /// - public Size(Vector2 vector) - { - this.backingVector = new Vector2(vector.X, vector.Y); - } + public int Width { get; set; } /// - /// The width of this . + /// Gets or sets the height of this . /// - public int Width - { - get - { - return (int)this.backingVector.X; - } - - set - { - this.backingVector.X = value; - } - } - - /// - /// The height of this . - /// - public int Height - { - get - { - return (int)this.backingVector.Y; - } - - set - { - this.backingVector.Y = value; - } - } + public int Height { get; set; } /// /// Gets a value indicating whether this is empty. @@ -95,9 +58,10 @@ namespace ImageProcessorCore /// /// The /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Size operator +(Size left, Size right) { - return new Size(left.backingVector + right.backingVector); + return new Size(left.Width + right.Width, left.Height + right.Height); } /// @@ -108,9 +72,10 @@ namespace ImageProcessorCore /// /// The /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Size operator -(Size left, Size right) { - return new Size(left.backingVector - right.backingVector); + return new Size(left.Width - right.Width, left.Height - right.Height); } /// @@ -125,6 +90,7 @@ namespace ImageProcessorCore /// /// True if the current left is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Size left, Size right) { return left.Equals(right); @@ -142,20 +108,12 @@ namespace ImageProcessorCore /// /// True if the current left is unequal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Size left, Size right) { return !left.Equals(right); } - /// - /// Gets a representation for this . - /// - /// A representation for this object. - public Vector2 ToVector2() - { - return new Vector2(this.Width, this.Height); - } - /// public override int GetHashCode() { @@ -170,11 +128,11 @@ namespace ImageProcessorCore return "Size [ Empty ]"; } - return - $"Size [ Width={this.Width}, Height={this.Height} ]"; + return $"Size [ Width={this.Width}, Height={this.Height} ]"; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { if (obj is Size) @@ -188,7 +146,7 @@ namespace ImageProcessorCore /// public bool Equals(Size other) { - return this.backingVector.Equals(other.backingVector); + return this.Width == other.Width && this.Height == other.Height; } /// @@ -202,7 +160,7 @@ namespace ImageProcessorCore /// private int GetHashCode(Size size) { - return size.backingVector.GetHashCode(); + return size.Width ^ size.Height; } } }