function edgeEventByPoints implement changes from C++ to better support Collinear points

49 views
Skip to first unread message

Mário Silva

unread,
Nov 20, 2015, 6:16:38 AM11/20/15
to poly2tri
Hi there, 

I would like to say i love this lib and i would like to contribute this improvement.

I have integrated the changes in the c++ version on the function edgeEventByPoints. here is the code:

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

Regards,
MS
Reply all
Reply to author
Forward
0 new messages