MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / JoinHorz

Function JoinHorz

TheForceEngine/TFE_Polygon/clipper.cpp:3371–3455  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3369//------------------------------------------------------------------------------
3370
3371bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b,
3372 const IntPoint Pt, bool DiscardLeft)
3373{
3374 Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? dRightToLeft : dLeftToRight);
3375 Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? dRightToLeft : dLeftToRight);
3376 if (Dir1 == Dir2) return false;
3377
3378 //When DiscardLeft, we want Op1b to be on the Left of Op1, otherwise we
3379 //want Op1b to be on the Right. (And likewise with Op2 and Op2b.)
3380 //So, to facilitate this while inserting Op1b and Op2b ...
3381 //when DiscardLeft, make sure we're AT or RIGHT of Pt before adding Op1b,
3382 //otherwise make sure we're AT or LEFT of Pt. (Likewise with Op2b.)
3383 if (Dir1 == dLeftToRight)
3384 {
3385 while (op1->Next->Pt.X <= Pt.X &&
3386 op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y)
3387 op1 = op1->Next;
3388 if (DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
3389 op1b = DupOutPt(op1, !DiscardLeft);
3390 if (op1b->Pt != Pt)
3391 {
3392 op1 = op1b;
3393 op1->Pt = Pt;
3394 op1b = DupOutPt(op1, !DiscardLeft);
3395 }
3396 }
3397 else
3398 {
3399 while (op1->Next->Pt.X >= Pt.X &&
3400 op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y)
3401 op1 = op1->Next;
3402 if (!DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
3403 op1b = DupOutPt(op1, DiscardLeft);
3404 if (op1b->Pt != Pt)
3405 {
3406 op1 = op1b;
3407 op1->Pt = Pt;
3408 op1b = DupOutPt(op1, DiscardLeft);
3409 }
3410 }
3411
3412 if (Dir2 == dLeftToRight)
3413 {
3414 while (op2->Next->Pt.X <= Pt.X &&
3415 op2->Next->Pt.X >= op2->Pt.X && op2->Next->Pt.Y == Pt.Y)
3416 op2 = op2->Next;
3417 if (DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next;
3418 op2b = DupOutPt(op2, !DiscardLeft);
3419 if (op2b->Pt != Pt)
3420 {
3421 op2 = op2b;
3422 op2->Pt = Pt;
3423 op2b = DupOutPt(op2, !DiscardLeft);
3424 };
3425 } else
3426 {
3427 while (op2->Next->Pt.X >= Pt.X &&
3428 op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y)

Callers 1

JoinPointsMethod · 0.85

Calls 1

DupOutPtFunction · 0.85

Tested by

no test coverage detected