private static bool flipTriangle(List <Point> points, List <Triad> triads, int testInd, out int flipInd) { int opp = 0, e1, e2, e3 = 0, e4 = 0; flipInd = 0; Triad t = triads[testInd]; if (t.bc >= 0) { flipInd = t.bc; Triad t2 = triads[flipInd]; t2.findAdj(t.b, testInd, out opp, out e3, out e4); if (t.insideCircumcircle(points[opp])) { e1 = t.ab; e2 = t.ac; if (e1 != e3 && e2 != e4) { int ta = t.a, tb = t.b, tc = t.c; t.init(ta, tb, opp, e1, e3, flipInd, points); t2.init(ta, tc, opp, e2, e4, testInd, points); if (e3 >= 0) { triads[e3].changeAdjInd(flipInd, testInd); } if (e2 >= 0) { triads[e2].changeAdjInd(testInd, flipInd); } return(true); } } } if (t.ab >= 0) { flipInd = t.ab; Triad t2 = triads[flipInd]; t2.findAdj(t.a, testInd, out opp, out e3, out e4); if (t.insideCircumcircle(points[opp])) { e1 = t.ac; e2 = t.bc; if (e1 != e3 && e2 != e4) { int ta = t.a, tb = t.b, tc = t.c; t.init(tc, ta, opp, e1, e3, flipInd, points); t2.init(tc, tb, opp, e2, e4, testInd, points); if (e3 >= 0) { triads[e3].changeAdjInd(flipInd, testInd); } if (e2 >= 0) { triads[e2].changeAdjInd(testInd, flipInd); } return(true); } } } if (t.ac >= 0) { flipInd = t.ac; Triad t2 = triads[flipInd]; t2.findAdj(t.a, testInd, out opp, out e3, out e4); if (t.insideCircumcircle(points[opp])) { e1 = t.ab; e2 = t.bc; if (e1 != e3 && e2 != e4) { int ta = t.a, tb = t.b, tc = t.c; t.init(tb, ta, opp, e1, e3, flipInd, points); t2.init(tb, tc, opp, e2, e4, testInd, points); if (e3 >= 0) { triads[e3].changeAdjInd(flipInd, testInd); } if (e2 >= 0) { triads[e2].changeAdjInd(testInd, flipInd); } return(true); } } } return(false); }