From deb1f2edd8a0d715525c5a6abf6655d6a36e945d Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 29 Nov 2022 17:12:39 +0000 Subject: [PATCH] Fix CA1602 violations --- X10D/src/Drawing/Polygon.cs | 14 +++++++------- X10D/src/Drawing/PolygonF.cs | 16 +++++++++------- X10D/src/Drawing/Polyhedron.cs | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/X10D/src/Drawing/Polygon.cs b/X10D/src/Drawing/Polygon.cs index 7de943b..87c29bf 100644 --- a/X10D/src/Drawing/Polygon.cs +++ b/X10D/src/Drawing/Polygon.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; namespace X10D.Drawing; @@ -20,7 +20,7 @@ public class Polygon : IEquatable /// Initializes a new instance of the class by copying the specified polygon. /// public Polygon(Polygon polygon) - : this(polygon._vertices) + : this(polygon?._vertices ?? throw new ArgumentNullException(nameof(polygon))) { } @@ -114,9 +114,9 @@ public class Polygon : IEquatable /// if and are considered equal; otherwise, /// . /// - public static bool operator ==(Polygon left, Polygon right) + public static bool operator ==(Polygon? left, Polygon? right) { - return left.Equals(right); + return Equals(left, right); } /// @@ -130,7 +130,7 @@ public class Polygon : IEquatable /// public static bool operator !=(Polygon left, Polygon right) { - return !left.Equals(right); + return !(left == right); } /// @@ -223,9 +223,9 @@ public class Polygon : IEquatable /// if this instance and are considered equal; otherwise, /// . /// - public bool Equals(Polygon other) + public bool Equals(Polygon? other) { - return _vertices.SequenceEqual(other._vertices); + return other is not null && _vertices.SequenceEqual(other._vertices); } /// diff --git a/X10D/src/Drawing/PolygonF.cs b/X10D/src/Drawing/PolygonF.cs index 15243e8..13d7813 100644 --- a/X10D/src/Drawing/PolygonF.cs +++ b/X10D/src/Drawing/PolygonF.cs @@ -21,8 +21,9 @@ public class PolygonF /// /// Initializes a new instance of the class by copying the specified polygon. /// + /// is . public PolygonF(PolygonF polygon) - : this(polygon._vertices) + : this(polygon?._vertices ?? throw new ArgumentNullException(nameof(polygon))) { } @@ -30,6 +31,7 @@ public class PolygonF /// Initializes a new instance of the class by constructing it from the specified vertices. /// /// An enumerable collection of vertices from which the polygon should be constructed. + /// is . public PolygonF(IEnumerable vertices) : this(vertices.Select(p => p.ToPointF())) { @@ -143,9 +145,9 @@ public class PolygonF /// if and are considered equal; otherwise, /// . /// - public static bool operator ==(PolygonF left, PolygonF right) + public static bool operator ==(PolygonF? left, PolygonF? right) { - return left.Equals(right); + return Equals(left, right); } /// @@ -157,9 +159,9 @@ public class PolygonF /// if and are considered not equal; otherwise, /// . /// - public static bool operator !=(PolygonF left, PolygonF right) + public static bool operator !=(PolygonF? left, PolygonF? right) { - return !left.Equals(right); + return !(left == right); } /// @@ -283,9 +285,9 @@ public class PolygonF /// if this instance and are considered equal; otherwise, /// . /// - public bool Equals(PolygonF other) + public bool Equals(PolygonF? other) { - return _vertices.SequenceEqual(other._vertices); + return other is not null && _vertices.SequenceEqual(other._vertices); } /// diff --git a/X10D/src/Drawing/Polyhedron.cs b/X10D/src/Drawing/Polyhedron.cs index 4a28394..79a27cc 100644 --- a/X10D/src/Drawing/Polyhedron.cs +++ b/X10D/src/Drawing/Polyhedron.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; using System.Numerics; namespace X10D.Drawing; @@ -20,8 +20,9 @@ public class Polyhedron : IEquatable /// /// Initializes a new instance of the class by copying the specified polyhedron. /// + /// is . public Polyhedron(Polyhedron polyhedron) - : this(polyhedron._vertices) + : this(polyhedron?._vertices ?? throw new ArgumentNullException(nameof(polyhedron))) { } @@ -29,6 +30,7 @@ public class Polyhedron : IEquatable /// Initializes a new instance of the class by constructing it from the specified vertices. /// /// An enumerable collection of vertices from which the polyhedron should be constructed. + /// is . public Polyhedron(IEnumerable vertices) { #if NET6_0_OR_GREATER @@ -112,9 +114,9 @@ public class Polyhedron : IEquatable /// if and are considered equal; otherwise, /// . /// - public static bool operator ==(Polyhedron left, Polyhedron right) + public static bool operator ==(Polyhedron? left, Polyhedron? right) { - return left.Equals(right); + return Equals(left, right); } /// @@ -126,9 +128,9 @@ public class Polyhedron : IEquatable /// if and are considered not equal; otherwise, /// . /// - public static bool operator !=(Polyhedron left, Polyhedron right) + public static bool operator !=(Polyhedron? left, Polyhedron? right) { - return !left.Equals(right); + return !(left == right); } /// @@ -262,9 +264,9 @@ public class Polyhedron : IEquatable /// if this instance and are considered equal; otherwise, /// . /// - public bool Equals(Polyhedron other) + public bool Equals(Polyhedron? other) { - return _vertices.SequenceEqual(other._vertices); + return other is not null && _vertices.SequenceEqual(other._vertices); } ///