MCPcopy Create free account
hub / github.com/axmolengine/axmol / getPolyMergeValue

Function getPolyMergeValue

3rdparty/recast/DetourTileCacheBuilder.cpp:1310–1371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1308}
1309
1310static int getPolyMergeValue(unsigned short* pa, unsigned short* pb,
1311 const unsigned short* verts, int& ea, int& eb)
1312{
1313 const int na = countPolyVerts(pa);
1314 const int nb = countPolyVerts(pb);
1315
1316 // If the merged polygon would be too big, do not merge.
1317 if (na+nb-2 > MAX_VERTS_PER_POLY)
1318 return -1;
1319
1320 // Check if the polygons share an edge.
1321 ea = -1;
1322 eb = -1;
1323
1324 for (int i = 0; i < na; ++i)
1325 {
1326 unsigned short va0 = pa[i];
1327 unsigned short va1 = pa[(i+1) % na];
1328 if (va0 > va1)
1329 dtSwap(va0, va1);
1330 for (int j = 0; j < nb; ++j)
1331 {
1332 unsigned short vb0 = pb[j];
1333 unsigned short vb1 = pb[(j+1) % nb];
1334 if (vb0 > vb1)
1335 dtSwap(vb0, vb1);
1336 if (va0 == vb0 && va1 == vb1)
1337 {
1338 ea = i;
1339 eb = j;
1340 break;
1341 }
1342 }
1343 }
1344
1345 // No common edge, cannot merge.
1346 if (ea == -1 || eb == -1)
1347 return -1;
1348
1349 // Check to see if the merged polygon would be convex.
1350 unsigned short va, vb, vc;
1351
1352 va = pa[(ea+na-1) % na];
1353 vb = pa[ea];
1354 vc = pb[(eb+2) % nb];
1355 if (!uleft(&verts[va*3], &verts[vb*3], &verts[vc*3]))
1356 return -1;
1357
1358 va = pb[(eb+nb-1) % nb];
1359 vb = pb[eb];
1360 vc = pa[(ea+2) % na];
1361 if (!uleft(&verts[va*3], &verts[vb*3], &verts[vc*3]))
1362 return -1;
1363
1364 va = pa[ea];
1365 vb = pa[(ea+1)%na];
1366
1367 int dx = (int)verts[va*3+0] - (int)verts[vb*3+0];

Callers 2

removeVertexFunction · 0.85
dtBuildTileCachePolyMeshFunction · 0.85

Calls 3

countPolyVertsFunction · 0.85
dtSwapFunction · 0.85
uleftFunction · 0.85

Tested by

no test coverage detected