From 1865941d82652491d9901170897c604d824f3e5e Mon Sep 17 00:00:00 2001 From: Patrick Hofman Date: Thu, 17 Dec 2020 10:05:17 +0100 Subject: [PATCH 1/2] Add Equals and GetHashCode methods, add support for .net 5 and .net core 3.1. --- Decimal2D.Tests/Decimal2D.Tests.csproj | 6 +++--- Decimal2D/Arc2D.cs | 14 +++++++++++++- Decimal2D/Circle2D.cs | 14 +++++++++++++- Decimal2D/Decimal2D.csproj | 2 +- Decimal2D/LineSeg2D.cs | 13 +++++++++++++ Decimal2D/Vector2D.cs | 9 +++++++++ DecimalEx.Tests/DecimalEx.Tests.csproj | 6 +++--- DecimalEx/DecimalEx.csproj | 3 ++- 8 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Decimal2D.Tests/Decimal2D.Tests.csproj b/Decimal2D.Tests/Decimal2D.Tests.csproj index 2249c0f..831f3b7 100644 --- a/Decimal2D.Tests/Decimal2D.Tests.csproj +++ b/Decimal2D.Tests/Decimal2D.Tests.csproj @@ -1,13 +1,13 @@  - netcoreapp2.2 + net472 - + - + diff --git a/Decimal2D/Arc2D.cs b/Decimal2D/Arc2D.cs index e9002a7..713ab18 100644 --- a/Decimal2D/Arc2D.cs +++ b/Decimal2D/Arc2D.cs @@ -169,6 +169,19 @@ public static Arc2D FromPointsOnArc(Point2D endPointA, Point2D endPointB, Point2 return objA.Circle != objB.Circle || objA._startAngle != objB._startAngle || objA._endAngle != objB._endAngle; } + public override bool Equals(object obj) + { + return obj is Arc2D other && other == this; + } + public override int GetHashCode() + { + int hashCode = 146115040; + hashCode = hashCode * -1521134295 + Circle.GetHashCode(); + hashCode = hashCode * -1521134295 + _startAngle.GetHashCode(); + hashCode = hashCode * -1521134295 + _endAngle.GetHashCode(); + return hashCode; + } + /// /// Gets or sets the center of the arc as an XY point. /// @@ -410,6 +423,5 @@ public string ToAutoCADCmd(bool linefeedTerminate = true) return string.Format("_arc {0},{1} c {2},{3} {4},{5}{6}", StartPt.X, StartPt.Y, Circle.Center.X, Circle.Center.Y, EndPt.X, EndPt.Y, (linefeedTerminate ? "\r\n" : " ")); } - } } diff --git a/Decimal2D/Circle2D.cs b/Decimal2D/Circle2D.cs index 81d4b15..b7eddfb 100644 --- a/Decimal2D/Circle2D.cs +++ b/Decimal2D/Circle2D.cs @@ -135,6 +135,19 @@ public Circle2D(Point2D pt1, Point2D pt2) return objA.Center != objB.Center || objA._radius != objB._radius; } + public override bool Equals(object obj) + { + return obj is Circle2D other && other == this; + } + + public override int GetHashCode() + { + int hashCode = 1922506679; + hashCode = hashCode * -1521134295 + _center.GetHashCode(); + hashCode = hashCode * -1521134295 + _radius.GetHashCode(); + return hashCode; + } + /// /// Returns a new circle with a radius equal to this circle's radius /// plus the amount specified. Negative amounts are allowed. @@ -1257,6 +1270,5 @@ public string ToAutoCADCmd(bool linefeedTerminate = true) return string.Format("_circle {0},{1} {2}{3}", _center.X, _center.Y, _radius, (linefeedTerminate ? "\r\n" : " ")); } - } } diff --git a/Decimal2D/Decimal2D.csproj b/Decimal2D/Decimal2D.csproj index 774bff0..f836544 100644 --- a/Decimal2D/Decimal2D.csproj +++ b/Decimal2D/Decimal2D.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp3.1;net50 Portable math support for Decimal-based geometric and trigonometric calculations. Nathan P Jones DecimalMath.Decimal2D diff --git a/Decimal2D/LineSeg2D.cs b/Decimal2D/LineSeg2D.cs index 47a8127..518220f 100644 --- a/Decimal2D/LineSeg2D.cs +++ b/Decimal2D/LineSeg2D.cs @@ -51,6 +51,19 @@ public LineSeg2D(decimal x1, decimal y1, decimal x2, decimal y2) return (lineSegA.Pt1 == lineSegB.Pt1) && (lineSegA.Pt2 == lineSegB.Pt2); } + public override bool Equals(object obj) + { + return obj is LineSeg2D other && other == this; + } + + public override int GetHashCode() + { + int hashCode = -913818983; + hashCode = hashCode * -1521134295 + Pt1.GetHashCode(); + hashCode = hashCode * -1521134295 + Pt2.GetHashCode(); + return hashCode; + } + /// /// Gets or sets the midpoint of the line segment. /// diff --git a/Decimal2D/Vector2D.cs b/Decimal2D/Vector2D.cs index 5083fbe..f93d908 100644 --- a/Decimal2D/Vector2D.cs +++ b/Decimal2D/Vector2D.cs @@ -105,6 +105,7 @@ public override bool Equals(object obj) } return this == (Vector2D)obj; } + /// /// Compares this point against another to the given number of decimal places. /// @@ -124,6 +125,14 @@ public bool Equals(Vector2D other, int decimals) return objA.X != objB.X || objA.Y != objB.Y; } + public override int GetHashCode() + { + int hashCode = 1861411795; + hashCode = hashCode * -1521134295 + X.GetHashCode(); + hashCode = hashCode * -1521134295 + Y.GetHashCode(); + return hashCode; + } + /// /// Gets whether or not this is a unit vector, i.e. has a magnitude of 1. /// diff --git a/DecimalEx.Tests/DecimalEx.Tests.csproj b/DecimalEx.Tests/DecimalEx.Tests.csproj index 9ba40dd..98b1c2c 100644 --- a/DecimalEx.Tests/DecimalEx.Tests.csproj +++ b/DecimalEx.Tests/DecimalEx.Tests.csproj @@ -1,13 +1,13 @@  - netcoreapp2.2 + net472 - + - + diff --git a/DecimalEx/DecimalEx.csproj b/DecimalEx/DecimalEx.csproj index 5c0b7f0..f952c95 100644 --- a/DecimalEx/DecimalEx.csproj +++ b/DecimalEx/DecimalEx.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp3.1;net50 Portable math support for Decimal that Microsoft forgot and more. Includes Decimal versions of Sqrt, Pow, Exp, and Log as well as the trig functions Sin, Cos, Tan, ASin, ACos, ATan, ATan2. @@ -20,6 +20,7 @@ Also included is other functionality for working with numbers in Decimal precisi false git https://github.com/nathanpjones/DecimalMath.git + false From ce197157f011d9a6259ffb80a62df5f6eafa3f85 Mon Sep 17 00:00:00 2001 From: Patrick Hofman Date: Thu, 17 Dec 2020 10:08:31 +0100 Subject: [PATCH 2/2] Sign assemblies with a strong name key. --- Decimal2D/Decimal2D.csproj | 1 + DecimalEx/DecimalEx.csproj | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Decimal2D/Decimal2D.csproj b/Decimal2D/Decimal2D.csproj index f836544..f1fb539 100644 --- a/Decimal2D/Decimal2D.csproj +++ b/Decimal2D/Decimal2D.csproj @@ -16,6 +16,7 @@ false https://github.com/nathanpjones/DecimalMath.git git + ..\sign.pfx diff --git a/DecimalEx/DecimalEx.csproj b/DecimalEx/DecimalEx.csproj index f952c95..e704622 100644 --- a/DecimalEx/DecimalEx.csproj +++ b/DecimalEx/DecimalEx.csproj @@ -20,7 +20,8 @@ Also included is other functionality for working with numbers in Decimal precisi false git https://github.com/nathanpjones/DecimalMath.git - false + true + ..\sign.pfx