mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Initial commit
This commit is contained in:
commit
3c7cc0c973
8391 changed files with 704313 additions and 0 deletions
|
@ -0,0 +1,248 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Contour.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class Contour
|
||||
{
|
||||
int marker;
|
||||
|
||||
bool convex;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of points making up the contour.
|
||||
/// </summary>
|
||||
public List<Vertex> Points { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Contour" /> class.
|
||||
/// </summary>
|
||||
/// <param name="points">The points that make up the contour.</param>
|
||||
public Contour(IEnumerable<Vertex> points)
|
||||
: this(points, 0, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Contour" /> class.
|
||||
/// </summary>
|
||||
/// <param name="points">The points that make up the contour.</param>
|
||||
/// <param name="marker">Contour marker.</param>
|
||||
public Contour(IEnumerable<Vertex> points, int marker)
|
||||
: this(points, marker, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Contour" /> class.
|
||||
/// </summary>
|
||||
/// <param name="points">The points that make up the contour.</param>
|
||||
/// <param name="marker">Contour marker.</param>
|
||||
/// <param name="convex">The hole is convex.</param>
|
||||
public Contour(IEnumerable<Vertex> points, int marker, bool convex)
|
||||
{
|
||||
AddPoints(points);
|
||||
|
||||
this.marker = marker;
|
||||
this.convex = convex;
|
||||
}
|
||||
|
||||
public List<ISegment> GetSegments()
|
||||
{
|
||||
var segments = new List<ISegment>();
|
||||
|
||||
var p = this.Points;
|
||||
|
||||
int count = p.Count - 1;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// Add segments to polygon.
|
||||
segments.Add(new Segment(p[i], p[i + 1], marker));
|
||||
}
|
||||
|
||||
// Close the contour.
|
||||
segments.Add(new Segment(p[count], p[0], marker));
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to find a point inside the contour.
|
||||
/// </summary>
|
||||
/// <param name="limit">The number of iterations on each segment (default = 5).</param>
|
||||
/// <param name="eps">Threshold for co-linear points (default = 2e-5).</param>
|
||||
/// <returns>Point inside the contour</returns>
|
||||
/// <exception cref="Exception">Throws if no point could be found.</exception>
|
||||
/// <remarks>
|
||||
/// For each corner (index i) of the contour, the 3 points with indices i-1, i and i+1
|
||||
/// are considered and a search on the line through the corner vertex is started (either
|
||||
/// on the bisecting line, or, if <see cref="IPredicates.CounterClockwise"/> is less than
|
||||
/// eps, on the perpendicular line.
|
||||
/// A given number of points will be tested (limit), while the distance to the contour
|
||||
/// boundary will be reduced in each iteration (with a factor 1 / 2^i, i = 1 ... limit).
|
||||
/// </remarks>
|
||||
public Point FindInteriorPoint(int limit = 5, double eps = 2e-5)
|
||||
{
|
||||
if (convex)
|
||||
{
|
||||
int count = this.Points.Count;
|
||||
|
||||
var point = new Point(0.0, 0.0);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
point.x += this.Points[i].x;
|
||||
point.y += this.Points[i].y;
|
||||
}
|
||||
|
||||
// If the contour is convex, use its centroid.
|
||||
point.x /= count;
|
||||
point.y /= count;
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
return FindPointInPolygon(this.Points, limit, eps);
|
||||
}
|
||||
|
||||
private void AddPoints(IEnumerable<Vertex> points)
|
||||
{
|
||||
this.Points = new List<Vertex>(points);
|
||||
|
||||
int count = Points.Count - 1;
|
||||
|
||||
// Check if first vertex equals last vertex.
|
||||
if (Points[0] == Points[count])
|
||||
{
|
||||
Points.RemoveAt(count);
|
||||
}
|
||||
}
|
||||
|
||||
#region Helper methods
|
||||
|
||||
private static Point FindPointInPolygon(List<Vertex> contour, int limit, double eps)
|
||||
{
|
||||
var bounds = new Rectangle();
|
||||
bounds.Expand(contour.Cast<Point>());
|
||||
|
||||
int length = contour.Count;
|
||||
|
||||
var test = new Point();
|
||||
|
||||
Point a, b, c; // Current corner points.
|
||||
|
||||
double bx, by;
|
||||
double dx, dy;
|
||||
double h;
|
||||
|
||||
var predicates = new RobustPredicates();
|
||||
|
||||
a = contour[0];
|
||||
b = contour[1];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
c = contour[(i + 2) % length];
|
||||
|
||||
// Corner point.
|
||||
bx = b.x;
|
||||
by = b.y;
|
||||
|
||||
// NOTE: if we knew the contour points were in counterclockwise order, we
|
||||
// could skip concave corners and search only in one direction.
|
||||
|
||||
h = predicates.CounterClockwise(a, b, c);
|
||||
|
||||
if (Math.Abs(h) < eps)
|
||||
{
|
||||
// Points are nearly co-linear. Use perpendicular direction.
|
||||
dx = (c.y - a.y) / 2;
|
||||
dy = (a.x - c.x) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Direction [midpoint(a-c) -> corner point]
|
||||
dx = (a.x + c.x) / 2 - bx;
|
||||
dy = (a.y + c.y) / 2 - by;
|
||||
}
|
||||
|
||||
// Move around the contour.
|
||||
a = b;
|
||||
b = c;
|
||||
|
||||
h = 1.0;
|
||||
|
||||
for (int j = 0; j < limit; j++)
|
||||
{
|
||||
// Search in direction.
|
||||
test.x = bx + dx * h;
|
||||
test.y = by + dy * h;
|
||||
|
||||
if (bounds.Contains(test) && IsPointInPolygon(test, contour))
|
||||
{
|
||||
return test;
|
||||
}
|
||||
|
||||
// Search in opposite direction (see NOTE above).
|
||||
test.x = bx - dx * h;
|
||||
test.y = by - dy * h;
|
||||
|
||||
if (bounds.Contains(test) && IsPointInPolygon(test, contour))
|
||||
{
|
||||
return test;
|
||||
}
|
||||
|
||||
h = h / 2;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the given point is inside the polygon, or false if it is not.
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check.</param>
|
||||
/// <param name="poly">The polygon (list of contour points).</param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// WARNING: If the point is exactly on the edge of the polygon, then the function
|
||||
/// may return true or false.
|
||||
///
|
||||
/// See http://alienryderflex.com/polygon/
|
||||
/// </remarks>
|
||||
private static bool IsPointInPolygon(Point point, List<Vertex> poly)
|
||||
{
|
||||
bool inside = false;
|
||||
|
||||
double x = point.x;
|
||||
double y = point.y;
|
||||
|
||||
int count = poly.Count;
|
||||
|
||||
for (int i = 0, j = count - 1; i < count; i++)
|
||||
{
|
||||
if (((poly[i].y < y && poly[j].y >= y) || (poly[j].y < y && poly[i].y >= y))
|
||||
&& (poly[i].x <= x || poly[j].x <= x))
|
||||
{
|
||||
inside ^= (poly[i].x + (y - poly[i].y) / (poly[j].y - poly[i].y) * (poly[j].x - poly[i].x) < x);
|
||||
}
|
||||
|
||||
j = i;
|
||||
}
|
||||
|
||||
return inside;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7115b8240624044b9a02b74ca778a32e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,59 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Edge.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a straight line segment in 2D space.
|
||||
/// </summary>
|
||||
internal class Edge : IEdge
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the first endpoints index.
|
||||
/// </summary>
|
||||
public int P0
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the second endpoints index.
|
||||
/// </summary>
|
||||
public int P1
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the segments boundary mark.
|
||||
/// </summary>
|
||||
public int Label
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Edge" /> class.
|
||||
/// </summary>
|
||||
public Edge(int p0, int p1)
|
||||
: this(p0, p1, 0)
|
||||
{}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Edge" /> class.
|
||||
/// </summary>
|
||||
public Edge(int p0, int p1, int label)
|
||||
{
|
||||
this.P0 = p0;
|
||||
this.P1 = p1;
|
||||
this.Label = label;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80d43aefd9bfa4f669b8abc336353628
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,143 @@
|
|||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using Animation.TriangleNet.Meshing;
|
||||
|
||||
internal static class ExtensionMethods
|
||||
{
|
||||
#region IPolygon extensions
|
||||
|
||||
/// <summary>
|
||||
/// Triangulates a polygon.
|
||||
/// </summary>
|
||||
internal static IMesh Triangulate(this IPolygon polygon)
|
||||
{
|
||||
return (new GenericMesher()).Triangulate(polygon, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triangulates a polygon, applying constraint options.
|
||||
/// </summary>
|
||||
/// <param name="options">Constraint options.</param>
|
||||
internal static IMesh Triangulate(this IPolygon polygon, ConstraintOptions options)
|
||||
{
|
||||
return (new GenericMesher()).Triangulate(polygon, options, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triangulates a polygon, applying quality options.
|
||||
/// </summary>
|
||||
/// <param name="quality">Quality options.</param>
|
||||
internal static IMesh Triangulate(this IPolygon polygon, QualityOptions quality)
|
||||
{
|
||||
return (new GenericMesher()).Triangulate(polygon, null, quality);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triangulates a polygon, applying quality and constraint options.
|
||||
/// </summary>
|
||||
/// <param name="options">Constraint options.</param>
|
||||
/// <param name="quality">Quality options.</param>
|
||||
internal static IMesh Triangulate(this IPolygon polygon, ConstraintOptions options, QualityOptions quality)
|
||||
{
|
||||
return (new GenericMesher()).Triangulate(polygon, options, quality);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triangulates a polygon, applying quality and constraint options.
|
||||
/// </summary>
|
||||
/// <param name="options">Constraint options.</param>
|
||||
/// <param name="quality">Quality options.</param>
|
||||
/// <param name="triangulator">The triangulation algorithm.</param>
|
||||
internal static IMesh Triangulate(this IPolygon polygon, ConstraintOptions options, QualityOptions quality,
|
||||
ITriangulator triangulator)
|
||||
{
|
||||
return (new GenericMesher(triangulator)).Triangulate(polygon, options, quality);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Rectangle extensions
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITriangle extensions
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a given point lies inside a triangle or not.
|
||||
/// </summary>
|
||||
/// <param name="p">Point to locate.</param>
|
||||
/// <returns>True, if point is inside or on the edge of this triangle.</returns>
|
||||
internal static bool Contains(this ITriangle triangle, Point p)
|
||||
{
|
||||
return Contains(triangle, p.X, p.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a given point lies inside a triangle or not.
|
||||
/// </summary>
|
||||
/// <param name="x">Point to locate.</param>
|
||||
/// <param name="y">Point to locate.</param>
|
||||
/// <returns>True, if point is inside or on the edge of this triangle.</returns>
|
||||
internal static bool Contains(this ITriangle triangle, double x, double y)
|
||||
{
|
||||
var t0 = triangle.GetVertex(0);
|
||||
var t1 = triangle.GetVertex(1);
|
||||
var t2 = triangle.GetVertex(2);
|
||||
|
||||
// TODO: no need to create new Point instances here
|
||||
Point d0 = new Point(t1.X - t0.X, t1.Y - t0.Y);
|
||||
Point d1 = new Point(t2.X - t0.X, t2.Y - t0.Y);
|
||||
Point d2 = new Point(x - t0.X, y - t0.Y);
|
||||
|
||||
// crossproduct of (0, 0, 1) and d0
|
||||
Point c0 = new Point(-d0.Y, d0.X);
|
||||
|
||||
// crossproduct of (0, 0, 1) and d1
|
||||
Point c1 = new Point(-d1.Y, d1.X);
|
||||
|
||||
// Linear combination d2 = s * d0 + v * d1.
|
||||
//
|
||||
// Multiply both sides of the equation with c0 and c1
|
||||
// and solve for s and v respectively
|
||||
//
|
||||
// s = d2 * c1 / d0 * c1
|
||||
// v = d2 * c0 / d1 * c0
|
||||
|
||||
double s = DotProduct(d2, c1) / DotProduct(d0, c1);
|
||||
double v = DotProduct(d2, c0) / DotProduct(d1, c0);
|
||||
|
||||
if (s >= 0 && v >= 0 && ((s + v) <= 1))
|
||||
{
|
||||
// Point is inside or on the edge of this triangle.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static Rectangle Bounds(this ITriangle triangle)
|
||||
{
|
||||
var bounds = new Rectangle();
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
bounds.Expand(triangle.GetVertex(i));
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper methods
|
||||
|
||||
internal static double DotProduct(Point p, Point q)
|
||||
{
|
||||
return p.X * q.X + p.Y * q.Y;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5756a98707df6417ba9135ea9d4f857e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,30 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="IEdge.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
internal interface IEdge
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the first endpoints index.
|
||||
/// </summary>
|
||||
int P0 { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the second endpoints index.
|
||||
/// </summary>
|
||||
int P1 { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a general-purpose label.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is used for the segments boundary mark.
|
||||
/// </remarks>
|
||||
int Label { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ac8497ccdcaa24180924e889b9d7b7d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,94 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="IPolygon.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Polygon interface.
|
||||
/// </summary>
|
||||
internal interface IPolygon
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the vertices of the polygon.
|
||||
/// </summary>
|
||||
List<Vertex> Points { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the segments of the polygon.
|
||||
/// </summary>
|
||||
List<ISegment> Segments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of points defining the holes of the polygon.
|
||||
/// </summary>
|
||||
List<Point> Holes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of pointers defining the regions of the polygon.
|
||||
/// </summary>
|
||||
List<RegionPointer> Regions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the vertices have marks or not.
|
||||
/// </summary>
|
||||
bool HasPointMarkers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the segments have marks or not.
|
||||
/// </summary>
|
||||
bool HasSegmentMarkers { get; set; }
|
||||
|
||||
[Obsolete("Use polygon.Add(contour) method instead.")]
|
||||
void AddContour(IEnumerable<Vertex> points, int marker, bool hole, bool convex);
|
||||
|
||||
[Obsolete("Use polygon.Add(contour) method instead.")]
|
||||
void AddContour(IEnumerable<Vertex> points, int marker, Point hole);
|
||||
|
||||
/// <summary>
|
||||
/// Compute the bounds of the polygon.
|
||||
/// </summary>
|
||||
/// <returns>Rectangle defining an axis-aligned bounding box.</returns>
|
||||
Rectangle Bounds();
|
||||
|
||||
/// <summary>
|
||||
/// Add a vertex to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="vertex">The vertex to insert.</param>
|
||||
void Add(Vertex vertex);
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="insert">If true, both endpoints will be added to the points list.</param>
|
||||
void Add(ISegment segment, bool insert = false);
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="index">The index of the segment endpoint to add to the points list (must be 0 or 1).</param>
|
||||
void Add(ISegment segment, int index);
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Treat contour as a hole.</param>
|
||||
void Add(Contour contour, bool hole = false);
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Point inside the contour, making it a hole.</param>
|
||||
void Add(Contour contour, Point hole);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 68c59424e0fae433b9a2957e751fb25f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,27 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="ISegment.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for segment geometry.
|
||||
/// </summary>
|
||||
internal interface ISegment : IEdge
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the vertex at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0 or 1).</param>
|
||||
Vertex GetVertex(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an adjoining triangle.
|
||||
/// </summary>
|
||||
/// <param name="index">The triangle index (0 or 1).</param>
|
||||
ITriangle GetTriangle(int index);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9132cd52e337145a7a84643de287a066
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,70 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="ITriangle.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using Animation.TriangleNet.Topology;
|
||||
|
||||
/// <summary>
|
||||
/// Triangle interface.
|
||||
/// </summary>
|
||||
internal interface ITriangle
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the triangle ID.
|
||||
/// </summary>
|
||||
int ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a general-purpose label.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is used for region information.
|
||||
/// </remarks>
|
||||
int Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the triangle area constraint.
|
||||
/// </summary>
|
||||
double Area { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertex at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0, 1 or 2).</param>
|
||||
/// <returns>The vertex.</returns>
|
||||
Vertex GetVertex(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the vertex at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0, 1 or 2).</param>
|
||||
/// <returns>The vertex ID.</returns>
|
||||
int GetVertexID(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the neighbor triangle at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0, 1 or 2).</param>
|
||||
/// <returns>The neighbor triangle.</returns>
|
||||
ITriangle GetNeighbor(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the neighbor triangle at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0, 1 or 2).</param>
|
||||
/// <returns>The neighbor triangle ID.</returns>
|
||||
int GetNeighborID(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the segment at given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The local index (0, 1 or 2).</param>
|
||||
/// <returns>The segment.</returns>
|
||||
ISegment GetSegment(int index);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c2817c735e6d4f80867fba95274f386
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,181 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Point.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a 2D point.
|
||||
/// </summary>
|
||||
#if USE_Z
|
||||
[DebuggerDisplay("ID {ID} [{X}, {Y}, {Z}]")]
|
||||
#else
|
||||
[DebuggerDisplay("ID {ID} [{X}, {Y}]")]
|
||||
#endif
|
||||
internal class Point : IComparable<Point>, IEquatable<Point>
|
||||
{
|
||||
internal int id;
|
||||
internal int label;
|
||||
|
||||
internal double x;
|
||||
internal double y;
|
||||
#if USE_Z
|
||||
internal double z;
|
||||
#endif
|
||||
|
||||
public Point()
|
||||
: this(0.0, 0.0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Point(double x, double y)
|
||||
: this(x, y, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public Point(double x, double y, int label)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
#region Public properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vertex id.
|
||||
/// </summary>
|
||||
public int ID
|
||||
{
|
||||
get { return this.id; }
|
||||
set { this.id = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vertex x coordinate.
|
||||
/// </summary>
|
||||
public double X
|
||||
{
|
||||
get { return this.x; }
|
||||
set { this.x = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vertex y coordinate.
|
||||
/// </summary>
|
||||
public double Y
|
||||
{
|
||||
get { return this.y; }
|
||||
set { this.y = value; }
|
||||
}
|
||||
|
||||
#if USE_Z
|
||||
/// <summary>
|
||||
/// Gets or sets the vertex z coordinate.
|
||||
/// </summary>
|
||||
public double Z
|
||||
{
|
||||
get { return this.z; }
|
||||
set { this.z = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a general-purpose label.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is used for the vertex boundary mark.
|
||||
/// </remarks>
|
||||
public int Label
|
||||
{
|
||||
get { return this.label; }
|
||||
set { this.label = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operator overloading / overriding Equals
|
||||
|
||||
// Compare "Guidelines for Overriding Equals() and Operator =="
|
||||
// http://msdn.microsoft.com/en-us/library/ms173147.aspx
|
||||
|
||||
public static bool operator==(Point a, Point b)
|
||||
{
|
||||
// If both are null, or both are same instance, return true.
|
||||
if (Object.ReferenceEquals(a, b))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If one is null, but not both, return false.
|
||||
if (((object)a == null) || ((object)b == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator!=(Point a, Point b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
// If parameter is null return false.
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Point p = obj as Point;
|
||||
|
||||
if ((object)p == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (x == p.x) && (y == p.y);
|
||||
}
|
||||
|
||||
public bool Equals(Point p)
|
||||
{
|
||||
// If vertex is null return false.
|
||||
if ((object)p == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true if the fields match:
|
||||
return (x == p.x) && (y == p.y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public int CompareTo(Point other)
|
||||
{
|
||||
if (x == other.x && y == other.y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (x < other.x || (x == other.x && y < other.y)) ? -1 : 1;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = 19;
|
||||
hash = hash * 31 + x.GetHashCode();
|
||||
hash = hash * 31 + y.GetHashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07d9e02d256864a01916e9533af15bca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,185 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Polygon.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// A polygon represented as a planar straight line graph.
|
||||
/// </summary>
|
||||
internal class Polygon : IPolygon
|
||||
{
|
||||
List<Vertex> points;
|
||||
List<Point> holes;
|
||||
List<RegionPointer> regions;
|
||||
|
||||
List<ISegment> segments;
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Vertex> Points
|
||||
{
|
||||
get { return points; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<Point> Holes
|
||||
{
|
||||
get { return holes; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<RegionPointer> Regions
|
||||
{
|
||||
get { return regions; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public List<ISegment> Segments
|
||||
{
|
||||
get { return segments; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasPointMarkers { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasSegmentMarkers { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count
|
||||
{
|
||||
get { return points.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Polygon" /> class.
|
||||
/// </summary>
|
||||
public Polygon()
|
||||
: this(3, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Polygon" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The default capacity for the points list.</param>
|
||||
public Polygon(int capacity)
|
||||
: this(3, false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Polygon" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The default capacity for the points list.</param>
|
||||
/// <param name="markers">Use point and segment markers.</param>
|
||||
public Polygon(int capacity, bool markers)
|
||||
{
|
||||
points = new List<Vertex>(capacity);
|
||||
holes = new List<Point>();
|
||||
regions = new List<RegionPointer>();
|
||||
|
||||
segments = new List<ISegment>();
|
||||
|
||||
HasPointMarkers = markers;
|
||||
HasSegmentMarkers = markers;
|
||||
}
|
||||
|
||||
[Obsolete("Use polygon.Add(contour) method instead.")]
|
||||
public void AddContour(IEnumerable<Vertex> points, int marker = 0,
|
||||
bool hole = false, bool convex = false)
|
||||
{
|
||||
this.Add(new Contour(points, marker, convex), hole);
|
||||
}
|
||||
|
||||
[Obsolete("Use polygon.Add(contour) method instead.")]
|
||||
public void AddContour(IEnumerable<Vertex> points, int marker, Point hole)
|
||||
{
|
||||
this.Add(new Contour(points, marker), hole);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rectangle Bounds()
|
||||
{
|
||||
var bounds = new Rectangle();
|
||||
bounds.Expand(this.points.Cast<Point>());
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a vertex to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="vertex">The vertex to insert.</param>
|
||||
public void Add(Vertex vertex)
|
||||
{
|
||||
this.points.Add(vertex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="insert">If true, both endpoints will be added to the points list.</param>
|
||||
public void Add(ISegment segment, bool insert = false)
|
||||
{
|
||||
this.segments.Add(segment);
|
||||
|
||||
if (insert)
|
||||
{
|
||||
this.points.Add(segment.GetVertex(0));
|
||||
this.points.Add(segment.GetVertex(1));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a segment to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="segment">The segment to insert.</param>
|
||||
/// <param name="index">The index of the segment endpoint to add to the points list (must be 0 or 1).</param>
|
||||
public void Add(ISegment segment, int index)
|
||||
{
|
||||
this.segments.Add(segment);
|
||||
|
||||
this.points.Add(segment.GetVertex(index));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Treat contour as a hole.</param>
|
||||
public void Add(Contour contour, bool hole = false)
|
||||
{
|
||||
if (hole)
|
||||
{
|
||||
this.Add(contour, contour.FindInteriorPoint());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.points.AddRange(contour.Points);
|
||||
this.segments.AddRange(contour.GetSegments());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a contour to the polygon.
|
||||
/// </summary>
|
||||
/// <param name="contour">The contour to insert.</param>
|
||||
/// <param name="hole">Point inside the contour, making it a hole.</param>
|
||||
public void Add(Contour contour, Point hole)
|
||||
{
|
||||
this.points.AddRange(contour.Points);
|
||||
this.segments.AddRange(contour.GetSegments());
|
||||
|
||||
this.holes.Add(hole);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7eb2e763592fc45778f3a2f7718c12fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,190 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Rectangle.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// A simple rectangle class.
|
||||
/// </summary>
|
||||
internal class Rectangle
|
||||
{
|
||||
double xmin, ymin, xmax, ymax;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rectangle" /> class.
|
||||
/// </summary>
|
||||
public Rectangle()
|
||||
{
|
||||
this.xmin = this.ymin = double.MaxValue;
|
||||
this.xmax = this.ymax = -double.MaxValue;
|
||||
}
|
||||
|
||||
public Rectangle(Rectangle other)
|
||||
: this(other.Left, other.Bottom, other.Right, other.Top)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Rectangle" /> class
|
||||
/// with predefined bounds.
|
||||
/// </summary>
|
||||
/// <param name="x">Minimum x value (left).</param>
|
||||
/// <param name="y">Minimum y value (bottom).</param>
|
||||
/// <param name="width">Width of the rectangle.</param>
|
||||
/// <param name="height">Height of the rectangle.</param>
|
||||
public Rectangle(double x, double y, double width, double height)
|
||||
{
|
||||
this.xmin = x;
|
||||
this.ymin = y;
|
||||
this.xmax = x + width;
|
||||
this.ymax = y + height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum x value (left boundary).
|
||||
/// </summary>
|
||||
public double Left
|
||||
{
|
||||
get { return xmin; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum x value (right boundary).
|
||||
/// </summary>
|
||||
public double Right
|
||||
{
|
||||
get { return xmax; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minimum y value (bottom boundary).
|
||||
/// </summary>
|
||||
public double Bottom
|
||||
{
|
||||
get { return ymin; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum y value (top boundary).
|
||||
/// </summary>
|
||||
public double Top
|
||||
{
|
||||
get { return ymax; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the rectangle.
|
||||
/// </summary>
|
||||
public double Width
|
||||
{
|
||||
get { return xmax - xmin; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the rectangle.
|
||||
/// </summary>
|
||||
public double Height
|
||||
{
|
||||
get { return ymax - ymin; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update bounds.
|
||||
/// </summary>
|
||||
/// <param name="dx">Add dx to left and right bounds.</param>
|
||||
/// <param name="dy">Add dy to top and bottom bounds.</param>
|
||||
public void Resize(double dx, double dy)
|
||||
{
|
||||
xmin -= dx;
|
||||
xmax += dx;
|
||||
ymin -= dy;
|
||||
ymax += dy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expand rectangle to include given point.
|
||||
/// </summary>
|
||||
/// <param name="p">Point.</param>
|
||||
public void Expand(Point p)
|
||||
{
|
||||
xmin = Math.Min(xmin, p.x);
|
||||
ymin = Math.Min(ymin, p.y);
|
||||
xmax = Math.Max(xmax, p.x);
|
||||
ymax = Math.Max(ymax, p.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expand rectangle to include a list of points.
|
||||
/// </summary>
|
||||
public void Expand(IEnumerable<Point> points)
|
||||
{
|
||||
foreach (var p in points)
|
||||
{
|
||||
Expand(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expand rectangle to include given rectangle.
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate.</param>
|
||||
/// <param name="y">Y coordinate.</param>
|
||||
public void Expand(Rectangle other)
|
||||
{
|
||||
xmin = Math.Min(xmin, other.xmin);
|
||||
ymin = Math.Min(ymin, other.ymin);
|
||||
xmax = Math.Max(xmax, other.xmax);
|
||||
ymax = Math.Max(ymax, other.ymax);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given point is inside rectangle.
|
||||
/// </summary>
|
||||
/// <param name="x">Point to check.</param>
|
||||
/// <param name="y">Point to check.</param>
|
||||
/// <returns>Return true, if rectangle contains given point.</returns>
|
||||
public bool Contains(double x, double y)
|
||||
{
|
||||
return ((x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given point is inside rectangle.
|
||||
/// </summary>
|
||||
/// <param name="pt">Point to check.</param>
|
||||
/// <returns>Return true, if rectangle contains given point.</returns>
|
||||
public bool Contains(Point pt)
|
||||
{
|
||||
return Contains(pt.x, pt.y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if this rectangle contains other rectangle.
|
||||
/// </summary>
|
||||
/// <param name="other">Rectangle to check.</param>
|
||||
/// <returns>Return true, if this rectangle contains given rectangle.</returns>
|
||||
public bool Contains(Rectangle other)
|
||||
{
|
||||
return (xmin <= other.Left && other.Right <= xmax
|
||||
&& ymin <= other.Bottom && other.Top <= ymax);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if this rectangle intersects other rectangle.
|
||||
/// </summary>
|
||||
/// <param name="other">Rectangle to check.</param>
|
||||
/// <returns>Return true, if given rectangle intersects this rectangle.</returns>
|
||||
public bool Intersects(Rectangle other)
|
||||
{
|
||||
return (other.Left < xmax && xmin < other.Right
|
||||
&& other.Bottom < ymax && ymin < other.Top);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6dab3a6b0e864d71a92072b3d3224c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,64 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="RegionPointer.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Pointer to a region in the mesh geometry. A region is a well-defined
|
||||
/// subset of the geomerty (enclosed by subsegments).
|
||||
/// </summary>
|
||||
internal class RegionPointer
|
||||
{
|
||||
internal Point point;
|
||||
internal int id;
|
||||
internal double area;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a region area constraint.
|
||||
/// </summary>
|
||||
public double Area
|
||||
{
|
||||
get { return area; }
|
||||
set
|
||||
{
|
||||
if (value < 0.0)
|
||||
{
|
||||
throw new ArgumentException("Area constraints must not be negative.");
|
||||
}
|
||||
area = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegionPointer" /> class.
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the region.</param>
|
||||
/// <param name="y">Y coordinate of the region.</param>
|
||||
/// <param name="id">Region id.</param>
|
||||
public RegionPointer(double x, double y, int id)
|
||||
: this(x, y, id, 0.0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegionPointer" /> class.
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the region.</param>
|
||||
/// <param name="y">Y coordinate of the region.</param>
|
||||
/// <param name="id">Region id.</param>
|
||||
/// <param name="area">Area constraint.</param>
|
||||
public RegionPointer(double x, double y, int id, double area)
|
||||
{
|
||||
this.point = new Point(x, y);
|
||||
this.id = id;
|
||||
this.area = area;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5c8f0437817e84603a4785292a7e5242
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,93 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Segment.cs" company="">
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a straight line segment in 2D space.
|
||||
/// </summary>
|
||||
internal class Segment : ISegment
|
||||
{
|
||||
Vertex v0;
|
||||
Vertex v1;
|
||||
|
||||
int label;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the segments boundary mark.
|
||||
/// </summary>
|
||||
public int Label
|
||||
{
|
||||
get { return label; }
|
||||
set { label = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the first endpoints index.
|
||||
/// </summary>
|
||||
public int P0
|
||||
{
|
||||
get { return v0.id; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the second endpoints index.
|
||||
/// </summary>
|
||||
public int P1
|
||||
{
|
||||
get { return v1.id; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Segment" /> class.
|
||||
/// </summary>
|
||||
public Segment(Vertex v0, Vertex v1)
|
||||
: this(v0, v1, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Segment" /> class.
|
||||
/// </summary>
|
||||
public Segment(Vertex v0, Vertex v1, int label)
|
||||
{
|
||||
this.v0 = v0;
|
||||
this.v1 = v1;
|
||||
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified segment endpoint.
|
||||
/// </summary>
|
||||
/// <param name="index">The endpoint index (0 or 1).</param>
|
||||
/// <returns></returns>
|
||||
public Vertex GetVertex(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
return v0;
|
||||
}
|
||||
|
||||
if (index == 1)
|
||||
{
|
||||
return v1;
|
||||
}
|
||||
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WARNING: not implemented.
|
||||
/// </summary>
|
||||
public ITriangle GetTriangle(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64b0cc51c72d04973b2516dd2c8137b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,127 @@
|
|||
// -----------------------------------------------------------------------
|
||||
// <copyright file="Vertex.cs" company="">
|
||||
// Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html
|
||||
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
|
||||
// </copyright>
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace UnityEngine.U2D.Animation.TriangleNet
|
||||
.Geometry
|
||||
{
|
||||
using System;
|
||||
using Animation.TriangleNet.Topology;
|
||||
|
||||
/// <summary>
|
||||
/// The vertex data structure.
|
||||
/// </summary>
|
||||
internal class Vertex : Point
|
||||
{
|
||||
// Hash for dictionary. Will be set by mesh instance.
|
||||
internal int hash;
|
||||
|
||||
#if USE_ATTRIBS
|
||||
internal double[] attributes;
|
||||
#endif
|
||||
internal VertexType type;
|
||||
internal Otri tri;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Vertex" /> class.
|
||||
/// </summary>
|
||||
public Vertex()
|
||||
: this(0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Vertex" /> class.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the vertex.</param>
|
||||
/// <param name="y">The y coordinate of the vertex.</param>
|
||||
public Vertex(double x, double y)
|
||||
: this(x, y, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Vertex" /> class.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the vertex.</param>
|
||||
/// <param name="y">The y coordinate of the vertex.</param>
|
||||
/// <param name="mark">The boundary mark.</param>
|
||||
public Vertex(double x, double y, int mark)
|
||||
: base(x, y, mark)
|
||||
{
|
||||
this.type = VertexType.InputVertex;
|
||||
}
|
||||
|
||||
#if USE_ATTRIBS
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Vertex" /> class.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the vertex.</param>
|
||||
/// <param name="y">The y coordinate of the vertex.</param>
|
||||
/// <param name="mark">The boundary mark.</param>
|
||||
/// <param name="attribs">The number of point attributes.</param>
|
||||
public Vertex(double x, double y, int mark, int attribs)
|
||||
: this(x, y, mark)
|
||||
{
|
||||
if (attribs > 0)
|
||||
{
|
||||
this.attributes = new double[attribs];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#region Public properties
|
||||
|
||||
#if USE_ATTRIBS
|
||||
/// <summary>
|
||||
/// Gets the vertex attributes (may be null).
|
||||
/// </summary>
|
||||
public double[] Attributes
|
||||
{
|
||||
get { return this.attributes; }
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertex type.
|
||||
/// </summary>
|
||||
public VertexType Type
|
||||
{
|
||||
get { return this.type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified coordinate of the vertex.
|
||||
/// </summary>
|
||||
/// <param name="i">Coordinate index.</param>
|
||||
/// <returns>X coordinate, if index is 0, Y coordinate, if index is 1.</returns>
|
||||
public double this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException("Index must be 0 or 1.");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.hash;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 32c23f1f2292142599f01204e68664c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue