skia2/tests/ClipperTest.cpp
epoger@google.com ec3ed6a5eb 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

97 lines
3.2 KiB
C++

/*
* 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 "SkPath.h"
#include "SkLineClipper.h"
#include "SkEdgeClipper.h"
static void test_intersectline(skiatest::Reporter* reporter) {
static const SkScalar L = 0;
static const SkScalar T = 0;
static const SkScalar R = SkIntToScalar(100);
static const SkScalar B = SkIntToScalar(100);
static const SkScalar CX = SkScalarHalf(L + R);
static const SkScalar CY = SkScalarHalf(T + B);
static const SkRect gR = { L, T, R, B };
size_t i;
SkPoint dst[2];
static const SkPoint gEmpty[] = {
// sides
{ L, CY }, { L - 10, CY },
{ R, CY }, { R + 10, CY },
{ CX, T }, { CX, T - 10 },
{ CX, B }, { CX, B + 10 },
// corners
{ L, T }, { L - 10, T - 10 },
{ L, B }, { L - 10, B + 10 },
{ R, T }, { R + 10, T - 10 },
{ R, B }, { R + 10, B + 10 },
};
for (i = 0; i < SK_ARRAY_COUNT(gEmpty); i += 2) {
bool valid = SkLineClipper::IntersectLine(&gEmpty[i], gR, dst);
if (valid) {
SkDebugf("----- [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY);
}
REPORTER_ASSERT(reporter, !valid);
}
static const SkPoint gFull[] = {
// diagonals, chords
{ L, T }, { R, B },
{ L, B }, { R, T },
{ CX, T }, { CX, B },
{ L, CY }, { R, CY },
{ CX, T }, { R, CY },
{ CX, T }, { L, CY },
{ L, CY }, { CX, B },
{ R, CY }, { CX, B },
// edges
{ L, T }, { L, B },
{ R, T }, { R, B },
{ L, T }, { R, T },
{ L, B }, { R, B },
};
for (i = 0; i < SK_ARRAY_COUNT(gFull); i += 2) {
bool valid = SkLineClipper::IntersectLine(&gFull[i], gR, dst);
if (!valid || memcmp(&gFull[i], dst, sizeof(dst))) {
SkDebugf("++++ [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY);
}
REPORTER_ASSERT(reporter, valid && !memcmp(&gFull[i], dst, sizeof(dst)));
}
static const SkPoint gPartial[] = {
{ L - 10, CY }, { CX, CY }, { L, CY }, { CX, CY },
{ CX, T - 10 }, { CX, CY }, { CX, T }, { CX, CY },
{ R + 10, CY }, { CX, CY }, { R, CY }, { CX, CY },
{ CX, B + 10 }, { CX, CY }, { CX, B }, { CX, CY },
// extended edges
{ L, T - 10 }, { L, B + 10 }, { L, T }, { L, B },
{ R, T - 10 }, { R, B + 10 }, { R, T }, { R, B },
{ L - 10, T }, { R + 10, T }, { L, T }, { R, T },
{ L - 10, B }, { R + 10, B }, { L, B }, { R, B },
};
for (i = 0; i < SK_ARRAY_COUNT(gPartial); i += 4) {
bool valid = SkLineClipper::IntersectLine(&gPartial[i], gR, dst);
if (!valid || memcmp(&gPartial[i+2], dst, sizeof(dst))) {
SkDebugf("++++ [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY);
}
REPORTER_ASSERT(reporter, valid &&
!memcmp(&gPartial[i+2], dst, sizeof(dst)));
}
}
void TestClipper(skiatest::Reporter* reporter) {
test_intersectline(reporter);
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("Clipper", TestClipperClass, TestClipper)