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

Function buildContour

TheForceEngine/TFE_Polygon/polygon.cpp:884–941  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

882 }
883
884 bool buildContour(const BEdge* startEdge, const std::vector<BEdge>& edgesList, std::vector<s32>& remEdges, Contour* outContour)
885 {
886 if (!outContour) { return false; }
887 outContour->vtx.clear();
888
889 Vec2f startPt = startEdge->v0;
890 s32 nextEdge = startEdge->nextEdge;
891 outContour->vtx.push_back(startPt);
892 // Loop until the end or we are back at the start.
893 while (!remEdges.empty())
894 {
895 const BEdge* edge = &edgesList[nextEdge];
896 if (vtxEqual(&edge->v0, &startPt))
897 {
898 // Vertex with 3+ edges intersecting.
899 break;
900 }
901 outContour->vtx.push_back(edge->v0);
902
903 // Erase the remaining edge.
904 const s32 remEdgeCount = (s32)remEdges.size();
905 const s32* remIdx = remEdges.data();
906 bool foundEdge = false;
907 for (s32 i = 0; i < remEdgeCount; i++)
908 {
909 if (remIdx[i] == nextEdge)
910 {
911 remEdges.erase(remEdges.begin() + i);
912 foundEdge = true;
913 break;
914 }
915 }
916 // There is a loop in the contour.
917 if (!foundEdge)
918 {
919 break;
920 }
921 nextEdge = edge->nextEdge;
922
923 // Reached the end.
924 if (vtxEqual(&edge->v1, &startPt))
925 {
926 break;
927 }
928 }
929
930 // No valid contour.
931 if (outContour->vtx.empty())
932 {
933 return false;
934 }
935
936 // Next determine the winding order.
937 const f32 area = TFE_Polygon::signedArea((s32)outContour->vtx.size(), outContour->vtx.data());
938 outContour->clockwise = (area >= 0.0f);
939 outContour->outsideClip = false;
940 return true;
941 }

Callers 1

buildContoursFromPolygonFunction · 0.85

Calls 8

vtxEqualFunction · 0.85
signedAreaFunction · 0.85
push_backMethod · 0.80
dataMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected