blob: 146528897dd99a08263ab4b778838f981053e61a [file] [log] [blame]
reed@android.comd8730ea2009-02-27 22:06:06 +00001#include "Test.h"
2#include "SkGeometry.h"
3
reed@google.com6fc321a2011-07-27 13:54:36 +00004static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
5 return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY);
6}
7
reed@android.comd8730ea2009-02-27 22:06:06 +00008static void TestGeometry(skiatest::Reporter* reporter) {
9 SkPoint pts[3], dst[5];
10
11 pts[0].set(0, 0);
12 pts[1].set(100, 50);
13 pts[2].set(0, 100);
14
15 int count = SkChopQuadAtMaxCurvature(pts, dst);
16 REPORTER_ASSERT(reporter, count == 1 || count == 2);
reed@google.com6fc321a2011-07-27 13:54:36 +000017
18 pts[0].set(0, 0);
19 pts[1].set(SkIntToScalar(3), 0);
20 pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
21 SkConvertQuadToCubic(pts, dst);
22 const SkPoint cubic[] = {
23 0, 0,
24 SkIntToScalar(2), 0,
25 SkIntToScalar(3), SkIntToScalar(1),
26 SkIntToScalar(3), SkIntToScalar(3)
27 };
28 for (int i = 0; i < 4; ++i) {
29 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
30 }
reed@android.comd8730ea2009-02-27 22:06:06 +000031}
32
33#include "TestClassDef.h"
34DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry)