public DiagonalSet merge(DiagonalSet d2) { int d2size = d2.getSize(); for (int j = 0; j < d2size; j++) { diagonalSet.Add(d2.getDiagonal(j)); } return this; }
public TriangulationColoring color(DiagonalSet d, Polygon p) { TriangulationColoring CSet = new TriangulationColoring(); Edge curDiag = d.getDiagonal(0); ColoredPoint a, b, cut; int d1, d2; if (p.vertices.Count == 3) { a = p.getColoredPoint(0); b = p.getColoredPoint(1); cut = p.getColoredPoint(2); a.vertexColor = ColoredPoint.color.Blue; b.vertexColor = ColoredPoint.color.Red; cut.vertexColor = ColoredPoint.color.Blue; CSet.add(a); CSet.add(b); CSet.add(cut); return CSet; } a = p.getColoredPoint(curDiag.Start.index); b = p.getColoredPoint(curDiag.End.index); cut = p.getColoredPoint(curDiag.Cutoff.index); p.getColoredPoint(a.index).vertexColor = ColoredPoint.color.Blue; p.getColoredPoint(b.index).vertexColor = ColoredPoint.color.Red; p.getColoredPoint(cut.index).vertexColor = ColoredPoint.color.Yellow; CSet.add(a); CSet.add(b); CSet.add(cut); if ((d1 = d.isInDiagSet(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); if ((d1 = d.isInDiagSet2(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet2(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); CSet.add(recurseColor(d, p, 0)); return CSet; }
TriangulationColoring recurseColor(DiagonalSet d, Polygon p, int i) { TriangulationColoring CSet = new TriangulationColoring(); Edge curDiag = d.getDiagonal(i); ColoredPoint a, b, cut; int d1, d2; a = p.getColoredPoint(curDiag.Start.index); b = p.getColoredPoint(curDiag.End.index); cut = p.getColoredPoint(curDiag.Cutoff.index); if (cut.vertexColor == ColoredPoint.color.None) // point has not been colored { p.vertices[cut.index].vertexColor = (GeometryTest.ColoredPoint.color)nextColor(a.index, b.index); CSet.add(cut); if ((d1 = d.isInDiagSet(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); if ((d1 = d.isInDiagSet2(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet2(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); } else { cut = getTriangle(a.index, b.index, p); if (cut == null) { return CSet; } p.vertices[cut.index].vertexColor = (GeometryTest.ColoredPoint.color)nextColor((int)a.vertexColor, (int)b.vertexColor); CSet.add(cut); if ((d1 = d.isInDiagSet(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); if ((d1 = d.isInDiagSet2(a, cut)) != -1) CSet.add(recurseColor(d, p, d1)); if ((d2 = d.isInDiagSet2(b, cut)) != -1) CSet.add(recurseColor(d, p, d2)); } return CSet; }
/** * This method was created by a SmartGuide. * @param pnt Point */ public void remove(int index, DiagonalSet d) { Edge diag; ; int j; if (!clockwise) { vertices.RemoveAt(index); for (int i = vertices.Count; i > 0; i--) { vertices[i].index = i; } } // remove diagonals if (closed) { for (j = d.diagonalSet.Count - 1; j >= 0; j--) { diag = d.getDiagonal(j); unlink(diag.getStart().index, diag.getEnd().index); } // reset the colors and remove guards for (j = 0; j < vertices.Count; j++) { //vertices[j].vertexColor = ColoredPoint.color.None; vertices[j].isGuard = false; } } link(vertices.Count - 1, 0); unlink(0, vertices.Count); closed = false; // open the polygon return; }