2015-01-16 15:04:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-03-26 14:52:43 +00:00
|
|
|
|
|
|
|
#include "PathOpsExtendedTest.h"
|
2015-01-16 15:04:10 +00:00
|
|
|
#include "PathOpsTestCommon.h"
|
2015-03-26 14:52:43 +00:00
|
|
|
#include "SkBitmap.h"
|
2015-01-16 15:04:10 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsBuilder, reporter) {
|
|
|
|
SkOpBuilder builder;
|
|
|
|
SkPath result;
|
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isEmpty());
|
|
|
|
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(result, kDifference_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isEmpty());
|
|
|
|
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(result, kUnion_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isEmpty());
|
|
|
|
|
|
|
|
SkPath rectPath;
|
2015-03-26 14:52:43 +00:00
|
|
|
rectPath.setFillType(SkPath::kEvenOdd_FillType);
|
2015-01-16 15:04:10 +00:00
|
|
|
rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction);
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(rectPath, kUnion_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
bool closed;
|
|
|
|
SkPath::Direction dir;
|
|
|
|
REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir));
|
|
|
|
REPORTER_ASSERT(reporter, closed);
|
|
|
|
REPORTER_ASSERT(reporter, dir == SkPath::kCW_Direction);
|
|
|
|
REPORTER_ASSERT(reporter, rectPath == result);
|
|
|
|
|
|
|
|
rectPath.reset();
|
2015-03-26 14:52:43 +00:00
|
|
|
rectPath.setFillType(SkPath::kEvenOdd_FillType);
|
2015-01-16 15:04:10 +00:00
|
|
|
rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction);
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(rectPath, kUnion_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir));
|
|
|
|
REPORTER_ASSERT(reporter, closed);
|
|
|
|
REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction);
|
2015-03-26 14:52:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rectPath == result);
|
2015-01-16 15:04:10 +00:00
|
|
|
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(rectPath, kDifference_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isEmpty());
|
|
|
|
|
|
|
|
SkPath rect2, rect3;
|
|
|
|
rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction);
|
|
|
|
rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction);
|
2015-03-26 14:52:43 +00:00
|
|
|
builder.add(rectPath, kUnion_SkPathOp);
|
|
|
|
builder.add(rect2, kUnion_SkPathOp);
|
|
|
|
builder.add(rect3, kUnion_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
|
|
|
REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir));
|
|
|
|
REPORTER_ASSERT(reporter, closed);
|
|
|
|
SkRect expected;
|
|
|
|
expected.set(0, 1, 5, 3);
|
|
|
|
REPORTER_ASSERT(reporter, result.getBounds() == expected);
|
|
|
|
|
|
|
|
SkPath circle1, circle2, circle3;
|
|
|
|
circle1.addCircle(5, 6, 4, SkPath::kCW_Direction);
|
|
|
|
circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction);
|
|
|
|
circle3.addCircle(6, 5, 6, SkPath::kCW_Direction);
|
|
|
|
SkPath opCompare;
|
2015-03-26 14:52:43 +00:00
|
|
|
Op(circle1, circle2, kUnion_SkPathOp, &opCompare);
|
|
|
|
Op(opCompare, circle3, kDifference_SkPathOp, &opCompare);
|
|
|
|
builder.add(circle1, kUnion_SkPathOp);
|
|
|
|
builder.add(circle2, kUnion_SkPathOp);
|
|
|
|
builder.add(circle3, kDifference_SkPathOp);
|
2015-01-16 15:04:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, builder.resolve(&result));
|
2015-03-26 14:52:43 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
int pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result, bitmap);
|
|
|
|
REPORTER_ASSERT(reporter, pixelDiff == 0);
|
2015-01-16 15:04:10 +00:00
|
|
|
}
|