From 91982ee8d92a80193915d59760e2ba9ce6f46989 Mon Sep 17 00:00:00 2001 From: Chris Dalton Date: Fri, 14 Jul 2017 14:04:52 -0600 Subject: Fix SkClassifyCubic for near-quadratics Fixes the threshold logic for "0 ~= d1 && 0 ~= d2". Previously, if d1 and d2 were both near zero, but on opposite sides of the threshold, the curve could be misclassified as kCuspAtInfinity and drawn incorrectly. Bug: skia: Change-Id: I65f30ddebf0a4a0b933610d8cc1a2f489efc99e4 Reviewed-on: https://skia-review.googlesource.com/22400 Commit-Queue: Chris Dalton Reviewed-by: Cary Clark --- tests/GeometryTest.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/GeometryTest.cpp') diff --git a/tests/GeometryTest.cpp b/tests/GeometryTest.cpp index 91136e0240..4d955b5b13 100644 --- a/tests/GeometryTest.cpp +++ b/tests/GeometryTest.cpp @@ -8,6 +8,7 @@ #include "SkGeometry.h" #include "Test.h" #include "SkRandom.h" +#include static bool nearly_equal(const SkPoint& a, const SkPoint& b) { return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY); @@ -205,6 +206,24 @@ static void test_cubic_tangents(skiatest::Reporter* reporter) { } } +static void check_cubic_type(skiatest::Reporter* reporter, + const std::array& bezierPoints, SkCubicType expectedType) { + SkCubicType actualType = SkClassifyCubic(bezierPoints.data()); + REPORTER_ASSERT(reporter, actualType == expectedType); +} + +static void test_classify_cubic(skiatest::Reporter* reporter) { + check_cubic_type(reporter, {{{149.325f, 107.705f}, {149.325f, 103.783f}, + {151.638f, 100.127f}, {156.263f, 96.736f}}}, + SkCubicType::kQuadratic); + check_cubic_type(reporter, {{{225.694f, 223.15f}, {209.831f, 224.837f}, + {195.994f, 230.237f}, {184.181f, 239.35f}}}, + SkCubicType::kQuadratic); + check_cubic_type(reporter, {{{4.873f, 5.581f}, {5.083f, 5.2783f}, + {5.182f, 4.8593f}, {5.177f, 4.3242f}}}, + SkCubicType::kSerpentine); +} + DEF_TEST(Geometry, reporter) { SkPoint pts[3], dst[5]; @@ -233,4 +252,5 @@ DEF_TEST(Geometry, reporter) { test_quad_tangents(reporter); test_conic_tangents(reporter); test_conic_to_quads(reporter); + test_classify_cubic(reporter); } -- cgit v1.2.3