blob: 803bacd3a2100d584b06ee190121ca82ba56e0e1 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.comd8730ea2009-02-27 22:06:06 +00008#include "Test.h"
9#include "SkGeometry.h"
10
reed@google.com6fc321a2011-07-27 13:54:36 +000011static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
12 return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY);
13}
14
reed@android.comd8730ea2009-02-27 22:06:06 +000015static void TestGeometry(skiatest::Reporter* reporter) {
16 SkPoint pts[3], dst[5];
17
18 pts[0].set(0, 0);
19 pts[1].set(100, 50);
20 pts[2].set(0, 100);
21
22 int count = SkChopQuadAtMaxCurvature(pts, dst);
23 REPORTER_ASSERT(reporter, count == 1 || count == 2);
reed@google.com6fc321a2011-07-27 13:54:36 +000024
25 pts[0].set(0, 0);
26 pts[1].set(SkIntToScalar(3), 0);
27 pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
28 SkConvertQuadToCubic(pts, dst);
29 const SkPoint cubic[] = {
30 0, 0,
31 SkIntToScalar(2), 0,
32 SkIntToScalar(3), SkIntToScalar(1),
33 SkIntToScalar(3), SkIntToScalar(3)
34 };
35 for (int i = 0; i < 4; ++i) {
36 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
37 }
reed@android.comd8730ea2009-02-27 22:06:06 +000038}
39
40#include "TestClassDef.h"
41DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry)