2013-04-26 19:51:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkPath.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkPathOps.h"
|
2013-04-26 19:51:16 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static const SkPoint nonFinitePts[] = {
|
|
|
|
{ SK_ScalarInfinity, 0 },
|
|
|
|
{ 0, SK_ScalarInfinity },
|
|
|
|
{ SK_ScalarInfinity, SK_ScalarInfinity },
|
|
|
|
{ SK_ScalarNegativeInfinity, 0},
|
|
|
|
{ 0, SK_ScalarNegativeInfinity },
|
|
|
|
{ SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
|
|
|
|
{ SK_ScalarNegativeInfinity, SK_ScalarInfinity },
|
|
|
|
{ SK_ScalarInfinity, SK_ScalarNegativeInfinity },
|
|
|
|
{ SK_ScalarNaN, 0 },
|
|
|
|
{ 0, SK_ScalarNaN },
|
|
|
|
{ SK_ScalarNaN, SK_ScalarNaN },
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
|
|
|
|
|
|
|
|
static const SkPoint finitePts[] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SK_ScalarMax, 0 },
|
|
|
|
{ 0, SK_ScalarMax },
|
|
|
|
{ SK_ScalarMax, SK_ScalarMax },
|
|
|
|
{ SK_ScalarMin, 0 },
|
|
|
|
{ 0, SK_ScalarMin },
|
|
|
|
{ SK_ScalarMin, SK_ScalarMin },
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
|
|
|
|
|
2013-09-16 15:55:01 +00:00
|
|
|
static void failOne(skiatest::Reporter* reporter, int index) {
|
|
|
|
SkPath path;
|
|
|
|
int i = (int) (index % nonFinitePtsCount);
|
|
|
|
int f = (int) (index % finitePtsCount);
|
|
|
|
int g = (int) ((f + 1) % finitePtsCount);
|
|
|
|
switch (index % 13) {
|
|
|
|
case 0: path.lineTo(nonFinitePts[i]); break;
|
|
|
|
case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
|
|
|
|
case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
|
|
|
|
case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
|
|
|
|
case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
|
|
|
|
case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
|
|
|
|
case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
|
|
|
|
case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
|
|
|
|
case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
|
|
|
|
case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
|
|
|
|
case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
|
|
|
|
case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
|
|
|
|
case 12: path.moveTo(nonFinitePts[i]); break;
|
|
|
|
}
|
|
|
|
SkPath result;
|
|
|
|
result.setFillType(SkPath::kWinding_FillType);
|
|
|
|
bool success = Simplify(path, &result);
|
|
|
|
REPORTER_ASSERT(reporter, !success);
|
|
|
|
REPORTER_ASSERT(reporter, result.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType);
|
|
|
|
reporter->bumpTestCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dontFailOne(skiatest::Reporter* reporter, int index) {
|
|
|
|
SkPath path;
|
|
|
|
int f = (int) (index % finitePtsCount);
|
|
|
|
int g = (int) ((f + 1) % finitePtsCount);
|
|
|
|
switch (index % 11) {
|
|
|
|
case 0: path.lineTo(finitePts[f]); break;
|
|
|
|
case 1: path.quadTo(finitePts[f], finitePts[f]); break;
|
|
|
|
case 2: path.quadTo(finitePts[f], finitePts[g]); break;
|
|
|
|
case 3: path.quadTo(finitePts[g], finitePts[f]); break;
|
|
|
|
case 4: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
|
|
|
|
case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
|
|
|
|
case 6: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
|
|
|
|
case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
|
|
|
|
case 8: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
|
|
|
|
case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
|
|
|
|
case 10: path.moveTo(finitePts[f]); break;
|
|
|
|
}
|
|
|
|
SkPath result;
|
|
|
|
result.setFillType(SkPath::kWinding_FillType);
|
|
|
|
bool success = Simplify(path, &result);
|
2015-03-26 14:52:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, success);
|
2013-09-16 15:55:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
|
|
|
|
reporter->bumpTestCount();
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsSimplifyFail, reporter) {
|
2013-04-26 19:51:16 +00:00
|
|
|
for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
|
2013-09-16 15:55:01 +00:00
|
|
|
failOne(reporter, index);
|
2013-04-26 20:41:24 +00:00
|
|
|
}
|
2013-04-26 19:51:16 +00:00
|
|
|
for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
|
2013-09-16 15:55:01 +00:00
|
|
|
dontFailOne(reporter, index);
|
2013-04-26 19:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsSimplifyFailOne, reporter) {
|
2013-09-16 15:55:01 +00:00
|
|
|
int index = 0;
|
|
|
|
failOne(reporter, index);
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsSimplifyDontFailOne, reporter) {
|
2014-04-14 17:08:59 +00:00
|
|
|
int index = 13;
|
2013-09-16 15:55:01 +00:00
|
|
|
dontFailOne(reporter, index);
|
|
|
|
}
|