GrTessellator: fix for disappearing thin path.
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>
diff --git a/gm/thinconcavepaths.cpp b/gm/thinconcavepaths.cpp
index 0f4dd50..7389642 100644
--- a/gm/thinconcavepaths.cpp
+++ b/gm/thinconcavepaths.cpp
@@ -24,6 +24,17 @@
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 @@
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);
}
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index 09a5662..d193b74 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -1457,8 +1457,8 @@
}
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 @@
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);