feat: Initial commit
This commit is contained in:
137
Assets/Plugins/Poly2Tri/Utility/FixedArray3.cs
Normal file
137
Assets/Plugins/Poly2Tri/Utility/FixedArray3.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
/* Poly2Tri
|
||||
* Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Poly2Tri
|
||||
{
|
||||
public struct FixedArray3<T> : IEnumerable<T> where T : class
|
||||
{
|
||||
public T _0, _1, _2;
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return _0;
|
||||
case 1:
|
||||
return _1;
|
||||
case 2:
|
||||
return _2;
|
||||
default:
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
_0 = value;
|
||||
break;
|
||||
case 1:
|
||||
_1 = value;
|
||||
break;
|
||||
case 2:
|
||||
_2 = value;
|
||||
break;
|
||||
default:
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool Contains(T value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] != null && this[i].Equals(value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int IndexOf(T value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] != null && this[i].Equals(value))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_0 = _1 = _2 = null;
|
||||
}
|
||||
|
||||
|
||||
public void Clear(T value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] != null && this[i].Equals(value))
|
||||
{
|
||||
this[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<T> Enumerate()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator<T> GetEnumerator() { return Enumerate().GetEnumerator(); }
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||
}
|
||||
}
|
11
Assets/Plugins/Poly2Tri/Utility/FixedArray3.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/FixedArray3.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d981e23ca4f5ac84e8ca45f87420f90a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
137
Assets/Plugins/Poly2Tri/Utility/FixedBitArray3.cs
Normal file
137
Assets/Plugins/Poly2Tri/Utility/FixedBitArray3.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
/* Poly2Tri
|
||||
* Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Poly2Tri
|
||||
{
|
||||
public struct FixedBitArray3 : IEnumerable<bool>
|
||||
{
|
||||
public bool _0, _1, _2;
|
||||
public bool this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return _0;
|
||||
case 1:
|
||||
return _1;
|
||||
case 2:
|
||||
return _2;
|
||||
default:
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
_0 = value;
|
||||
break;
|
||||
case 1:
|
||||
_1 = value;
|
||||
break;
|
||||
case 2:
|
||||
_2 = value;
|
||||
break;
|
||||
default:
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool Contains(bool value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] == value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public int IndexOf(bool value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] == value)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_0 = _1 = _2 = false;
|
||||
}
|
||||
|
||||
|
||||
public void Clear(bool value)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (this[i] == value)
|
||||
{
|
||||
this[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<bool> Enumerate()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator<bool> GetEnumerator() { return Enumerate().GetEnumerator(); }
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||
}
|
||||
}
|
11
Assets/Plugins/Poly2Tri/Utility/FixedBitArray3.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/FixedBitArray3.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd393331db7c67b4583d7563f1ecd0ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
91
Assets/Plugins/Poly2Tri/Utility/MathUtil.cs
Normal file
91
Assets/Plugins/Poly2Tri/Utility/MathUtil.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Poly2Tri
|
||||
{
|
||||
public class MathUtil
|
||||
{
|
||||
public static double EPSILON = 1e-12;
|
||||
|
||||
|
||||
public static bool AreValuesEqual(double val1, double val2)
|
||||
{
|
||||
return AreValuesEqual(val1, val2, EPSILON);
|
||||
}
|
||||
|
||||
|
||||
public static bool AreValuesEqual(double val1, double val2, double tolerance)
|
||||
{
|
||||
if (val1 >= (val2 - tolerance) && val1 <= (val2 + tolerance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsValueBetween(double val, double min, double max, double tolerance)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
double tmp = min;
|
||||
min = max;
|
||||
max = tmp;
|
||||
}
|
||||
if ((val + tolerance) >= min && (val - tolerance) <= max)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static double RoundWithPrecision(double f, double precision)
|
||||
{
|
||||
if (precision < 0.0)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
double mul = Math.Pow(10.0, precision);
|
||||
double fTemp = Math.Floor(f * mul) / mul;
|
||||
|
||||
return fTemp;
|
||||
}
|
||||
|
||||
|
||||
public static double Clamp(double a, double low, double high)
|
||||
{
|
||||
return Math.Max(low, Math.Min(a, high));
|
||||
}
|
||||
|
||||
|
||||
public static void Swap<T>(ref T a, ref T b)
|
||||
{
|
||||
T tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
|
||||
public static uint Jenkins32Hash(byte[] data, uint nInitialValue)
|
||||
{
|
||||
foreach (byte b in data)
|
||||
{
|
||||
nInitialValue += (uint)b;
|
||||
nInitialValue += (nInitialValue << 10);
|
||||
nInitialValue += (nInitialValue >> 6);
|
||||
}
|
||||
|
||||
nInitialValue += (nInitialValue << 3);
|
||||
nInitialValue ^= (nInitialValue >> 11);
|
||||
nInitialValue += (nInitialValue << 15);
|
||||
|
||||
return nInitialValue;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Plugins/Poly2Tri/Utility/MathUtil.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/MathUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d6dd55f740849b41994d1d937652e56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
262
Assets/Plugins/Poly2Tri/Utility/Point2D.cs
Normal file
262
Assets/Plugins/Poly2Tri/Utility/Point2D.cs
Normal file
@@ -0,0 +1,262 @@
|
||||
/* Poly2Tri
|
||||
* Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace Poly2Tri
|
||||
{
|
||||
public class Point2D : IComparable<Point2D>
|
||||
{
|
||||
protected double mX = 0.0;
|
||||
public virtual double X { get { return mX; } set { mX = value; } }
|
||||
protected double mY = 0.0;
|
||||
public virtual double Y { get { return mY; } set { mY = value; } }
|
||||
|
||||
public float Xf { get { return (float)X; } }
|
||||
public float Yf { get { return (float)Y; } }
|
||||
|
||||
|
||||
public Point2D()
|
||||
{
|
||||
mX = 0.0;
|
||||
mY = 0.0;
|
||||
}
|
||||
|
||||
|
||||
public Point2D(double x, double y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
|
||||
public Point2D(Point2D p)
|
||||
{
|
||||
mX = p.X;
|
||||
mY = p.Y;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "[" + X.ToString() + "," + Y.ToString() + "]";
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(Object obj)
|
||||
{
|
||||
Point2D p = obj as Point2D;
|
||||
if (p != null)
|
||||
{
|
||||
return Equals(p);
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(Point2D p)
|
||||
{
|
||||
return Equals(p, 0.0);
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(Point2D p, double epsilon)
|
||||
{
|
||||
if ((object)p == null || !MathUtil.AreValuesEqual(X, p.X, epsilon) || !MathUtil.AreValuesEqual(Y, p.Y, epsilon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int CompareTo(Point2D other)
|
||||
{
|
||||
if (Y < other.Y)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (Y > other.Y)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (X < other.X)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (X > other.X)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public virtual void Set(double x, double y) { X = x; Y = y; }
|
||||
public virtual void Set(Point2D p) { X = p.X; Y = p.Y; }
|
||||
|
||||
public void Add(Point2D p) { X += p.X; Y += p.Y; }
|
||||
public void Add(double scalar) { X += scalar; Y += scalar; }
|
||||
public void Subtract(Point2D p) { X -= p.X; Y -= p.Y; }
|
||||
public void Subtract(double scalar) { X -= scalar; Y -= scalar; }
|
||||
public void Multiply(Point2D p) { X *= p.X; Y *= p.Y; }
|
||||
public void Multiply(double scalar) { X *= scalar; Y *= scalar; }
|
||||
public void Divide(Point2D p) { X /= p.X; Y /= p.Y; }
|
||||
public void Divide(double scalar) { X /= scalar; Y /= scalar; }
|
||||
public void Negate() { X = -X; Y = -Y; }
|
||||
public double Magnitude() { return Math.Sqrt((X * X) + (Y * Y)); }
|
||||
public double MagnitudeSquared() { return (X * X) + (Y * Y); }
|
||||
public double MagnitudeReciprocal() { return 1.0 / Magnitude(); }
|
||||
public void Normalize() { Multiply(MagnitudeReciprocal()); }
|
||||
public double Dot(Point2D p) { return (X * p.X) + (Y * p.Y); }
|
||||
public double Cross(Point2D p) { return (X * p.Y) - (Y * p.X); }
|
||||
public void Clamp(Point2D low, Point2D high) { X = Math.Max(low.X, Math.Min(X, high.X)); Y = Math.Max(low.Y, Math.Min(Y, high.Y)); }
|
||||
public void Abs() { X = Math.Abs(X); Y = Math.Abs(Y); }
|
||||
public void Reciprocal() { if (X != 0.0 && Y != 0.0) { X = 1.0 / X; Y = 1.0 / Y; } }
|
||||
|
||||
public void Translate(Point2D vector) { Add(vector); }
|
||||
public void Translate(double x, double y) { X += x; Y += y; }
|
||||
public void Scale(Point2D vector) { Multiply(vector); }
|
||||
public void Scale(double scalar) { Multiply(scalar); }
|
||||
public void Scale(double x, double y) { X *= x; Y *= y; }
|
||||
public void Rotate(double radians)
|
||||
{
|
||||
double cosr = Math.Cos(radians);
|
||||
double sinr = Math.Sin(radians);
|
||||
double xold = X;
|
||||
double yold = Y;
|
||||
X = (xold * cosr) - (yold * sinr);
|
||||
Y = (xold * sinr) + (yold * cosr);
|
||||
}
|
||||
public void RotateDegrees(double degrees)
|
||||
{
|
||||
double radians = degrees * Math.PI / 180.0;
|
||||
Rotate(radians);
|
||||
}
|
||||
|
||||
public static double Dot(Point2D lhs, Point2D rhs) { return (lhs.X * rhs.X) + (lhs.Y * rhs.Y); }
|
||||
public static double Cross(Point2D lhs, Point2D rhs) { return (lhs.X * rhs.Y) - (lhs.Y * rhs.X); }
|
||||
public static Point2D Clamp(Point2D a, Point2D low, Point2D high) { Point2D p = new Point2D(a); p.Clamp(low, high); return p; }
|
||||
public static Point2D Min(Point2D a, Point2D b) { Point2D p = new Point2D(); p.X = Math.Min(a.X, b.X); p.Y = Math.Min(a.Y, b.Y); return p; }
|
||||
public static Point2D Max(Point2D a, Point2D b) { Point2D p = new Point2D(); p.X = Math.Max(a.X, b.X); p.Y = Math.Max(a.Y, b.Y); return p; }
|
||||
public static Point2D Abs(Point2D a) { Point2D p = new Point2D(Math.Abs(a.X), Math.Abs(a.Y)); return p; }
|
||||
public static Point2D Reciprocal(Point2D a) { Point2D p = new Point2D(1.0 / a.X, 1.0 / a.Y); return p; }
|
||||
|
||||
// returns a scaled perpendicular vector. Which direction it goes depends on the order in which the arguments are passed
|
||||
public static Point2D Perpendicular(Point2D lhs, double scalar) { Point2D p = new Point2D(lhs.Y * scalar, lhs.X * -scalar); return p; }
|
||||
public static Point2D Perpendicular(double scalar, Point2D rhs) { Point2D p = new Point2D(-scalar * rhs.Y, scalar * rhs.X); return p; }
|
||||
|
||||
|
||||
//
|
||||
// operator overloading
|
||||
//
|
||||
|
||||
// Binary Operators
|
||||
// Note that in C#, when a binary operator is overloaded, its corresponding compound assignment operator is also automatically
|
||||
// overloaded. So, for example, overloading operator + implicitly overloads += as well
|
||||
public static Point2D operator +(Point2D lhs, Point2D rhs) { Point2D result = new Point2D(lhs); result.Add(rhs); return result; }
|
||||
public static Point2D operator +(Point2D lhs, double scalar) { Point2D result = new Point2D(lhs); result.Add(scalar); return result; }
|
||||
public static Point2D operator -(Point2D lhs, Point2D rhs) { Point2D result = new Point2D(lhs); result.Subtract(rhs); return result; }
|
||||
public static Point2D operator -(Point2D lhs, double scalar) { Point2D result = new Point2D(lhs); result.Subtract(scalar); return result; }
|
||||
public static Point2D operator *(Point2D lhs, Point2D rhs) { Point2D result = new Point2D(lhs); result.Multiply(rhs); return result; }
|
||||
public static Point2D operator *(Point2D lhs, double scalar) { Point2D result = new Point2D(lhs); result.Multiply(scalar); return result; }
|
||||
public static Point2D operator *(double scalar, Point2D lhs) { Point2D result = new Point2D(lhs); result.Multiply(scalar); return result; }
|
||||
public static Point2D operator /(Point2D lhs, Point2D rhs) { Point2D result = new Point2D(lhs); result.Divide(rhs); return result; }
|
||||
public static Point2D operator /(Point2D lhs, double scalar) { Point2D result = new Point2D(lhs); result.Divide(scalar); return result; }
|
||||
|
||||
// Unary Operators
|
||||
public static Point2D operator -(Point2D p) { Point2D tmp = new Point2D(p); tmp.Negate(); return tmp; }
|
||||
|
||||
// Relational Operators
|
||||
//public static bool operator ==(Point2D lhs, Point2D rhs) { if ((object)lhs != null) { return lhs.Equals(rhs, 0.0); } if ((object)rhs == null) { return true; } else { return false; } }
|
||||
//public static bool operator !=(Point2D lhs, Point2D rhs) { if ((object)lhs != null) { return !lhs.Equals(rhs, 0.0); } if ((object)rhs == null) { return false; } else { return true; } }
|
||||
public static bool operator <(Point2D lhs, Point2D rhs) { return (lhs.CompareTo(rhs) == -1) ? true : false; }
|
||||
public static bool operator >(Point2D lhs, Point2D rhs) { return (lhs.CompareTo(rhs) == 1) ? true : false; }
|
||||
public static bool operator <=(Point2D lhs, Point2D rhs) { return (lhs.CompareTo(rhs) <= 0) ? true : false; }
|
||||
public static bool operator >=(Point2D lhs, Point2D rhs) { return (lhs.CompareTo(rhs) >= 0) ? true : false; }
|
||||
}
|
||||
|
||||
|
||||
public class Point2DEnumerator : IEnumerator<Point2D>
|
||||
{
|
||||
protected IList<Point2D> mPoints;
|
||||
protected int position = -1; // Enumerators are positioned before the first element until the first MoveNext() call.
|
||||
|
||||
|
||||
public Point2DEnumerator(IList<Point2D> points)
|
||||
{
|
||||
mPoints = points;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
position++;
|
||||
return (position < mPoints.Count);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
position = -1;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose() { }
|
||||
|
||||
Object IEnumerator.Current { get { return Current; } }
|
||||
|
||||
public Point2D Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= mPoints.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return mPoints[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Plugins/Poly2Tri/Utility/Point2D.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/Point2D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6906e61511580494d946ed1a07dd0e82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1027
Assets/Plugins/Poly2Tri/Utility/Point2DList.cs
Normal file
1027
Assets/Plugins/Poly2Tri/Utility/Point2DList.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Assets/Plugins/Poly2Tri/Utility/Point2DList.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/Point2DList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd6f3a734edccfb4d912e7d1322c5d83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
321
Assets/Plugins/Poly2Tri/Utility/Rect2D.cs
Normal file
321
Assets/Plugins/Poly2Tri/Utility/Rect2D.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
/* Poly2Tri
|
||||
* Copyright (c) 2009-2010, Poly2Tri Contributors
|
||||
* http://code.google.com/p/poly2tri/
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
namespace Poly2Tri
|
||||
{
|
||||
public class Rect2D
|
||||
{
|
||||
private double mMinX; // left
|
||||
private double mMaxX; // right
|
||||
private double mMinY; // bottom // top
|
||||
private double mMaxY; // top // bottom
|
||||
|
||||
public double MinX { get { return mMinX; } set { mMinX = value; } }
|
||||
public double MaxX { get { return mMaxX; } set { mMaxX = value; } }
|
||||
public double MinY { get { return mMinY; } set { mMinY = value; } }
|
||||
public double MaxY { get { return mMaxY; } set { mMaxY = value; } }
|
||||
public double Left { get { return mMinX; } set { mMinX = value; } }
|
||||
public double Right { get { return mMaxX; } set { mMaxX = value; } }
|
||||
public double Top { get { return mMaxY; } set { mMaxY = value; } }
|
||||
public double Bottom { get { return mMinY; } set { mMinY = value; } }
|
||||
|
||||
public double Width { get { return (Right - Left); } }
|
||||
public double Height { get { return (Top - Bottom); } }
|
||||
public bool Empty { get { return (Left == Right) || (Top == Bottom); } }
|
||||
|
||||
|
||||
public Rect2D()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(Object obj)
|
||||
{
|
||||
Rect2D r = obj as Rect2D;
|
||||
if( r != null)
|
||||
{
|
||||
return Equals(r);
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(Rect2D r)
|
||||
{
|
||||
return Equals(r, MathUtil.EPSILON);
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(Rect2D r, double epsilon)
|
||||
{
|
||||
if (!MathUtil.AreValuesEqual(MinX, r.MinX, epsilon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MathUtil.AreValuesEqual(MaxX, r.MaxX))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MathUtil.AreValuesEqual(MinY, r.MinY, epsilon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!MathUtil.AreValuesEqual(MaxY, r.MaxY, epsilon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
MinX = Double.MaxValue;
|
||||
MaxX = Double.MinValue;
|
||||
MinY = Double.MaxValue;
|
||||
MaxY = Double.MinValue;
|
||||
}
|
||||
|
||||
|
||||
public void Set(double xmin, double xmax, double ymin, double ymax)
|
||||
{
|
||||
MinX = xmin;
|
||||
MaxX = xmax;
|
||||
MinY = ymin;
|
||||
MaxY = ymax;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
|
||||
public void Set(Rect2D b)
|
||||
{
|
||||
MinX = b.MinX;
|
||||
MaxX = b.MaxX;
|
||||
MinY = b.MinY;
|
||||
MaxY = b.MaxY;
|
||||
}
|
||||
|
||||
|
||||
public void SetSize(double w, double h)
|
||||
{
|
||||
Right = Left + w;
|
||||
Top = Bottom + h;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the coordinate is inside the bounding box. Note that this will return
|
||||
/// false if the point is ON the edge of the bounding box. If you want to test for whether
|
||||
/// the point is inside OR on the rect, use ContainsInclusive
|
||||
/// </summary>
|
||||
public bool Contains(double x, double y)
|
||||
{
|
||||
return (x > Left) && (y > Bottom) && (x < Right) && (y < Top);
|
||||
}
|
||||
public bool Contains(Point2D p) { return Contains(p.X, p.Y); }
|
||||
public bool Contains(Rect2D r)
|
||||
{
|
||||
return (Left < r.Left) && (Right > r.Right) && (Top < r.Top) && (Bottom > r.Bottom);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the coordinate is inside the bounding box. Note that this will return
|
||||
/// false if the point is ON the edge of the bounding box. If you want to test for whether
|
||||
/// the point is inside OR on the rect, use ContainsInclusive
|
||||
/// </summary>
|
||||
public bool ContainsInclusive(double x, double y)
|
||||
{
|
||||
return (x >= Left) && (y >= Top) && (x <= Right) && (y <= Bottom);
|
||||
}
|
||||
public bool ContainsInclusive(double x, double y, double epsilon)
|
||||
{
|
||||
return ((x + epsilon) >= Left) && ((y + epsilon) >= Top) && ((x - epsilon) <= Right) && ((y - epsilon) <= Bottom);
|
||||
}
|
||||
public bool ContainsInclusive(Point2D p) { return ContainsInclusive(p.X, p.Y); }
|
||||
public bool ContainsInclusive(Point2D p, double epsilon) { return ContainsInclusive(p.X, p.Y, epsilon); }
|
||||
public bool ContainsInclusive(Rect2D r)
|
||||
{
|
||||
return (Left <= r.Left) && (Right >= r.Right) && (Top <= r.Top) && (Bottom >= r.Bottom);
|
||||
}
|
||||
public bool ContainsInclusive(Rect2D r, double epsilon)
|
||||
{
|
||||
return ((Left - epsilon) <= r.Left) && ((Right + epsilon) >= r.Right) && ((Top - epsilon) <= r.Top) && ((Bottom + epsilon) >= r.Bottom);
|
||||
}
|
||||
|
||||
|
||||
public bool Intersects(Rect2D r)
|
||||
{
|
||||
return (Right > r.Left) &&
|
||||
(Left < r.Right) &&
|
||||
(Bottom < r.Top) &&
|
||||
(Top > r.Bottom);
|
||||
}
|
||||
|
||||
|
||||
public Point2D GetCenter()
|
||||
{
|
||||
Point2D p = new Point2D((Left + Right ) / 2, (Bottom + Top) / 2);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
public bool IsNormalized()
|
||||
{
|
||||
return (Right >= Left) && (Bottom <= Top);
|
||||
}
|
||||
|
||||
|
||||
public void Normalize()
|
||||
{
|
||||
if (Left > Right)
|
||||
{
|
||||
MathUtil.Swap<double>(ref mMinX, ref mMaxX);
|
||||
}
|
||||
|
||||
if (Bottom < Top)
|
||||
{
|
||||
MathUtil.Swap<double>(ref mMinY, ref mMaxY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddPoint(Point2D p)
|
||||
{
|
||||
MinX = Math.Min(MinX, p.X);
|
||||
MaxX = Math.Max(MaxX, p.X);
|
||||
MinY = Math.Min(MinY, p.Y);
|
||||
MaxY = Math.Max(MaxY, p.Y);
|
||||
}
|
||||
|
||||
|
||||
public void Inflate(double w, double h)
|
||||
{
|
||||
Left -= w;
|
||||
Top += h;
|
||||
Right += w;
|
||||
Bottom -= h;
|
||||
}
|
||||
|
||||
|
||||
public void Inflate(double left, double top, double right, double bottom)
|
||||
{
|
||||
Left -= left;
|
||||
Top += top;
|
||||
Right += right;
|
||||
Bottom -= bottom;
|
||||
}
|
||||
|
||||
|
||||
public void Offset(double w, double h)
|
||||
{
|
||||
Left += w;
|
||||
Top += h;
|
||||
Right += w;
|
||||
Bottom += h;
|
||||
}
|
||||
|
||||
|
||||
public void SetPosition(double x, double y)
|
||||
{
|
||||
double w = Right - Left;
|
||||
double h = Bottom - Top;
|
||||
Left = x;
|
||||
Bottom = y;
|
||||
Right = x + w;
|
||||
Top = y + h;
|
||||
}
|
||||
|
||||
|
||||
/// Intersection
|
||||
///
|
||||
/// Sets the rectangle to the intersection of two rectangles.
|
||||
/// Returns true if there is any intersection between the two rectangles.
|
||||
/// If there is no intersection, the rectangle is set to 0, 0, 0, 0.
|
||||
/// Either of the input rectangles may be the same as destination rectangle.
|
||||
///
|
||||
public bool Intersection(Rect2D r1, Rect2D r2)
|
||||
{
|
||||
if (!TriangulationUtil.RectsIntersect(r1, r2))
|
||||
{
|
||||
Left = Right = Top = Bottom = 0.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
Left = (r1.Left > r2.Left) ? r1.Left : r2.Left;
|
||||
Top = (r1.Top < r2.Top ) ? r1.Top : r2.Top;
|
||||
Right = (r1.Right < r2.Right) ? r1.Right : r2.Right;
|
||||
Bottom = (r1.Bottom > r2.Bottom) ? r1.Bottom : r2.Bottom;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// Union
|
||||
///
|
||||
/// Sets the rectangle to the union of two rectangles r1 and r2.
|
||||
/// If either rect is empty, it is ignored. If both are empty, the rectangle
|
||||
/// is set to r1.
|
||||
/// Either of the input rectangle references may refer to the destination rectangle.
|
||||
///
|
||||
public void Union(Rect2D r1, Rect2D r2)
|
||||
{
|
||||
if ((r2.Right == r2.Left) || (r2.Bottom == r2.Top))
|
||||
{
|
||||
Set(r1);
|
||||
}
|
||||
else if ((r1.Right == r1.Left) || (r1.Bottom == r1.Top))
|
||||
{
|
||||
Set(r2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Left = (r1.Left < r2.Left) ? r1.Left : r2.Left;
|
||||
Top = (r1.Top > r2.Top) ? r1.Top : r2.Top;
|
||||
Right = (r1.Right > r2.Right) ? r1.Right : r2.Right;
|
||||
Bottom = (r1.Bottom < r2.Bottom) ? r1.Bottom : r2.Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Plugins/Poly2Tri/Utility/Rect2D.cs.meta
Normal file
11
Assets/Plugins/Poly2Tri/Utility/Rect2D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d90c83ef75550a34b8be1b39c495defc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user