Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (pcurrentline != NULL)
- {
- // Skip the root line when encountered
- if (pcurrentline == prootline) {
- pcurrentline = pcurrentline->pnextlineseg;
- } else {
- nx = pvertexlist[prootline->startvertex].y -
- pvertexlist[prootline->endvertex].y;
- ny = -(pvertexlist[prootline->startvertex].x -
- pvertexlist[prootline->endvertex].x);
- // Calculate the dot products we'll need for line intersection
- // and spatial relationship
- numer = (nx * (pvertexlist[pcurrentline->startvertex].x -
- pvertexlist[prootline->startvertex].x)) +
- (ny * (pvertexlist[pcurrentline->startvertex].y -
- pvertexlist[prootline->startvertex].y));
- denom = ((-nx) * (pvertexlist[pcurrentline->endvertex].x -
- pvertexlist[pcurrentline->startvertex].x)) +
- (-(ny) * (pvertexlist[pcurrentline->endvertex].y -
- pvertexlist[pcurrentline->startvertex].y));
- // Figure out if the infinite lines of the current line and
- // the root intersect; if so, figure out if the current line
- // segment is actually split, split if so, and add front/back
- // polygons as appropriate
- if (denom == 0.0) {
- // No intersection, because lines are parallel; just add
- // to appropriate list
- pnextlineseg = pcurrentline->pnextlineseg;
- if (numer < 0.0) {
- // Current line is in front of root line; link into
- // front list
- pcurrentline->pnextlineseg = pfrontlines;
- pfrontlines = pcurrentline;
- } else {
- // Current line behind root line; link into back list
- pcurrentline->pnextlineseg = pbacklines;
- pbacklines = pcurrentline;
- }
- pcurrentline = pnextlineseg;
- } else {
- // Infinite lines intersect; figure out whether the actual
- // line segment intersects the infinite line of the root,
- // and split if so
- t = numer / denom;
- if ((t > pcurrentline->tstart) &&
- (t < pcurrentline->tend)) {
- // The line segment must be split; add one split
- // segment to each list
- if (NumCompiledLinesegs > (MAX_NUM_LINESEGS - 1)) {
- DisplayMessageBox("Out of space for line segs;"
- "increase MAX_NUM_LINESEGS");
- return NULL;
- }
- // Make a new line entry for the split part of line
- psplitline = &pCompiledLinesegs[NumCompiledLinesegs];
- NumCompiledLinesegs++;
- *psplitline = *pcurrentline;
- psplitline->tstart = t;
- pcurrentline->tend = t;
- pnextlineseg = pcurrentline->pnextlineseg;
- if (numer < 0.0) {
- // Presplit part is in front of root line; link
- // into front list and put postsplit part in back
- // list
- pcurrentline->pnextlineseg = pfrontlines;
- pfrontlines = pcurrentline;
- psplitline->pnextlineseg = pbacklines;
- pbacklines = psplitline;
- } else {
- // Presplit part is in back of root line; link
- // into back list and put postsplit part in front
- // list
- psplitline->pnextlineseg = pfrontlines;
- pfrontlines = psplitline;
- pcurrentline->pnextlineseg = pbacklines;
- pbacklines = pcurrentline;
- }
- pcurrentline = pnextlineseg;
- } else {
- // Intersection outside segment limits, so no need to
- // split; just add to proper list
- pnextlineseg = pcurrentline->pnextlineseg;
- Done = 0;
- while (!Done) {
- if (numer < -MATCH_TOLERANCE) {
- // Current line is in front of root line;
- // link into front list
- pcurrentline->pnextlineseg = pfrontlines;
- pfrontlines = pcurrentline;
- Done = 1;
- } else if (numer > MATCH_TOLERANCE) {
- // Current line is behind root line; link
- // into back list
- pcurrentline->pnextlineseg = pbacklines;
- pbacklines = pcurrentline;
- Done = 1;
- } else {
- // The point on the current line we picked to
- // do front/back evaluation happens to be
- // collinear with the root, so use the other
- // end of the current line and try again
- numer =
- (nx *
- (pvertexlist[pcurrentline->endvertex].x -
- pvertexlist[prootline->startvertex].x))+
- (ny *
- (pvertexlist[pcurrentline->endvertex].y -
- pvertexlist[prootline->startvertex].y));
- }
- }
- pcurrentline = pnextlineseg;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement