aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GeometryTest.cpp
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2017-07-14 14:04:52 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-14 20:34:34 +0000
commit91982ee8d92a80193915d59760e2ba9ce6f46989 (patch)
treebd1831431ae7a862f6349313f785be4a0e78ed63 /tests/GeometryTest.cpp
parent1e0779ba1120182c03f5d52a66df043d70efc376 (diff)
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 <csmartdalton@google.com> Reviewed-by: Cary Clark <caryclark@google.com>
Diffstat (limited to 'tests/GeometryTest.cpp')
-rw-r--r--tests/GeometryTest.cpp20
1 files changed, 20 insertions, 0 deletions
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 <array>
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<SkPoint, 4>& 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);
}