From 2e9f27b6b7a40bb4a80644b8b4108ca1369bc541 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 11 Apr 2023 17:05:58 +0100 Subject: [PATCH] fix: validate null arguments for Polygon and PolygonF extensions --- X10D.Unity/src/Drawing/PolygonExtensions.cs | 21 ++++++++++ X10D.Unity/src/Drawing/PolygonFExtensions.cs | 42 ++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/X10D.Unity/src/Drawing/PolygonExtensions.cs b/X10D.Unity/src/Drawing/PolygonExtensions.cs index 8a72df8..b1b962f 100644 --- a/X10D.Unity/src/Drawing/PolygonExtensions.cs +++ b/X10D.Unity/src/Drawing/PolygonExtensions.cs @@ -14,8 +14,14 @@ public static class PolygonExtensions /// /// The polygon whose points to update. /// The point to add. + /// is . public static void AddVertex(this Polygon polygon, Vector2Int point) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + polygon.AddVertex(point.ToSystemPoint()); } @@ -24,8 +30,23 @@ public static class PolygonExtensions /// /// The polygon whose vertices to update. /// The vertices to add. + /// + /// is . + /// -or- + /// is . + /// public static void AddVertices(this Polygon polygon, IEnumerable vertices) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + + if (vertices is null) + { + throw new ArgumentNullException(nameof(vertices)); + } + foreach (Vector2Int vertex in vertices) { polygon.AddVertex(vertex); diff --git a/X10D.Unity/src/Drawing/PolygonFExtensions.cs b/X10D.Unity/src/Drawing/PolygonFExtensions.cs index 0042904..1b91d0c 100644 --- a/X10D.Unity/src/Drawing/PolygonFExtensions.cs +++ b/X10D.Unity/src/Drawing/PolygonFExtensions.cs @@ -14,8 +14,14 @@ public static class PolygonFExtensions /// /// The polygon whose vertices to update. /// The vertex to add. + /// is . public static void AddVertex(this PolygonF polygon, Vector2Int vertex) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + polygon.AddVertex(vertex.ToSystemPoint()); } @@ -24,8 +30,14 @@ public static class PolygonFExtensions /// /// The polygon whose vertices to update. /// The vertex to add. + /// is . public static void AddVertex(this PolygonF polygon, Vector2 vertex) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + polygon.AddVertex(vertex.ToSystemPointF()); } @@ -34,8 +46,23 @@ public static class PolygonFExtensions /// /// The polygon whose vertices to update. /// The vertices to add. + /// + /// is . + /// -or- + /// is . + /// public static void AddVertices(this PolygonF polygon, IEnumerable vertices) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + + if (vertices is null) + { + throw new ArgumentNullException(nameof(vertices)); + } + foreach (Vector2Int vertex in vertices) { polygon.AddVertex(vertex); @@ -47,8 +74,23 @@ public static class PolygonFExtensions /// /// The polygon whose vertices to update. /// The vertices to add. + /// + /// is . + /// -or- + /// is . + /// public static void AddVertices(this PolygonF polygon, IEnumerable vertices) { + if (polygon is null) + { + throw new ArgumentNullException(nameof(polygon)); + } + + if (vertices is null) + { + throw new ArgumentNullException(nameof(vertices)); + } + foreach (Vector2 vertex in vertices) { polygon.AddVertex(vertex);