function edgeEventByPoints(tcx, ep, eq, triangle, point) {
if (isEdgeSideOfTriangle(triangle, ep, eq)) {
return;
}
var p1 = triangle.pointCCW(point);
var o1 = orient2d(eq, p1, ep);
if (o1 === Orientation.COLLINEAR) {
if (triangle.containsPoints(eq, p1)) {
triangle.markConstrainedEdgeByPoints(eq, p1);
// We are modifying the constraint maybe it would be better to
// not change the given constraint and just keep a variable for the new constraint
tcx.edge_event.constrained_edge.q = p1;
var nbTriangle = triangle.neighborAcross(point);
edgeEventByPoints(tcx, ep, p1, nbTriangle, p1);
}
else {
throw new PointError('poly2tri EdgeEvent: Collinear not supported!', [eq, p1, ep]);
}
return;
}
var p2 = triangle.pointCW(point);
var o2 = orient2d(eq, p2, ep);
if (o2 === Orientation.COLLINEAR) {
if (triangle.containsPoints(eq, p2)) {
triangle.markConstrainedEdgeByPoints(eq, p2);
// We are modifying the constraint maybe it would be better to
// not change the given constraint and just keep a variable for the new constraint
tcx.edge_event.constrained_edge.q = p2;
var nbTriangle = triangle.neighborAcross(point);
edgeEventByPoints(tcx, ep, p2, nbTriangle, p2);
}
else {
throw new PointError('poly2tri EdgeEvent: Collinear not supported!', [eq, p2, ep]);
}
return;
}
if (o1 === o2) {
// Need to decide if we are rotating CW or CCW to get to a triangle
// that will cross edge
if (o1 === Orientation.CW) {
triangle = triangle.neighborCCW(point);
} else {
triangle = triangle.neighborCW(point);
}
edgeEventByPoints(tcx, ep, eq, triangle, point);
} else {
// This triangle crosses constraint so lets flippin start!
flipEdgeEvent(tcx, ep, eq, triangle, point);
}
}