Skip to content

Commit

Permalink
Replaced IList with IReadOnlyList wherever possible
Browse files Browse the repository at this point in the history
Closing #69. Nice.
  • Loading branch information
BasmanovDaniil committed Jan 7, 2021
1 parent de196fb commit 73825b9
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Runtime/ArrayE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public static LinkedListNode<T> PreviousOrLast<T>(this LinkedListNode<T> current
/// <summary>
/// Two-dimensional indexer getter
/// </summary>
public static T GetXY<T>(this IList<T> list, Vector2Int position, int width)
public static T GetXY<T>(this IReadOnlyList<T> list, Vector2Int position, int width)
{
return list[position.y*width + position.x];
}

/// <summary>
/// Two-dimensional indexer getter
/// </summary>
public static T GetXY<T>(this IList<T> list, int x, int y, int width)
public static T GetXY<T>(this IReadOnlyList<T> list, int x, int y, int width)
{
return list[y*width + x];
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public static void SetXY<T>(this NativeArray<T> list, int x, int y, int width, T
/// <summary>
/// Looped indexer getter, allows out of bounds indices
/// </summary>
public static T GetLooped<T>(this IList<T> list, int index)
public static T GetLooped<T>(this IReadOnlyList<T> list, int index)
{
while (index < 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/ClipperUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ClipperUtility
{
public const float ClipperScale = 100000;

public static List<IntPoint> ToIntPath(IList<Vector2> path)
public static List<IntPoint> ToIntPath(IReadOnlyList<Vector2> path)
{
var intPath = new List<IntPoint>(path.Count);
foreach (var vertex in path)
Expand Down
12 changes: 6 additions & 6 deletions Runtime/Geometry/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public static Vector2 GetAngleBisector(Vector2 previous, Vector2 current, Vector
/// </summary>
/// <param name="polygon">Vertices of the polygon in clockwise order.</param>
/// <param name="distance">Offset distance. Positive values offset outside, negative inside.</param>
public static List<Vector2> OffsetPolygon(IList<Vector2> polygon, float distance)
public static List<Vector2> OffsetPolygon(IReadOnlyList<Vector2> polygon, float distance)
{
var newPolygon = new List<Vector2>(polygon.Count);
for (int i = 0; i < polygon.Count; i++)
Expand Down Expand Up @@ -699,7 +699,7 @@ public static float GetAngleBisectorSin(float angle)
/// Calculates the area of the input polygon.
/// </summary>
/// <param name="polygon">Vertices of the polygon.</param>
public static float GetArea(IList<Vector2> polygon)
public static float GetArea(IReadOnlyList<Vector2> polygon)
{
return Mathf.Abs(GetSignedArea(polygon));
}
Expand All @@ -708,7 +708,7 @@ public static float GetArea(IList<Vector2> polygon)
/// Calculates the signed area of the input polygon.
/// </summary>
/// <param name="polygon">Vertices of the polygon.</param>
public static float GetSignedArea(IList<Vector2> polygon)
public static float GetSignedArea(IReadOnlyList<Vector2> polygon)
{
if (polygon.Count < 3) return 0;
float a = 0;
Expand All @@ -723,7 +723,7 @@ public static float GetSignedArea(IList<Vector2> polygon)
/// Calculates the orientation of the vertices of the input polygon.
/// </summary>
/// <param name="polygon">Vertices of the polygon.</param>
public static Orientation GetOrientation(IList<Vector2> polygon)
public static Orientation GetOrientation(IReadOnlyList<Vector2> polygon)
{
if (polygon.Count < 3) return Orientation.NonOrientable;
float signedArea = GetSignedArea(polygon);
Expand All @@ -736,7 +736,7 @@ public static Orientation GetOrientation(IList<Vector2> polygon)
/// Calculates the perimeter of the input polygon.
/// </summary>
/// <param name="polygon">Vertices of the polygon.</param>
public static float GetPerimeter(IList<Vector2> polygon)
public static float GetPerimeter(IReadOnlyList<Vector2> polygon)
{
if (polygon.Count < 2) return 0;
float perimeter = 0;
Expand All @@ -750,7 +750,7 @@ public static float GetPerimeter(IList<Vector2> polygon)
/// <summary>
/// Calculates a bounding rect for a set of vertices.
/// </summary>
public static Rect GetRect(IList<Vector2> vertices)
public static Rect GetRect(IReadOnlyList<Vector2> vertices)
{
Vector2 min = vertices[0];
Vector2 max = vertices[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class StraightSkeletonGenerator
private readonly List<Plan> newPlans = new List<Plan>();
private StraightSkeleton skeleton;

public StraightSkeleton Generate(IList<Vector2> polygon)
public StraightSkeleton Generate(IReadOnlyList<Vector2> polygon)
{
activePlans.Clear();
newPlans.Clear();
Expand Down
6 changes: 3 additions & 3 deletions Runtime/LibTessDotNet/Tess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ private void OutputContours()
}
}

private Real SignedArea(IList<ContourVertex> vertices)
private Real SignedArea(IReadOnlyList<ContourVertex> vertices)
{
Real area = 0.0f;

Expand Down Expand Up @@ -745,12 +745,12 @@ public void AddContour(ContourVertex[] vertices, ContourOrientation forceOrienta
/// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/>
/// force the vertices to have a specified orientation.
/// </param>
public void AddContour(IList<ContourVertex> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
public void AddContour(IReadOnlyList<ContourVertex> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
{
AddContourInternal(vertices, forceOrientation);
}

private void AddContourInternal(IList<ContourVertex> vertices, ContourOrientation forceOrientation)
private void AddContourInternal(IReadOnlyList<ContourVertex> vertices, ContourOrientation forceOrientation)
{
if (_mesh == null)
{
Expand Down
33 changes: 17 additions & 16 deletions Runtime/MeshDraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private MeshDraft _AddQuad(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, Ve
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, bool reverseTriangles = false)
{
Vector3 normal = Vector3.Cross(fan[1] - fan[0], fan[fan.Count - 1] - fan[0]).normalized;
return AddTriangleFan(fan, normal, reverseTriangles);
Expand All @@ -307,7 +307,7 @@ public MeshDraft AddTriangleFan(IList<Vector3> fan, bool reverseTriangles = fals
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, Vector3 normal, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, Vector3 normal, bool reverseTriangles = false)
{
AddTriangleFanVertices(fan, reverseTriangles);
for (int i = 0; i < fan.Count; i++)
Expand All @@ -323,7 +323,7 @@ public MeshDraft AddTriangleFan(IList<Vector3> fan, Vector3 normal, bool reverse
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, IList<Vector3> normals, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, IReadOnlyList<Vector3> normals, bool reverseTriangles = false)
{
AddTriangleFanVertices(fan, reverseTriangles);
this.normals.AddRange(normals);
Expand All @@ -336,7 +336,7 @@ public MeshDraft AddTriangleFan(IList<Vector3> fan, IList<Vector3> normals, bool
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, IList<Vector2> uv, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, IReadOnlyList<Vector2> uv, bool reverseTriangles = false)
{
this.uv.AddRange(uv);
return AddTriangleFan(fan, reverseTriangles);
Expand All @@ -348,7 +348,7 @@ public MeshDraft AddTriangleFan(IList<Vector3> fan, IList<Vector2> uv, bool reve
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, Vector3 normal, IList<Vector2> uv, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, Vector3 normal, IReadOnlyList<Vector2> uv, bool reverseTriangles = false)
{
this.uv.AddRange(uv);
return AddTriangleFan(fan, normal, reverseTriangles);
Expand All @@ -360,13 +360,14 @@ public MeshDraft AddTriangleFan(IList<Vector3> fan, Vector3 normal, IList<Vector
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_fan
/// </remarks>
public MeshDraft AddTriangleFan(IList<Vector3> fan, IList<Vector3> normals, IList<Vector2> uv, bool reverseTriangles = false)
public MeshDraft AddTriangleFan(IReadOnlyList<Vector3> fan, IReadOnlyList<Vector3> normals, IReadOnlyList<Vector2> uv,
bool reverseTriangles = false)
{
this.uv.AddRange(uv);
return AddTriangleFan(fan, normals, reverseTriangles);
}

private void AddTriangleFanVertices(IList<Vector3> fan, bool reverseTriangles)
private void AddTriangleFanVertices(IReadOnlyList<Vector3> fan, bool reverseTriangles)
{
int count = vertices.Count;
if (reverseTriangles)
Expand Down Expand Up @@ -400,7 +401,7 @@ private void AddTriangleFanVertices(IList<Vector3> fan, bool reverseTriangles)
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip)
{
Vector3 normal = Vector3.Cross(strip[1] - strip[0], strip[2] - strip[0]).normalized;
return AddTriangleStrip(strip, normal);
Expand All @@ -412,7 +413,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip)
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip, Vector3 normal)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip, Vector3 normal)
{
for (int i = 0, j = 1, k = 2;
i < strip.Count - 2;
Expand All @@ -436,7 +437,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip, Vector3 normal)
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector3> normals)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip, IReadOnlyList<Vector3> normals)
{
for (int i = 0, j = 1, k = 2;
i < strip.Count - 2;
Expand All @@ -457,7 +458,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector3> normals)
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector2> uv)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip, IReadOnlyList<Vector2> uv)
{
this.uv.AddRange(uv);
return AddTriangleStrip(strip);
Expand All @@ -469,7 +470,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector2> uv)
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip, Vector3 normal, IList<Vector2> uv)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip, Vector3 normal, IReadOnlyList<Vector2> uv)
{
this.uv.AddRange(uv);
return AddTriangleStrip(strip, normal);
Expand All @@ -481,7 +482,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip, Vector3 normal, IList<Ve
/// <remarks>
/// https://en.wikipedia.org/wiki/Triangle_strip
/// </remarks>
public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector3> normals, IList<Vector2> uv)
public MeshDraft AddTriangleStrip(IReadOnlyList<Vector3> strip, IReadOnlyList<Vector3> normals, IReadOnlyList<Vector2> uv)
{
this.uv.AddRange(uv);
return AddTriangleStrip(strip, normals);
Expand All @@ -494,7 +495,7 @@ public MeshDraft AddTriangleStrip(IList<Vector3> strip, IList<Vector3> normals,
/// <summary>
/// Adds a baseless pyramid to the draft
/// </summary>
public MeshDraft AddBaselessPyramid(Vector3 apex, IList<Vector3> ring, bool generateUV, bool reverseTriangles = false)
public MeshDraft AddBaselessPyramid(Vector3 apex, IReadOnlyList<Vector3> ring, bool generateUV, bool reverseTriangles = false)
{
if (generateUV)
{
Expand Down Expand Up @@ -547,7 +548,7 @@ public MeshDraft AddBaselessPyramid(Vector3 apex, IList<Vector3> ring, bool gene
/// <summary>
/// Adds a band made from triangles to the draft
/// </summary>
public MeshDraft AddFlatTriangleBand(IList<Vector3> lowerRing, IList<Vector3> upperRing, bool generateUV)
public MeshDraft AddFlatTriangleBand(IReadOnlyList<Vector3> lowerRing, IReadOnlyList<Vector3> upperRing, bool generateUV)
{
if (lowerRing.Count != upperRing.Count)
{
Expand Down Expand Up @@ -608,7 +609,7 @@ public MeshDraft AddFlatTriangleBand(IList<Vector3> lowerRing, IList<Vector3> up
/// <summary>
/// Adds a band made from quads to the draft
/// </summary>
public MeshDraft AddFlatQuadBand(IList<Vector3> lowerRing, IList<Vector3> upperRing, bool generateUV)
public MeshDraft AddFlatQuadBand(IReadOnlyList<Vector3> lowerRing, IReadOnlyList<Vector3> upperRing, bool generateUV)
{
if (lowerRing.Count != upperRing.Count)
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/PathClipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public PathClipper(InitOptions initOptions = 0)
/// <param name="polyType"> Type of the path (Subject or Clip). </param>
/// <param name="closed"> Controls whether the path is closed. Clipping paths must always be closed. </param>
/// <returns> False if the path is invalid for clipping, true otherwise. </returns>
public bool AddPath(IList<Vector2> path, PolyType polyType, bool closed = true)
public bool AddPath(IReadOnlyList<Vector2> path, PolyType polyType, bool closed = true)
{
return clipper.AddPath(ClipperUtility.ToIntPath(path), polyType, closed);
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/PathOffsetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public PathOffsetter(double miterLimit = 2.0, double arcTolerance = 0.25)
/// <param name="path"> Vertices of the path. </param>
/// <param name="joinType"> See http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/JoinType.htm </param>
/// <param name="endType"> See http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/EndType.htm </param>
public void AddPath(IList<Vector2> path, JoinType joinType = JoinType.jtMiter, EndType endType = EndType.etClosedPolygon)
public void AddPath(IReadOnlyList<Vector2> path, JoinType joinType = JoinType.jtMiter, EndType endType = EndType.etClosedPolygon)
{
clipperOffset.AddPath(ClipperUtility.ToIntPath(path), joinType, endType);
}
Expand Down
8 changes: 4 additions & 4 deletions Runtime/RandomE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static List<ColorHSV> TetradicPalette(float saturation = 1, float value =
/// <summary>
/// Returns a random element
/// </summary>
public static T GetRandom<T>(this IList<T> list)
public static T GetRandom<T>(this IReadOnlyList<T> list)
{
if (list == null)
{
Expand All @@ -338,7 +338,7 @@ public static T GetRandom<T>(this IList<T> list)
/// <summary>
/// Returns a random element
/// </summary>
public static T GetRandom<T>(this IList<T> list, ref MRandom random)
public static T GetRandom<T>(this IReadOnlyList<T> list, ref MRandom random)
{
if (list == null)
{
Expand Down Expand Up @@ -376,7 +376,7 @@ public static T GetRandom<T>(T item1, T item2, params T[] items)
/// Returns a random element with the chances of rolling based on <paramref name="weights"/>
/// </summary>
/// <param name="weights">Positive floats representing weights. Negative values may lead to unpredictable behaviour.</param>
public static T GetRandom<T>(this IList<T> list, IList<float> weights)
public static T GetRandom<T>(this IReadOnlyList<T> list, IReadOnlyList<float> weights)
{
if (list == null)
{
Expand Down Expand Up @@ -423,7 +423,7 @@ public static T GetRandom<T>(this IList<T> list, IList<float> weights)
/// Returns a random element with the chances of rolling based on <paramref name="weights"/>
/// </summary>
/// <param name="weights">Positive floats representing weights. Negative values may lead to unpredictable behaviour.</param>
public static T GetRandom<T>(this IList<T> list, IList<float> weights, ref MRandom random)
public static T GetRandom<T>(this IReadOnlyList<T> list, IReadOnlyList<float> weights, ref MRandom random)
{
if (list == null)
{
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Tessellator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool removeEmptyPolygons
/// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/>
/// force the vertices to have a specified orientation.
/// </param>
public void AddContour(IList<Vector2> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
public void AddContour(IReadOnlyList<Vector2> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
{
var contour = new ContourVertex[vertices.Count];
for (int i = 0; i < vertices.Count; i++)
Expand All @@ -68,7 +68,7 @@ public void AddContour(IList<Vector2> vertices, ContourOrientation forceOrientat
/// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/>
/// force the vertices to have a specified orientation.
/// </param>
public void AddContour(IList<Vector3> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
public void AddContour(IReadOnlyList<Vector3> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
{
var contour = new ContourVertex[vertices.Count];
for (int i = 0; i < vertices.Count; i++)
Expand All @@ -89,7 +89,7 @@ public void AddContour(IList<Vector3> vertices, ContourOrientation forceOrientat
/// <see cref="ContourOrientation.Clockwise"/> and <see cref="ContourOrientation.CounterClockwise"/>
/// force the vertices to have a specified orientation.
/// </param>
public void AddContour(IList<ContourVertex> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
public void AddContour(IReadOnlyList<ContourVertex> vertices, ContourOrientation forceOrientation = ContourOrientation.Original)
{
tess.AddContour(vertices, forceOrientation);
}
Expand Down

0 comments on commit 73825b9

Please sign in to comment.