int GetEqualCellForCells(NativeArray <TessCell> cells, int count, TessCell p) { int l = 0; int h = count - 1; TessCellCompare tcc = new TessCellCompare(); while (l <= h) { int m; m = ((int)(l + h)) >> 1; int f = tcc.Compare(cells[m], p); if (f == 0) { return(m); } else if (f <= 0) { l = m + 1; } else { h = m - 1; } } return(-1); }
NativeArray <TessCell> GetCells(ref int count) { NativeArray <TessCell> cellsOut = new NativeArray <TessCell>(m_NumPoints * (m_NumPoints + 1), Allocator.Temp); count = 0; for (int i = 0, n = m_Stars.Length; i < n; ++i) { ArraySlice <int> points = m_Stars[i].points; for (int j = 0, m = m_Stars[i].pointCount; j < m; j += 2) { int s = points[j]; int t = points[j + 1]; if (i < math.min(s, t)) { TessCell c = new TessCell(); c.a = i; c.b = s; c.c = t; cellsOut[count++] = c; } } } return(cellsOut); }
void AddPoint(NativeArray <TessHull> hulls, int hullCount, NativeArray <float2> points, float2 p, int idx) { int l = GetLowerHullForVector(hulls, hullCount, p); int u = GetUpperHullForVector(hulls, hullCount, p); for (int i = l; i < u; ++i) { TessHull hull = hulls[i]; int m = hull.ilcount; while (m > 1 && TessUtils.OrientFast(points[hull.ilarray[m - 2]], points[hull.ilarray[m - 1]], p) > 0) { TessCell c = new TessCell(); c.a = hull.ilarray[m - 1]; c.b = hull.ilarray[m - 2]; c.c = idx; m_Cells[m_CellCount++] = c; m -= 1; } hull.ilcount = m + 1; hull.ilarray[m] = idx; m = hull.iucount; while (m > 1 && TessUtils.OrientFast(points[hull.iuarray[m - 2]], points[hull.iuarray[m - 1]], p) < 0) { TessCell c = new TessCell(); c.a = hull.iuarray[m - 2]; c.b = hull.iuarray[m - 1]; c.c = idx; m_Cells[m_CellCount++] = c; m -= 1; } hull.iucount = m + 1; hull.iuarray[m] = idx; hulls[i] = hull; } }
NativeArray <TessCell> Constrain(ref int count) { var cells = GetCells(ref count); int nc = count; for (int i = 0; i < nc; ++i) { TessCell c = cells[i]; int x = c.a, y = c.b, z = c.c; if (y < z) { if (y < x) { c.a = y; c.b = z; c.c = x; } } else if (z < x) { c.a = z; c.b = x; c.c = y; } cells[i] = c; } unsafe { TessUtils.InsertionSort <TessCell, TessCellCompare>( NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(cells), 0, m_CellCount - 1, new TessCellCompare()); } // Out m_Flags = new NativeArray <int>(nc, Allocator.Temp); m_Neighbors = new NativeArray <int>(nc * 3, Allocator.Temp); m_Constraints = new NativeArray <int>(nc * 3, Allocator.Temp); var next = new NativeArray <int>(nc * 3, Allocator.Temp); var active = new NativeArray <int>(nc * 3, Allocator.Temp); int side = 1, nextCount = 0, activeCount = 0; for (int i = 0; i < nc; ++i) { TessCell c = cells[i]; for (int j = 0; j < 3; ++j) { int x = j, y = (j + 1) % 3; x = (x == 0) ? c.a : (j == 1) ? c.b : c.c; y = (y == 0) ? c.a : (y == 1) ? c.b : c.c; int o = OppositeOf(y, x); int a = m_Neighbors[3 * i + j] = FindNeighbor(cells, count, y, x, o); int b = m_Constraints[3 * i + j] = (-1 != FindConstraint(x, y)) ? 1 : 0; if (a < 0) { if (0 != b) { next[nextCount++] = i; } else { active[activeCount++] = i; m_Flags[i] = 1; } } } } while (activeCount > 0 || nextCount > 0) { while (activeCount > 0) { int t = active[activeCount - 1]; activeCount--; if (m_Flags[t] == -side) { continue; } m_Flags[t] = side; TessCell c = cells[t]; for (int j = 0; j < 3; ++j) { int f = m_Neighbors[3 * t + j]; if (f >= 0 && m_Flags[f] == 0) { if (0 != m_Constraints[3 * t + j]) { next[nextCount++] = f; } else { active[activeCount++] = f; m_Flags[f] = side; } } } } for (int e = 0; e < nextCount; e++) { active[e] = next[e]; } activeCount = nextCount; nextCount = 0; side = -side; } active.Dispose(); next.Dispose(); return(cells); }