31373 {
31374 const MInt COPLANAR = 0;
31375 const MInt FRONT = 1;
31376 const MInt BACK = 2;
31377 const MInt SPANNING = 3;
31378
31379 MInt polygonType = 0;
31380 std::vector<MInt> types;
31381
31382
31383 MBool normalsEqual =
false;
31384 IF_CONSTEXPR(
nDim == 3) {
31385 if(abs(abs(this->
normal.
xx[0]) - abs(polygon->plane.normal.xx[0])) < MFloatEps
31386 && abs(abs(this->
normal.
xx[1]) - abs(polygon->plane.normal.xx[1])) < MFloatEps
31387 && abs(abs(this->
normal.
xx[2]) - abs(polygon->plane.normal.xx[2])) < MFloatEps)
31388 normalsEqual = true;
31389 }
31390
31391 MBool coplanarVertex =
false;
31392 for(
MInt i = 0; (unsigned)i < polygon->vertices.size(); i++) {
31394 MInt type = (t < -
eps) ? BACK : (t >
eps) ? FRONT : COPLANAR;
31395 polygonType |= type;
31396 types.push_back(type);
31397 IF_CONSTEXPR(
nDim == 3) {
31398 if(type == 0) coplanarVertex = true;
31399 }
31400 }
31401 ASSERT2(!(std::isnan(polygon->plane.normal.xx[0])), "");
31402
31403
31404 if(normalsEqual && coplanarVertex) polygonType = COPLANAR;
31405
31406 switch(polygonType) {
31407 case COPLANAR:
31408 (this->
normal.
dot((polygon->plane.normal)) > F0 ? coplanarFront : coplanarBack)->push_back(*polygon);
31409 break;
31410 case FRONT:
31411 front->push_back(*polygon);
31412 break;
31413 case BACK:
31414 back->push_back(*polygon);
31415 break;
31416 case SPANNING: {
31417 std::vector<CsgVertex> f;
31418 std::vector<CsgVertex>
b;
31419 IF_CONSTEXPR(
nDim == 2) {
31422 MInt ti = types[i], tj = types[j];
31423 CsgVertex vi = polygon->vertices[i];
31424 CsgVertex vj = polygon->vertices[j];
31425 if(ti != BACK) f.push_back(vi);
31426 if(ti != FRONT)
b.push_back(ti != BACK ? vi.clone() : vi);
31427 if((ti | tj) == SPANNING) {
31429 CsgVertex v = vi.interpolate(&vj, t);
31430 f.push_back(v);
31431 b.push_back(v.clone());
31432 }
31433 if(tj != BACK) f.push_back(vj);
31434 if(tj != FRONT)
b.push_back(tj != BACK ? vj.clone() : vj);
31435 }
31436 else IF_CONSTEXPR(
nDim == 3) {
31437 for(
MInt i = 0; (unsigned)i < polygon->vertices.size(); i++) {
31438 MInt j = (i + 1) % polygon->vertices.size();
31439 MInt ti = types[i], tj = types[j];
31440 CsgVertex vi = polygon->vertices[i];
31441 CsgVertex vj = polygon->vertices[j];
31442 if(ti != BACK) f.push_back(vi);
31443 if(ti != FRONT)
b.push_back(ti != BACK ? vi.clone() : vi);
31444 if((ti | tj) == SPANNING) {
31446 CsgVertex v = vi.interpolate(&vj, t);
31447 f.push_back(v);
31448 b.push_back(v.clone());
31449 }
31450 }
31451 }
31452 if(f.size() >=
nDim)
31453 front->push_back(
31454 CsgPolygon(f, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
31455 if(
b.size() >=
nDim)
31456 back->push_back(
31457 CsgPolygon(
b, polygon->setIndex, polygon->faceId, polygon->faceType, polygon->bodyId, polygon->plane));
31458 } break;
31459 default:
31460 break;
31461 }
31462}
static constexpr MFloat eps