04863fa14a
git-svn-id: http://skia.googlecode.com/svn/trunk@1324 2bbb7eff-a529-9590-31e7-b0007b416f81
170 lines
5.2 KiB
C++
170 lines
5.2 KiB
C++
#include "Test.h"
|
|
#include "SkPath.h"
|
|
#include "SkParse.h"
|
|
#include "SkSize.h"
|
|
|
|
static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
|
|
const SkRect& bounds) {
|
|
REPORTER_ASSERT(reporter, p.isConvex());
|
|
REPORTER_ASSERT(reporter, p.getBounds() == bounds);
|
|
|
|
SkPath p2(p);
|
|
REPORTER_ASSERT(reporter, p2.isConvex());
|
|
REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
|
|
|
|
SkPath other;
|
|
other.swap(p2);
|
|
REPORTER_ASSERT(reporter, other.isConvex());
|
|
REPORTER_ASSERT(reporter, other.getBounds() == bounds);
|
|
}
|
|
|
|
static void setFromString(SkPath* path, const char str[]) {
|
|
bool first = true;
|
|
while (str) {
|
|
SkScalar x, y;
|
|
str = SkParse::FindScalar(str, &x);
|
|
if (NULL == str) {
|
|
break;
|
|
}
|
|
str = SkParse::FindScalar(str, &y);
|
|
SkASSERT(str);
|
|
if (first) {
|
|
path->moveTo(x, y);
|
|
first = false;
|
|
} else {
|
|
path->lineTo(x, y);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void test_convexity(skiatest::Reporter* reporter) {
|
|
static const SkPath::Convexity U = SkPath::kUnknown_Convexity;
|
|
static const SkPath::Convexity C = SkPath::kConcave_Convexity;
|
|
static const SkPath::Convexity V = SkPath::kConvex_Convexity;
|
|
|
|
SkPath path;
|
|
|
|
REPORTER_ASSERT(reporter, U == SkPath::ComputeConvexity(path));
|
|
path.addCircle(0, 0, 10);
|
|
REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path));
|
|
path.addCircle(0, 0, 10); // 2nd circle
|
|
REPORTER_ASSERT(reporter, C == SkPath::ComputeConvexity(path));
|
|
path.reset();
|
|
path.addRect(0, 0, 10, 10, SkPath::kCCW_Direction);
|
|
REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path));
|
|
path.reset();
|
|
path.addRect(0, 0, 10, 10, SkPath::kCW_Direction);
|
|
REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path));
|
|
|
|
static const struct {
|
|
const char* fPathStr;
|
|
SkPath::Convexity fExpectedConvexity;
|
|
} gRec[] = {
|
|
{ "0 0", SkPath::kUnknown_Convexity },
|
|
{ "0 0 10 10", SkPath::kUnknown_Convexity },
|
|
{ "0 0 10 10 20 20 0 0 10 10", SkPath::kUnknown_Convexity },
|
|
{ "0 0 10 10 10 20", SkPath::kConvex_Convexity },
|
|
{ "0 0 10 10 10 0", SkPath::kConvex_Convexity },
|
|
{ "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity },
|
|
{ "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity },
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
SkPath path;
|
|
setFromString(&path, gRec[i].fPathStr);
|
|
SkPath::Convexity c = SkPath::ComputeConvexity(path);
|
|
REPORTER_ASSERT(reporter, c == gRec[i].fExpectedConvexity);
|
|
}
|
|
}
|
|
|
|
void TestPath(skiatest::Reporter* reporter);
|
|
void TestPath(skiatest::Reporter* reporter) {
|
|
{
|
|
SkSize size;
|
|
size.fWidth = 3.4f;
|
|
size.width();
|
|
size = SkSize::Make(3,4);
|
|
SkISize isize = SkISize::Make(3,4);
|
|
}
|
|
|
|
SkTSize<SkScalar>::Make(3,4);
|
|
|
|
SkPath p, p2;
|
|
SkRect bounds, bounds2;
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
|
|
REPORTER_ASSERT(reporter, !p.isInverseFillType());
|
|
REPORTER_ASSERT(reporter, p == p2);
|
|
REPORTER_ASSERT(reporter, !(p != p2));
|
|
|
|
REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
|
|
|
|
bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
|
|
|
|
p.setIsConvex(false);
|
|
p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
|
|
check_convex_bounds(reporter, p, bounds);
|
|
|
|
p.reset();
|
|
p.setIsConvex(false);
|
|
p.addOval(bounds);
|
|
check_convex_bounds(reporter, p, bounds);
|
|
|
|
p.reset();
|
|
p.setIsConvex(false);
|
|
p.addRect(bounds);
|
|
check_convex_bounds(reporter, p, bounds);
|
|
|
|
REPORTER_ASSERT(reporter, p != p2);
|
|
REPORTER_ASSERT(reporter, !(p == p2));
|
|
|
|
// does getPoints return the right result
|
|
REPORTER_ASSERT(reporter, p.getPoints(NULL, 5) == 4);
|
|
SkPoint pts[4];
|
|
int count = p.getPoints(pts, 4);
|
|
REPORTER_ASSERT(reporter, count == 4);
|
|
bounds2.set(pts, 4);
|
|
REPORTER_ASSERT(reporter, bounds == bounds2);
|
|
|
|
bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
|
|
p.offset(SK_Scalar1*3, SK_Scalar1*4);
|
|
REPORTER_ASSERT(reporter, bounds == p.getBounds());
|
|
|
|
#if 0 // isRect needs to be implemented
|
|
REPORTER_ASSERT(reporter, p.isRect(NULL));
|
|
bounds.setEmpty();
|
|
REPORTER_ASSERT(reporter, p.isRect(&bounds2));
|
|
REPORTER_ASSERT(reporter, bounds == bounds2);
|
|
|
|
// now force p to not be a rect
|
|
bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
|
|
p.addRect(bounds);
|
|
REPORTER_ASSERT(reporter, !p.isRect(NULL));
|
|
#endif
|
|
|
|
SkPoint pt;
|
|
|
|
p.moveTo(SK_Scalar1, 0);
|
|
p.getLastPt(&pt);
|
|
REPORTER_ASSERT(reporter, pt.fX == SK_Scalar1);
|
|
|
|
// check that reset and rewind clear the convex hint back to false
|
|
p.setIsConvex(false);
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
p.setIsConvex(true);
|
|
REPORTER_ASSERT(reporter, p.isConvex());
|
|
p.reset();
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
p.setIsConvex(true);
|
|
REPORTER_ASSERT(reporter, p.isConvex());
|
|
p.rewind();
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
|
|
test_convexity(reporter);
|
|
}
|
|
|
|
#include "TestClassDef.h"
|
|
DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
|