Example #1
0
        internal static void BuildTrianglesAndEdges(NativeArray <float2> vertices, int vertexCount, NativeArray <int> indices, int indexCount, ref NativeArray <UTriangle> triangles, ref int triangleCount, ref NativeArray <int4> delaEdges, ref int delaEdgeCount, ref float maxArea, ref float avgArea, ref float minArea)
        {
            // Check if there are invalid triangles or segments.
            for (int i = 0; i < indexCount; i += 3)
            {
                UTriangle tri = new UTriangle();
                var       i0  = indices[i + 0];
                var       i1  = indices[i + 1];
                var       i2  = indices[i + 2];
                tri.va      = vertices[i0];
                tri.vb      = vertices[i1];
                tri.vc      = vertices[i2];
                tri.c       = CircumCircle(tri);
                tri.area    = TriangleArea(tri.va, tri.vb, tri.vc);
                maxArea     = math.max(tri.area, maxArea);
                minArea     = math.min(tri.area, minArea);
                avgArea     = avgArea + tri.area;
                tri.indices = new int3(i0, i1, i2);

                // Outputs.
                delaEdges[delaEdgeCount++] = new int4(math.min(i0, i1), math.max(i0, i1), triangleCount, -1);
                delaEdges[delaEdgeCount++] = new int4(math.min(i1, i2), math.max(i1, i2), triangleCount, -1);
                delaEdges[delaEdgeCount++] = new int4(math.min(i2, i0), math.max(i2, i0), triangleCount, -1);
                triangles[triangleCount++] = tri;
            }
            avgArea = avgArea / triangleCount;
        }
Example #2
0
        internal static UCircle CircumCircle(UTriangle tri)
        {
            float xa = tri.va.x * tri.va.x;
            float xb = tri.vb.x * tri.vb.x;
            float xc = tri.vc.x * tri.vc.x;
            float ya = tri.va.y * tri.va.y;
            float yb = tri.vb.y * tri.vb.y;
            float yc = tri.vc.y * tri.vc.y;
            float c  = 2f * ((tri.vb.x - tri.va.x) * (tri.vc.y - tri.va.y) - (tri.vb.y - tri.va.y) * (tri.vc.x - tri.va.x));
            float x  = ((tri.vc.y - tri.va.y) * (xb - xa + yb - ya) + (tri.va.y - tri.vb.y) * (xc - xa + yc - ya)) / c;
            float y  = ((tri.va.x - tri.vc.x) * (xb - xa + yb - ya) + (tri.vb.x - tri.va.x) * (xc - xa + yc - ya)) / c;
            float vx = (tri.va.x - x);
            float vy = (tri.va.y - y);

            return(new UCircle {
                center = new float2(x, y), radius = math.sqrt((vx * vx) + (vy * vy))
            });
        }
 internal static void BuildTriangles(NativeArray <float2> vertices, int vertexCount, NativeArray <int> indices, int indexCount, ref NativeArray <UTriangle> triangles, ref int triangleCount, ref float maxArea)
 {
     // Check if there are invalid triangles or segments.
     for (int i = 0; i < indexCount; i += 3)
     {
         UTriangle tri = new UTriangle();
         var       i0  = indices[i + 0];
         var       i1  = indices[i + 1];
         var       i2  = indices[i + 2];
         tri.va   = vertices[i0];
         tri.vb   = vertices[i1];
         tri.vc   = vertices[i2];
         tri.c    = UTess.CircumCircle(tri);
         tri.area = UTess.TriangleArea(tri.va, tri.vb, tri.vc);
         maxArea  = math.max(tri.area, maxArea);
         triangles[triangleCount++] = tri;
     }
 }
Example #4
0
        internal static void BuildTriangles(NativeArray <float2> vertices, int vertexCount, NativeArray <int> indices, int indexCount, ref NativeArray <UTriangle> triangles, ref int triangleCount, ref float maxArea, ref float avgArea, ref float minArea, ref float maxEdge, ref float avgEdge, ref float minEdge)
        {
            // Check if there are invalid triangles or segments.
            for (int i = 0; i < indexCount; i += 3)
            {
                UTriangle tri = new UTriangle();
                var       i0  = indices[i + 0];
                var       i1  = indices[i + 1];
                var       i2  = indices[i + 2];
                tri.va = vertices[i0];
                tri.vb = vertices[i1];
                tri.vc = vertices[i2];
                tri.c  = CircumCircle(tri);

                tri.area = TriangleArea(tri.va, tri.vb, tri.vc);
                maxArea  = math.max(tri.area, maxArea);
                minArea  = math.min(tri.area, minArea);
                avgArea  = avgArea + tri.area;

                var e1 = math.distance(tri.va, tri.vb);
                var e2 = math.distance(tri.vb, tri.vc);
                var e3 = math.distance(tri.vc, tri.va);
                maxEdge = math.max(e1, maxEdge);
                maxEdge = math.max(e2, maxEdge);
                maxEdge = math.max(e3, maxEdge);
                minEdge = math.min(e1, minEdge);
                minEdge = math.min(e2, minEdge);
                minEdge = math.min(e3, minEdge);

                avgEdge = avgEdge + e1;
                avgEdge = avgEdge + e2;
                avgEdge = avgEdge + e3;
                triangles[triangleCount++] = tri;
            }
            avgArea = avgArea / triangleCount;
            avgEdge = avgEdge / indexCount;
        }
Example #5
0
 // Check if Triangle is Ok.
 static bool RequiresRefining(UTriangle tri, float maxArea)
 {
     // Add any further criteria later on.
     return(tri.area > maxArea);
 }