GrTessellator: fix for disappearing thin path.
authorStephen White <senorblanco@chromium.org>
Mon, 16 Jan 2017 16:47:21 +0000 (11:47 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 17 Jan 2017 15:59:50 +0000 (15:59 +0000)
simplify_boundary() was incorrectly comparing squared distances
against a non-squared constant. For .25 of a pixel, we need to
compare against 0.25 squared, or 0.0625.

This also includes a fix to get_edge_normal(), We were actually
returning edge "vectors", instead of edge normals. This wasn't
causing problems, since the error cancels itself out, but it's
confusing.

BUG=skia:

Change-Id: I0d50f2d001ed5e41de2900139c396b9ef75d2ddf
Reviewed-on: https://skia-review.googlesource.com/7043
Commit-Queue: Stephan White <senorblanco@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
gm/thinconcavepaths.cpp
src/gpu/GrTessellator.cpp

index 0f4dd507bffb228ee9a106ec456fa31d58f23f91..7389642da3c474e8357d845824665b55f75a90ca 100644 (file)
@@ -24,6 +24,17 @@ void draw_thin_stroked_rect(SkCanvas* canvas, const SkPaint& paint, SkScalar wid
     canvas->drawPath(path, paint);
 }
 
+void draw_thin_right_angle(SkCanvas* canvas, const SkPaint& paint, SkScalar width) {
+    SkPath path;
+    path.moveTo(10 + width, 10 + width);
+    path.lineTo(40,         10 + width);
+    path.lineTo(40,         20);
+    path.lineTo(40 + width, 20 + width);
+    path.lineTo(40 + width, 10);
+    path.lineTo(10,         10);
+    canvas->drawPath(path, paint);
+}
+
 };
 
 DEF_SIMPLE_GM(thinconcavepaths, canvas, 400, 400) {
@@ -38,4 +49,12 @@ DEF_SIMPLE_GM(thinconcavepaths, canvas, 400, 400) {
         canvas->translate(0, 25);
     }
     canvas->restore();
+    canvas->translate(50, 0);
+    canvas->save();
+    for (SkScalar width = 0.5; width < 2.05; width += 0.25) {
+        draw_thin_right_angle(canvas, paint, width);
+        canvas->translate(0, 25);
+    }
+    canvas->restore();
+    canvas->translate(100, 0);
 }
index 09a5662f8db0cb04cb74a9740ad323440a7e223e..d193b7486cf0f5ce530c14135543a3297d43de68 100644 (file)
@@ -1457,8 +1457,8 @@ void remove_non_boundary_edges(const VertexList& mesh, SkPath::FillType fillType
 }
 
 void get_edge_normal(const Edge* e, SkVector* normal) {
-    normal->setNormalize(SkDoubleToScalar(-e->fLine.fB) * e->fWinding,
-                         SkDoubleToScalar(e->fLine.fA) * e->fWinding);
+    normal->setNormalize(SkDoubleToScalar(e->fLine.fA) * e->fWinding,
+                         SkDoubleToScalar(e->fLine.fB) * e->fWinding);
 }
 
 // Stage 5c: detect and remove "pointy" vertices whose edge normals point in opposite directions
@@ -1475,7 +1475,7 @@ void simplify_boundary(EdgeList* boundary, Comparator& c, SkChunkAlloc& alloc) {
         double dist = e->dist(prev->fPoint);
         SkVector normal;
         get_edge_normal(e, &normal);
-        float denom = 0.25f * static_cast<float>(e->fLine.magSq());
+        float denom = 0.0625f * static_cast<float>(e->fLine.magSq());
         if (prevNormal.dot(normal) < 0.0 && (dist * dist) <= denom) {
             Edge* join = new_edge(prev, next, Edge::Type::kInner, c, alloc);
             insert_edge(join, e, boundary);