ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/triangulate.c
(Generate patch)

Comparing ray/src/common/triangulate.c (file contents):
Revision 2.3 by greg, Fri Jan 24 02:22:49 2014 UTC vs.
Revision 2.4 by greg, Thu Dec 22 18:48:36 2016 UTC

# Line 38 | Line 38 | static int
38   polySnip(const Vert2_list *contour, int u, int v, int w, int n, int *V)
39   {
40    int p;
41 <  double Ax, Ay, Bx, By, Cx, Cy, Px, Py;
41 >  double Ax, Ay, Bx, By, Cx, Cy, Px, Py, cross;
42  
43    Ax = contour->v[V[u]].mX;
44    Ay = contour->v[V[u]].mY;
# Line 49 | Line 49 | polySnip(const Vert2_list *contour, int u, int v, int
49    Cx = contour->v[V[w]].mX;
50    Cy = contour->v[V[w]].mY;
51  
52 <  if ( EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) ) return false;
52 >  cross = ((Bx - Ax)*(Cy - Ay)) - ((By - Ay)*(Cx - Ax));
53 >  if (EPSILON > cross) return EPSILON > -cross ? -1 : false; /* Negative if colinear points */
54  
55    for (p=0;p<n;p++)
56    {
57      if( (p == u) | (p == v) | (p == w) ) continue;
58      Px = contour->v[V[p]].mX;
59      Py = contour->v[V[p]].mY;
60 +    if ((Px == Ax && Py == Ay) || (Px == Bx && Py == By) ||
61 +                (Px == Cx && Py == Cy)) continue; /* Handle donuts */
62      if (insideTriangle(Ax,Ay,Bx,By,Cx,Cy,Px,Py)) return false;
63    }
64  
# Line 123 | Line 126 | polyTriangulate(const Vert2_list *contour, tri_out_t *
126   {
127    /* allocate and initialize list of Vertices in polygon */
128  
129 <  int nv, m, u, v, w, count;
129 >  int nv, m, u, v, w, count, result;
130    int *V;
131  
132    if ( contour->nv < 3 ) return false;
# Line 157 | Line 160 | polyTriangulate(const Vert2_list *contour, tri_out_t *
160      v = u+1; if (nv <= v) v = 0;     /* new v    */
161      w = v+1; if (nv <= w) w = 0;     /* next     */
162  
163 <    if ( polySnip(contour,u,v,w,nv,V) )
163 >    result = polySnip(contour, u, v, w, nv, V);
164 >    if (result > 0) /* successfully found a triangle */
165      {
166 <      int a,b,c,s,t;
166 >      int a,b,c;
167  
168        /* true names of the vertices */
169        a = V[u]; b = V[v]; c = V[w];
# Line 168 | Line 172 | polyTriangulate(const Vert2_list *contour, tri_out_t *
172        if (!(*cb)(contour, a, b, c)) return false;
173  
174        m++;
175 +    }
176 +    if (result) /* successfully found a triangle or three consecutive colinear points */
177 +    {
178 +      int s,t;
179  
180        /* remove v from remaining polygon */
181        for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines