2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkGeometry.h"
11 static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
12 return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY);
15 static void testChopCubic(skiatest::Reporter* reporter) {
17 Inspired by this test, which used to assert that the tValues had dups
19 <path stroke="#202020" d="M0,0 C0,0 1,1 2190,5130 C2190,5070 2220,5010 2205,4980" />
21 const SkPoint src[] = {
22 { SkIntToScalar(2190), SkIntToScalar(5130) },
23 { SkIntToScalar(2190), SkIntToScalar(5070) },
24 { SkIntToScalar(2220), SkIntToScalar(5010) },
25 { SkIntToScalar(2205), SkIntToScalar(4980) },
29 // make sure we don't assert internally
30 int count = SkChopCubicAtMaxCurvature(src, dst, tValues);
31 if (false) { // avoid bit rot, suppress warning
32 REPORTER_ASSERT(reporter, count);
36 DEF_TEST(Geometry, reporter) {
37 SkPoint pts[3], dst[5];
43 int count = SkChopQuadAtMaxCurvature(pts, dst);
44 REPORTER_ASSERT(reporter, count == 1 || count == 2);
47 pts[1].set(SkIntToScalar(3), 0);
48 pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
49 SkConvertQuadToCubic(pts, dst);
50 const SkPoint cubic[] = {
52 { SkIntToScalar(2), 0, },
53 { SkIntToScalar(3), SkIntToScalar(1), },
54 { SkIntToScalar(3), SkIntToScalar(3) },
56 for (int i = 0; i < 4; ++i) {
57 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
60 testChopCubic(reporter);