// ----------------------------------------------------------------------- // // 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/ // // ----------------------------------------------------------------------- namespace UnityEngine.U2D.Animation.TriangleNet { using System; using Animation.TriangleNet.Geometry; /// /// Controls the behavior of the meshing software. /// class Behavior { bool poly = false; bool quality = false; bool varArea = false; bool convex = false; bool jettison = false; bool boundaryMarkers = true; bool noHoles = false; bool conformDel = false; Func usertest; int noBisect = 0; double minAngle = 0.0; double maxAngle = 0.0; double maxArea = -1.0; internal bool fixedArea = false; internal bool useSegments = true; internal bool useRegions = false; internal double goodAngle = 0.0; internal double maxGoodAngle = 0.0; internal double offconstant = 0.0; /// /// Creates an instance of the Behavior class. /// public Behavior(bool quality = false, double minAngle = 20.0) { if (quality) { this.quality = true; this.minAngle = minAngle; Update(); } } /// /// Update quality options dependencies. /// private void Update() { this.quality = true; if (this.minAngle < 0 || this.minAngle > 60) { this.minAngle = 0; this.quality = false; Log.Instance.Warning("Invalid quality option (minimum angle).", "Mesh.Behavior"); } if ((this.maxAngle != 0.0) && (this.maxAngle < 60 || this.maxAngle > 180)) { this.maxAngle = 0; this.quality = false; Log.Instance.Warning("Invalid quality option (maximum angle).", "Mesh.Behavior"); } this.useSegments = this.Poly || this.Quality || this.Convex; this.goodAngle = Math.Cos(this.MinAngle * Math.PI / 180.0); this.maxGoodAngle = Math.Cos(this.MaxAngle * Math.PI / 180.0); if (this.goodAngle == 1.0) { this.offconstant = 0.0; } else { this.offconstant = 0.475 * Math.Sqrt((1.0 + this.goodAngle) / (1.0 - this.goodAngle)); } this.goodAngle *= this.goodAngle; } #region Static properties /// /// No exact arithmetic. /// internal static bool NoExact { get; set; } #endregion #region Public properties /// /// Quality mesh generation. /// public bool Quality { get { return quality; } set { quality = value; if (quality) { Update(); } } } /// /// Minimum angle constraint. /// public double MinAngle { get { return minAngle; } set { minAngle = value; Update(); } } /// /// Maximum angle constraint. /// public double MaxAngle { get { return maxAngle; } set { maxAngle = value; Update(); } } /// /// Maximum area constraint. /// public double MaxArea { get { return maxArea; } set { maxArea = value; fixedArea = value > 0.0; } } /// /// Apply a maximum triangle area constraint. /// public bool VarArea { get { return varArea; } set { varArea = value; } } /// /// Input is a Planar Straight Line Graph. /// public bool Poly { get { return poly; } set { poly = value; } } /// /// Apply a user-defined triangle constraint. /// public Func UserTest { get { return usertest; } set { usertest = value; } } /// /// Enclose the convex hull with segments. /// public bool Convex { get { return convex; } set { convex = value; } } /// /// Conforming Delaunay (all triangles are truly Delaunay). /// public bool ConformingDelaunay { get { return conformDel; } set { conformDel = value; } } /// /// Suppresses boundary segment splitting. /// /// /// 0 = split segments /// 1 = no new vertices on the boundary /// 2 = prevent all segment splitting, including internal boundaries /// public int NoBisect { get { return noBisect; } set { noBisect = value; if (noBisect < 0 || noBisect > 2) { noBisect = 0; } } } /// /// Compute boundary information. /// public bool UseBoundaryMarkers { get { return boundaryMarkers; } set { boundaryMarkers = value; } } /// /// Ignores holes in polygons. /// public bool NoHoles { get { return noHoles; } set { noHoles = value; } } /// /// Jettison unused vertices from output. /// public bool Jettison { get { return jettison; } set { jettison = value; } } #endregion } }