From 26143a3e9f6f01e12f6a00730a64b169d9c759cf Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Wed, 12 Jul 2023 08:22:54 +0200 Subject: [PATCH] Fixed #180 --- core/Shape.cpp | 22 ++++++++++++---------- core/ShapeDistanceFinder.hpp | 8 +++++++- core/edge-selectors.cpp | 1 + core/msdfgen.cpp | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/core/Shape.cpp b/core/Shape.cpp index 8d6f47c..f4449ba 100644 --- a/core/Shape.cpp +++ b/core/Shape.cpp @@ -162,16 +162,18 @@ void Shape::orientContours() { } } } - qsort(&intersections[0], intersections.size(), sizeof(Intersection), &Intersection::compare); - // Disqualify multiple intersections - for (int j = 1; j < (int) intersections.size(); ++j) - if (intersections[j].x == intersections[j-1].x) - intersections[j].direction = intersections[j-1].direction = 0; - // Inspect scanline and deduce orientations of intersected contours - for (int j = 0; j < (int) intersections.size(); ++j) - if (intersections[j].direction) - orientations[intersections[j].contourIndex] += 2*((j&1)^(intersections[j].direction > 0))-1; - intersections.clear(); + if (!intersections.empty()) { + qsort(&intersections[0], intersections.size(), sizeof(Intersection), &Intersection::compare); + // Disqualify multiple intersections + for (int j = 1; j < (int) intersections.size(); ++j) + if (intersections[j].x == intersections[j-1].x) + intersections[j].direction = intersections[j-1].direction = 0; + // Inspect scanline and deduce orientations of intersected contours + for (int j = 0; j < (int) intersections.size(); ++j) + if (intersections[j].direction) + orientations[intersections[j].contourIndex] += 2*((j&1)^(intersections[j].direction > 0))-1; + intersections.clear(); + } } } // Reverse contours that have the opposite orientation diff --git a/core/ShapeDistanceFinder.hpp b/core/ShapeDistanceFinder.hpp index 028738e..c19b8f7 100644 --- a/core/ShapeDistanceFinder.hpp +++ b/core/ShapeDistanceFinder.hpp @@ -1,6 +1,8 @@ #include "ShapeDistanceFinder.h" +#include + namespace msdfgen { template @@ -9,7 +11,11 @@ ShapeDistanceFinder::ShapeDistanceFinder(const Shape &shape) : template typename ShapeDistanceFinder::DistanceType ShapeDistanceFinder::distance(const Point2 &origin) { contourCombiner.reset(origin); - typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = &shapeEdgeCache[0]; +#ifdef MSDFGEN_USE_CPP11 + typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = shapeEdgeCache.data(); +#else + typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = shapeEdgeCache.empty() ? NULL : &shapeEdgeCache[0]; +#endif for (std::vector::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) { if (!contour->edges.empty()) { diff --git a/core/edge-selectors.cpp b/core/edge-selectors.cpp index aee7884..9bc49b1 100644 --- a/core/edge-selectors.cpp +++ b/core/edge-selectors.cpp @@ -1,6 +1,7 @@ #include "edge-selectors.h" +#include #include "arithmetics.hpp" namespace msdfgen { diff --git a/core/msdfgen.cpp b/core/msdfgen.cpp index 0289295..e2ba143 100644 --- a/core/msdfgen.cpp +++ b/core/msdfgen.cpp @@ -1,6 +1,7 @@ #include "../msdfgen.h" +#include #include #include "edge-selectors.h" #include "contour-combiners.h"