Chlumsky 2 years ago
parent
commit
26143a3e9f
4 changed files with 21 additions and 11 deletions
  1. 12 10
      core/Shape.cpp
  2. 7 1
      core/ShapeDistanceFinder.hpp
  3. 1 0
      core/edge-selectors.cpp
  4. 1 0
      core/msdfgen.cpp

+ 12 - 10
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

+ 7 - 1
core/ShapeDistanceFinder.hpp

@@ -1,6 +1,8 @@
 
 #include "ShapeDistanceFinder.h"
 
+#include <cstddef>
+
 namespace msdfgen {
 
 template <class ContourCombiner>
@@ -9,7 +11,11 @@ ShapeDistanceFinder<ContourCombiner>::ShapeDistanceFinder(const Shape &shape) :
 template <class ContourCombiner>
 typename ShapeDistanceFinder<ContourCombiner>::DistanceType ShapeDistanceFinder<ContourCombiner>::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<Contour>::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) {
         if (!contour->edges.empty()) {

+ 1 - 0
core/edge-selectors.cpp

@@ -1,6 +1,7 @@
 
 #include "edge-selectors.h"
 
+#include <cstddef>
 #include "arithmetics.hpp"
 
 namespace msdfgen {

+ 1 - 0
core/msdfgen.cpp

@@ -1,6 +1,7 @@
 
 #include "../msdfgen.h"
 
+#include <cstddef>
 #include <vector>
 #include "edge-selectors.h"
 #include "contour-combiners.h"