1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:38:47 +00:00

Add Polygon/Polyhedron extension methods for Unity vector types

This commit is contained in:
Oliver Booth 2022-06-01 18:38:14 +01:00
parent 43a155ad90
commit eaa88ce11a
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,34 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity.Drawing;
/// <summary>
/// Drawing-related extension methods for <see cref="Polygon" />.
/// </summary>
public static class PolygonExtensions
{
/// <summary>
/// Adds a vertex to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose points to update.</param>
/// <param name="point">The point to add.</param>
public static void AddVertex(this Polygon polygon, Vector2Int point)
{
polygon.AddVertex(point.ToSystemPoint());
}
/// <summary>
/// Adds a collection of vertices to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
public static void AddVertices(this Polygon polygon, IEnumerable<Vector2Int> vertices)
{
foreach (Vector2Int vertex in vertices)
{
polygon.AddVertex(vertex);
}
}
}

View File

@ -0,0 +1,57 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity.Drawing;
/// <summary>
/// Drawing-related extension methods for <see cref="PolygonF" />.
/// </summary>
public static class PolygonFExtensions
{
/// <summary>
/// Adds a point to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
public static void AddVertex(this PolygonF polygon, Vector2Int vertex)
{
polygon.AddVertex(vertex.ToSystemPoint());
}
/// <summary>
/// Adds a point to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
public static void AddVertex(this PolygonF polygon, Vector2 vertex)
{
polygon.AddVertex(vertex.ToSystemPointF());
}
/// <summary>
/// Adds a collection of vertices to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
public static void AddVertices(this PolygonF polygon, IEnumerable<Vector2Int> vertices)
{
foreach (Vector2Int vertex in vertices)
{
polygon.AddVertex(vertex);
}
}
/// <summary>
/// Adds a collection of vertices to this polygon.
/// </summary>
/// <param name="polygon">The polygon whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
public static void AddVertices(this PolygonF polygon, IEnumerable<Vector2> vertices)
{
foreach (Vector2 vertex in vertices)
{
polygon.AddVertex(vertex);
}
}
}

View File

@ -0,0 +1,57 @@
using UnityEngine;
using X10D.Drawing;
using X10D.Unity.Numerics;
namespace X10D.Unity.Drawing;
/// <summary>
/// Drawing-related extension methods for <see cref="Polyhedron" />.
/// </summary>
public static class PolyhedronExtensions
{
/// <summary>
/// Adds a vertex to this polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
public static void AddVertex(this Polyhedron polyhedron, Vector3Int vertex)
{
polyhedron.AddVertex(vertex.ToSystemVector());
}
/// <summary>
/// Adds a vertex to this polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
public static void AddVertex(this Polyhedron polyhedron, Vector3 vertex)
{
polyhedron.AddVertex(vertex.ToSystemVector());
}
/// <summary>
/// Adds a collection of vertices to this polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
public static void AddVertices(this Polyhedron polyhedron, IEnumerable<Vector3Int> vertices)
{
foreach (Vector3Int vertex in vertices)
{
polyhedron.AddVertex(vertex);
}
}
/// <summary>
/// Adds a collection of vertices to this polyhedron.
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
public static void AddVertices(this Polyhedron polyhedron, IEnumerable<Vector3> vertices)
{
foreach (Vector3 vertex in vertices)
{
polyhedron.AddVertex(vertex);
}
}
}