- int i;
- for (i = 0; i < numpoints; i++)
- {
- vec_t dot = -chopPlane->DistanceToPoint(p[i]);
- dists[i] = dot;
-
- if (dot > epsilon)
- sides[i] = SIDE_FRONT;
- else if (dot < -epsilon)
- sides[i] = SIDE_BACK;
- else
- sides[i] = SIDE_ON;
-
- counts[sides[i]]++;
- }
- sides[i] = sides[0];
- dists[i] = dists[0];
-
- *front = *back = NULL;
-
- if (!counts[0])
- {
- *back = CopyWinding();
- return;
- }
- if (!counts[1])
- {
- *front = CopyWinding();
- return;
- }
-
- int maxpts = numpoints+4; // cant use counts[0]+2 because
- // of fp grouping errors
-
- DWinding* f = new DWinding;
- DWinding* b = new DWinding;
-
- f->AllocWinding(maxpts);
- f->numpoints = 0;
-
- b->AllocWinding(maxpts);
- b->numpoints = 0;
-
- *front = f;
- *back = b;
-
- for (i = 0; i < numpoints ; i++)
- {
- p1 = p[i];
-
- if (sides[i] == SIDE_ON)
- {
- VectorCopy (p1, f->p[f->numpoints]);
- f->numpoints++;
- VectorCopy (p1, b->p[b->numpoints]);
- b->numpoints++;
- continue;
- }
-
- if (sides[i] == SIDE_FRONT)
- {
- VectorCopy (p1, f->p[f->numpoints]);
- f->numpoints++;
- }
- if (sides[i] == SIDE_BACK)
- {
- VectorCopy (p1, b->p[b->numpoints]);
- b->numpoints++;
- }
-
- if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
- continue;
-
- // generate a split point
- p2 = p[(i+1)%numpoints];
-
- vec_t dot = dists[i] / (dists[i]-dists[i+1]);
- for (int j = 0; j < 3; j++)
- {
- if (chopPlane->normal[j] == 1)
- mid[j] = chopPlane->_d;
- else if (chopPlane->normal[j] == -1)
- mid[j] = -chopPlane->_d;
- else
- mid[j] = p1[j] + dot*(p2[j]-p1[j]);
- }
-
- VectorCopy (mid, f->p[f->numpoints]);
- f->numpoints++;
- VectorCopy (mid, b->p[b->numpoints]);
- b->numpoints++;
- }
-
- if (f->numpoints > maxpts || b->numpoints > maxpts)
- globalOutputStream() << "ClipWinding: points exceeded estimate\n";
- if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING)
- globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n";
+ int i;
+ for (i = 0; i < numpoints; i++) {
+ vec_t dot = -chopPlane->DistanceToPoint(p[i]);
+ dists[i] = dot;
+
+ if (dot > epsilon) {
+ sides[i] = SIDE_FRONT;
+ } else if (dot < -epsilon) {
+ sides[i] = SIDE_BACK;
+ } else {
+ sides[i] = SIDE_ON;
+ }
+
+ counts[sides[i]]++;
+ }
+ sides[i] = sides[0];
+ dists[i] = dists[0];
+
+ *front = *back = NULL;
+
+ if (!counts[0]) {
+ *back = CopyWinding();
+ return;
+ }
+ if (!counts[1]) {
+ *front = CopyWinding();
+ return;
+ }
+
+ int maxpts = numpoints + 4; // cant use counts[0]+2 because
+ // of fp grouping errors
+
+ DWinding *f = new DWinding;
+ DWinding *b = new DWinding;
+
+ f->AllocWinding(maxpts);
+ f->numpoints = 0;
+
+ b->AllocWinding(maxpts);
+ b->numpoints = 0;
+
+ *front = f;
+ *back = b;
+
+ for (i = 0; i < numpoints; i++) {
+ p1 = p[i];
+
+ if (sides[i] == SIDE_ON) {
+ VectorCopy(p1, f->p[f->numpoints]);
+ f->numpoints++;
+ VectorCopy(p1, b->p[b->numpoints]);
+ b->numpoints++;
+ continue;
+ }
+
+ if (sides[i] == SIDE_FRONT) {
+ VectorCopy(p1, f->p[f->numpoints]);
+ f->numpoints++;
+ }
+ if (sides[i] == SIDE_BACK) {
+ VectorCopy(p1, b->p[b->numpoints]);
+ b->numpoints++;
+ }
+
+ if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i]) {
+ continue;
+ }
+
+ // generate a split point
+ p2 = p[(i + 1) % numpoints];
+
+ vec_t dot = dists[i] / (dists[i] - dists[i + 1]);
+ for (int j = 0; j < 3; j++) {
+ if (chopPlane->normal[j] == 1) {
+ mid[j] = chopPlane->_d;
+ } else if (chopPlane->normal[j] == -1) {
+ mid[j] = -chopPlane->_d;
+ } else {
+ mid[j] = p1[j] + dot * (p2[j] - p1[j]);
+ }
+ }
+
+ VectorCopy(mid, f->p[f->numpoints]);
+ f->numpoints++;
+ VectorCopy(mid, b->p[b->numpoints]);
+ b->numpoints++;
+ }
+
+ if (f->numpoints > maxpts || b->numpoints > maxpts) {
+ globalOutputStream() << "ClipWinding: points exceeded estimate\n";
+ }
+ if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING) {
+ globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n";
+ }