From f8a9b439aa0c72febf4dae1557b9a71994b7b6d8 Mon Sep 17 00:00:00 2001 From: James South Date: Fri, 24 Apr 2015 20:19:01 +0100 Subject: [PATCH] Adding example Point class. Former-commit-id: bef6431b2ad89bc9e7668a84359d0e1aa4cd6662 Former-commit-id: d0d13cb4f20623fcb7681030272271f6157f9445 Former-commit-id: 012b040185e93ec3032cf895e089d0b9ff09295a --- src/ImageProcessor/ImageProcessor.csproj | 3 + src/ImageProcessor/Point.cs | 129 ++++++++++++++++++ src/ImageProcessor/Properties/AssemblyInfo.cs | 2 +- src/ImageProcessor/Settings.StyleCop | 11 ++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/ImageProcessor/Point.cs create mode 100644 src/ImageProcessor/Settings.StyleCop diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 3c9b33550f..8d8c4d70a5 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -38,8 +38,11 @@ + + + diff --git a/src/ImageProcessor/Point.cs b/src/ImageProcessor/Point.cs new file mode 100644 index 0000000000..29d8a9847c --- /dev/null +++ b/src/ImageProcessor/Point.cs @@ -0,0 +1,129 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright © James South and contributors. +// Licensed under the Apache License, Version 2.0. +// +// +// Represents an ordered pair of integer x- and y-coordinates that defines a point in +// a two-dimensional plane. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ImageProcessor +{ + using System; + using System.ComponentModel; + + /// + /// Represents an ordered pair of integer x- and y-coordinates that defines a point in + /// a two-dimensional plane. + /// + public struct Point : IEquatable + { + /// + /// Represents a Point that has X and Y values set to zero. + /// + public static readonly Point Empty = new Point(); + + /// + /// The x-coordinate of this Point. + /// + public int X; + + /// + /// The y-coordinate of this Point. + /// + public int Y; + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The horizontal position of the point. + /// + /// + /// The vertical position of the point. + /// + public Point(int x, int y) + { + this.X = x; + this.Y = y; + } + + /// + /// Gets a value indicating whether this Point is empty. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsEmpty + { + get + { + return this.X == 0 && this.Y == 0; + } + } + + /// + /// Indicates whether this instance and a specified object are equal. + /// + /// + /// The object to compare with the current instance. + /// + /// + /// true if and this instance are the same type and represent the + /// same value; otherwise, false. + /// + public override bool Equals(object obj) + { + if (!(obj is Point)) + { + return false; + } + + Point other = (Point)obj; + + return other.X == this.X && other.Y == this.Y; + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + public override int GetHashCode() + { + return this.GetHashCode(this); + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// true if the current object is equal to the parameter; otherwise, false. + /// + /// An object to compare with this object. + public bool Equals(Point other) + { + return this.X.Equals(other.X) && this.Y.Equals(other.Y); + } + + /// + /// Returns the hash code for this instance. + /// + /// + /// The instance of to return the hash code for. + /// + /// + /// A 32-bit signed integer that is the hash code for this instance. + /// + private int GetHashCode(Point obj) + { + unchecked + { + int hashCode = obj.X.GetHashCode(); + hashCode = (hashCode * 397) ^ obj.Y.GetHashCode(); + return hashCode; + } + } + } +} diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index c5f8051d5c..31db7fe297 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ImageProcessor")] -[assembly: AssemblyCopyright("Copyright © James South 2012")] +[assembly: AssemblyCopyright("Copyright © James South and contributors 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: NeutralResourcesLanguage("en")] diff --git a/src/ImageProcessor/Settings.StyleCop b/src/ImageProcessor/Settings.StyleCop new file mode 100644 index 0000000000..54173f942d --- /dev/null +++ b/src/ImageProcessor/Settings.StyleCop @@ -0,0 +1,11 @@ + + + + + James South + Copyright © James South and contributors. +Licensed under the Apache License, Version 2.0. + + + + \ No newline at end of file