fast triangulate single “sub paths” We were triangulating single paths using a simple and fast triangulator, but most of our paths in Rive are container paths (shapes) with a single path inside of them. In that case we were always going through the slower triangulator (which does evenOdd/nonZero winding). This catches containers with a single path and lets them go through the fast path too. Diffs= ed84a5ca3 fast triangulate single “sub paths”
diff --git a/.rive_head b/.rive_head index 3bc8648..4a69d7f 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -4bc43ad929a73747f0ed51401d0b9a2d69188bb9 +ed84a5ca3153d142172d258bda071a98de3dd0e7
diff --git a/tess/src/tess_render_path.cpp b/tess/src/tess_render_path.cpp index 5fa23db..6599931 100644 --- a/tess/src/tess_render_path.cpp +++ b/tess/src/tess_render_path.cpp
@@ -82,7 +82,7 @@ // doing any funky self overlapping winding and we'll try to triangulate it // quickly as a single polygon. if (m_subPaths.size() == 0) { - if (!m_rawPath.empty()) { + if (!empty()) { Mat2D identity; contour(identity); @@ -94,7 +94,26 @@ containerPath->addTriangles(contour, m_earcut.indices); } + } else if (m_subPaths.size() == 1) { + // We're a container but we only have 1 path, let's see if we can use + // our fast triangulator. + SubPath& subPath = m_subPaths.front(); + auto subRenderPath = static_cast<TessRenderPath*>(subPath.path()); + if (subRenderPath->isContainer()) { + // Nope, subpath is also a container, keep going. + subRenderPath->triangulate(containerPath); + } else if (!subRenderPath->empty()) { + // Yes, it's a single path with commands, triangulate it. + subRenderPath->contour(subPath.transform()); + const SegmentedContour& segmentedContour = subRenderPath->segmentedContour(); + auto contour = segmentedContour.contourPoints(); + auto contours = Span(&contour, 1); + m_earcut(contours); + + containerPath->addTriangles(contour, m_earcut.indices); + } } else { + // We're a container with multiple sub-paths. TESStesselator* tess = nullptr; for (SubPath& subPath : m_subPaths) { auto subRenderPath = static_cast<TessRenderPath*>(subPath.path());