2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-02-27 22:06:06 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkGeometry.h"
|
|
|
|
|
2011-07-27 13:54:36 +00:00
|
|
|
static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
|
|
|
|
return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY);
|
|
|
|
}
|
|
|
|
|
2012-02-29 20:59:24 +00:00
|
|
|
static void testChopCubic(skiatest::Reporter* reporter) {
|
|
|
|
/*
|
|
|
|
Inspired by this test, which used to assert that the tValues had dups
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-29 20:59:24 +00:00
|
|
|
<path stroke="#202020" d="M0,0 C0,0 1,1 2190,5130 C2190,5070 2220,5010 2205,4980" />
|
|
|
|
*/
|
|
|
|
const SkPoint src[] = {
|
|
|
|
{ SkIntToScalar(2190), SkIntToScalar(5130) },
|
|
|
|
{ SkIntToScalar(2190), SkIntToScalar(5070) },
|
|
|
|
{ SkIntToScalar(2220), SkIntToScalar(5010) },
|
|
|
|
{ SkIntToScalar(2205), SkIntToScalar(4980) },
|
|
|
|
};
|
|
|
|
SkPoint dst[13];
|
|
|
|
SkScalar tValues[3];
|
2012-02-29 21:57:36 +00:00
|
|
|
// make sure we don't assert internally
|
2012-02-29 20:59:24 +00:00
|
|
|
int count = SkChopCubicAtMaxCurvature(src, dst, tValues);
|
2012-06-06 12:03:39 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
REPORTER_ASSERT(reporter, count);
|
|
|
|
}
|
2012-02-29 20:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 22:06:06 +00:00
|
|
|
static void TestGeometry(skiatest::Reporter* reporter) {
|
|
|
|
SkPoint pts[3], dst[5];
|
|
|
|
|
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(100, 50);
|
|
|
|
pts[2].set(0, 100);
|
|
|
|
|
|
|
|
int count = SkChopQuadAtMaxCurvature(pts, dst);
|
|
|
|
REPORTER_ASSERT(reporter, count == 1 || count == 2);
|
2011-07-27 13:54:36 +00:00
|
|
|
|
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(SkIntToScalar(3), 0);
|
|
|
|
pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
|
|
|
|
SkConvertQuadToCubic(pts, dst);
|
|
|
|
const SkPoint cubic[] = {
|
2011-07-28 21:10:29 +00:00
|
|
|
{ 0, 0, },
|
|
|
|
{ SkIntToScalar(2), 0, },
|
|
|
|
{ SkIntToScalar(3), SkIntToScalar(1), },
|
|
|
|
{ SkIntToScalar(3), SkIntToScalar(3) },
|
2011-07-27 13:54:36 +00:00
|
|
|
};
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-29 20:59:24 +00:00
|
|
|
testChopCubic(reporter);
|
2009-02-27 22:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry)
|