MCPcopy Create free account
hub / github.com/AngusJohnson/Clipper2 / SetWindCountForClosedPathEdge

Method SetWindCountForClosedPathEdge

CPP/Clipper2Lib/src/clipper.engine.cpp:1011–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1009
1010
1011 void ClipperBase::SetWindCountForClosedPathEdge(Active& e)
1012 {
1013 //Wind counts refer to polygon regions not edges, so here an edge's WindCnt
1014 //indicates the higher of the wind counts for the two regions touching the
1015 //edge. (NB Adjacent regions can only ever have their wind counts differ by
1016 //one. Also, open paths have no meaningful wind directions or counts.)
1017
1018 Active* e2 = e.prev_in_ael;
1019 //find the nearest closed path edge of the same PolyType in AEL (heading left)
1020 PathType pt = GetPolyType(e);
1021 while (e2 && (GetPolyType(*e2) != pt || IsOpen(*e2))) e2 = e2->prev_in_ael;
1022
1023 if (!e2)
1024 {
1025 e.wind_cnt = e.wind_dx;
1026 e2 = actives_;
1027 }
1028 else if (fillrule_ == FillRule::EvenOdd)
1029 {
1030 e.wind_cnt = e.wind_dx;
1031 e.wind_cnt2 = e2->wind_cnt2;
1032 e2 = e2->next_in_ael;
1033 }
1034 else
1035 {
1036 //NonZero, positive, or negative filling here ...
1037 //if e's WindCnt is in the SAME direction as its WindDx, then polygon
1038 //filling will be on the right of 'e'.
1039 //NB neither e2.WindCnt nor e2.WindDx should ever be 0.
1040 if (e2->wind_cnt * e2->wind_dx < 0)
1041 {
1042 //opposite directions so 'e' is outside 'e2' ...
1043 if (abs(e2->wind_cnt) > 1)
1044 {
1045 //outside prev poly but still inside another.
1046 if (e2->wind_dx * e.wind_dx < 0)
1047 //reversing direction so use the same WC
1048 e.wind_cnt = e2->wind_cnt;
1049 else
1050 //otherwise keep 'reducing' the WC by 1 (ie towards 0) ...
1051 e.wind_cnt = e2->wind_cnt + e.wind_dx;
1052 }
1053 else
1054 //now outside all polys of same polytype so set own WC ...
1055 e.wind_cnt = (IsOpen(e) ? 1 : e.wind_dx);
1056 }
1057 else
1058 {
1059 //'e' must be inside 'e2'
1060 if (e2->wind_dx * e.wind_dx < 0)
1061 //reversing direction so use the same WC
1062 e.wind_cnt = e2->wind_cnt;
1063 else
1064 //otherwise keep 'increasing' the WC by 1 (ie away from 0) ...
1065 e.wind_cnt = e2->wind_cnt + e.wind_dx;
1066 }
1067 e.wind_cnt2 = e2->wind_cnt2;
1068 e2 = e2->next_in_ael; // ie get ready to calc WindCnt2

Callers

nothing calls this directly

Calls 2

GetPolyTypeFunction · 0.85
IsOpenFunction · 0.85

Tested by

no test coverage detected