add test for SkConvertQuadToCubic
git-svn-id: http://skia.googlecode.com/svn/trunk@1967 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
9510ccc06b
commit
6fc321a18a
@ -448,18 +448,20 @@ int SkChopQuadAtMaxCurvature(const SkPoint src[3], SkPoint dst[5])
|
||||
}
|
||||
}
|
||||
|
||||
void SkConvertQuadToCubic(const SkPoint src[3], SkPoint dst[4])
|
||||
{
|
||||
SkScalar two = SkIntToScalar(2);
|
||||
SkScalar one_third = SkScalarDiv(SK_Scalar1, SkIntToScalar(3));
|
||||
dst[0].set(src[0].fX, src[0].fY);
|
||||
dst[1].set(
|
||||
SkScalarMul(SkScalarMulAdd(src[1].fX, two, src[0].fX), one_third),
|
||||
SkScalarMul(SkScalarMulAdd(src[1].fY, two, src[0].fY), one_third));
|
||||
dst[2].set(
|
||||
SkScalarMul(SkScalarMulAdd(src[1].fX, two, src[2].fX), one_third),
|
||||
SkScalarMul(SkScalarMulAdd(src[1].fY, two, src[2].fY), one_third));
|
||||
dst[3].set(src[2].fX, src[2].fY);
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
#define SK_ScalarTwoThirds (0.666666666f)
|
||||
#else
|
||||
#define SK_ScalarTwoThirds ((SkFixed)(43691))
|
||||
#endif
|
||||
|
||||
void SkConvertQuadToCubic(const SkPoint src[3], SkPoint dst[4]) {
|
||||
const SkScalar scale = SK_ScalarTwoThirds;
|
||||
dst[0] = src[0];
|
||||
dst[1].set(src[0].fX + SkScalarMul(src[1].fX - src[0].fX, scale),
|
||||
src[0].fY + SkScalarMul(src[1].fY - src[0].fY, scale));
|
||||
dst[2].set(src[2].fX + SkScalarMul(src[1].fX - src[2].fX, scale),
|
||||
src[2].fY + SkScalarMul(src[1].fY - src[2].fY, scale));
|
||||
dst[3] = src[2];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "Test.h"
|
||||
#include "SkGeometry.h"
|
||||
|
||||
static bool nearly_equal(const SkPoint& a, const SkPoint& b) {
|
||||
return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY);
|
||||
}
|
||||
|
||||
static void TestGeometry(skiatest::Reporter* reporter) {
|
||||
SkPoint pts[3], dst[5];
|
||||
|
||||
@ -10,6 +14,20 @@ static void TestGeometry(skiatest::Reporter* reporter) {
|
||||
|
||||
int count = SkChopQuadAtMaxCurvature(pts, dst);
|
||||
REPORTER_ASSERT(reporter, count == 1 || count == 2);
|
||||
|
||||
pts[0].set(0, 0);
|
||||
pts[1].set(SkIntToScalar(3), 0);
|
||||
pts[2].set(SkIntToScalar(3), SkIntToScalar(3));
|
||||
SkConvertQuadToCubic(pts, dst);
|
||||
const SkPoint cubic[] = {
|
||||
0, 0,
|
||||
SkIntToScalar(2), 0,
|
||||
SkIntToScalar(3), SkIntToScalar(1),
|
||||
SkIntToScalar(3), SkIntToScalar(3)
|
||||
};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i]));
|
||||
}
|
||||
}
|
||||
|
||||
#include "TestClassDef.h"
|
||||
|
Loading…
Reference in New Issue
Block a user