skia2/tests/GeometryTest.cpp

66 lines
1.9 KiB
C++
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
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.
*/
#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 testChopCubic(skiatest::Reporter* reporter) {
/*
Inspired by this test, which used to assert that the tValues had dups
<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];
// make sure we don't assert internally
int count = SkChopCubicAtMaxCurvature(src, dst, tValues);
if (false) { // avoid bit rot, suppress warning
REPORTER_ASSERT(reporter, count);
}
}
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);
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]));
}
testChopCubic(reporter);
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry)