MCPcopy Create free account
hub / github.com/JACoders/OpenJK / ChopWindingInPlace

Function ChopWindingInPlace

code/qcommon/cm_polylib.cpp:188–282  ·  view source on GitHub ↗

============= ChopWindingInPlace ============= */

Source from the content-addressed store, hash-verified

186=============
187*/
188void ChopWindingInPlace (winding_t **inout, vec3_t normal, vec_t dist, vec_t epsilon)
189{
190 winding_t *in;
191 float dists[MAX_POINTS_ON_WINDING+4] = { 0 };
192 int sides[MAX_POINTS_ON_WINDING+4] = { 0 };
193 int counts[3];
194 static float dot; // VC 4.2 optimizer bug if not static
195 int i, j;
196 float *p1, *p2;
197 vec3_t mid;
198 winding_t *f;
199 int maxpts;
200
201 in = *inout;
202 counts[0] = counts[1] = counts[2] = 0;
203
204// determine sides for each point
205 for (i=0 ; i<in->numpoints ; i++)
206 {
207 dot = DotProduct (in->p[i], normal);
208 dot -= dist;
209 dists[i] = dot;
210 if (dot > epsilon)
211 sides[i] = SIDE_FRONT;
212 else if (dot < -epsilon)
213 sides[i] = SIDE_BACK;
214 else
215 {
216 sides[i] = SIDE_ON;
217 }
218 counts[sides[i]]++;
219 }
220 sides[i] = sides[0];
221 dists[i] = dists[0];
222
223 if (!counts[0])
224 {
225 FreeWinding (in);
226 *inout = NULL;
227 return;
228 }
229 if (!counts[1])
230 return; // inout stays the same
231
232 maxpts = in->numpoints+4; // cant use counts[0]+2 because
233 // of fp grouping errors
234
235 f = AllocWinding (maxpts);
236
237 for (i=0 ; i<in->numpoints ; i++)
238 {
239 p1 = in->p[i];
240
241 if (sides[i] == SIDE_ON)
242 {
243 VectorCopy (p1, f->p[f->numpoints]);
244 f->numpoints++;
245 continue;

Callers 2

CM_ValidateFacetFunction · 0.70
CM_AddFacetBevelsFunction · 0.70

Calls 5

DotProductFunction · 0.85
VectorCopyFunction · 0.85
FreeWindingFunction · 0.70
AllocWindingFunction · 0.70
Com_ErrorFunction · 0.70

Tested by

no test coverage detected