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;
        }