Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.51 KB | None | 0 0
  1. while (pcurrentline != NULL)
  2.     {
  3.       // Skip the root line when encountered
  4.       if (pcurrentline == prootline) {
  5.         pcurrentline = pcurrentline->pnextlineseg;
  6.       } else  {
  7.         nx = pvertexlist[prootline->startvertex].y -
  8.                 pvertexlist[prootline->endvertex].y;
  9.         ny = -(pvertexlist[prootline->startvertex].x -
  10.                 pvertexlist[prootline->endvertex].x);
  11.         // Calculate the dot products we'll need for line intersection
  12.         // and spatial relationship
  13.         numer = (nx * (pvertexlist[pcurrentline->startvertex].x -
  14.                  pvertexlist[prootline->startvertex].x)) +
  15.                 (ny * (pvertexlist[pcurrentline->startvertex].y -
  16.                  pvertexlist[prootline->startvertex].y));
  17.         denom = ((-nx) * (pvertexlist[pcurrentline->endvertex].x -
  18.                  pvertexlist[pcurrentline->startvertex].x)) +
  19.                 (-(ny) * (pvertexlist[pcurrentline->endvertex].y -
  20.                  pvertexlist[pcurrentline->startvertex].y));
  21.         // Figure out if the infinite lines of the current line and
  22.         // the root intersect; if so, figure out if the current line
  23.         // segment is actually split, split if so, and add front/back
  24.         // polygons as appropriate
  25.         if (denom == 0.0) {
  26.             // No intersection, because lines are parallel; just add
  27.             // to appropriate list
  28.             pnextlineseg = pcurrentline->pnextlineseg;
  29.             if (numer < 0.0) {
  30.                 // Current line is in front of root line; link into
  31.                 // front list
  32.                 pcurrentline->pnextlineseg = pfrontlines;
  33.                 pfrontlines = pcurrentline;
  34.             } else {
  35.                 // Current line behind root line; link into back list
  36.                 pcurrentline->pnextlineseg = pbacklines;
  37.                 pbacklines = pcurrentline;
  38.             }
  39.             pcurrentline = pnextlineseg;
  40.         } else {
  41.             // Infinite lines intersect; figure out whether the actual
  42.             // line segment intersects the infinite line of the root,
  43.             // and split if so
  44.             t =  numer / denom;
  45.             if ((t > pcurrentline->tstart) &&
  46.                     (t < pcurrentline->tend)) {
  47.                 // The line segment must be split; add one split
  48.                 // segment to each list
  49.                 if (NumCompiledLinesegs > (MAX_NUM_LINESEGS - 1)) {
  50.                     DisplayMessageBox("Out of space for line segs;"
  51.                                  "increase MAX_NUM_LINESEGS");
  52.                     return NULL;
  53.                 }
  54.                 // Make a new line entry for the split part of line
  55.                 psplitline = &pCompiledLinesegs[NumCompiledLinesegs];
  56.                 NumCompiledLinesegs++;
  57.                 *psplitline = *pcurrentline;
  58.                 psplitline->tstart = t;
  59.                 pcurrentline->tend = t;
  60.  
  61.                 pnextlineseg = pcurrentline->pnextlineseg;
  62.                 if (numer < 0.0) {
  63.                     // Presplit part is in front of root line; link
  64.                     // into front list and put postsplit part in back
  65.                     // list
  66.                     pcurrentline->pnextlineseg = pfrontlines;
  67.                     pfrontlines = pcurrentline;
  68.                     psplitline->pnextlineseg = pbacklines;
  69.                     pbacklines = psplitline;
  70.                 } else {
  71.                     // Presplit part is in back of root line; link
  72.                     // into back list and put postsplit part in front
  73.                     // list
  74.                     psplitline->pnextlineseg = pfrontlines;
  75.                     pfrontlines = psplitline;
  76.                     pcurrentline->pnextlineseg = pbacklines;
  77.                     pbacklines = pcurrentline;
  78.                 }
  79.                 pcurrentline = pnextlineseg;
  80.             } else {
  81.                 // Intersection outside segment limits, so no need to
  82.                 // split; just add to proper list
  83.                 pnextlineseg = pcurrentline->pnextlineseg;
  84.                 Done = 0;
  85.                 while (!Done) {
  86.                     if (numer < -MATCH_TOLERANCE) {
  87.                         // Current line is in front of root line;
  88.                         // link into front list
  89.                         pcurrentline->pnextlineseg = pfrontlines;
  90.                         pfrontlines = pcurrentline;
  91.                         Done = 1;
  92.                     } else if (numer > MATCH_TOLERANCE) {
  93.                         // Current line is behind root line; link
  94.                         // into back list
  95.                         pcurrentline->pnextlineseg = pbacklines;
  96.                         pbacklines = pcurrentline;
  97.                         Done = 1;
  98.                     } else {
  99.                         // The point on the current line we picked to
  100.                         // do front/back evaluation happens to be
  101.                         // collinear with the root, so use the other
  102.                         // end of the current line and try again
  103.                         numer =
  104.                             (nx *
  105.                              (pvertexlist[pcurrentline->endvertex].x -
  106.                               pvertexlist[prootline->startvertex].x))+
  107.                             (ny *
  108.                              (pvertexlist[pcurrentline->endvertex].y -
  109.                               pvertexlist[prootline->startvertex].y));
  110.                     }
  111.                 }
  112.                 pcurrentline = pnextlineseg;
  113.             }
  114.         }
  115.       }
  116.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement