2009-03-02 05:36:20 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "SkPath.h"
|
2010-02-11 11:09:39 +00:00
|
|
|
#include "SkSize.h"
|
2009-03-02 05:36:20 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
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);
|
2011-02-07 19:39:09 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
static void TestPath(skiatest::Reporter* reporter) {
|
2010-02-11 11:09:39 +00:00
|
|
|
{
|
|
|
|
SkSize size;
|
|
|
|
size.fWidth = 3.4f;
|
|
|
|
size.width();
|
|
|
|
size = SkSize::Make(3,4);
|
|
|
|
SkISize isize = SkISize::Make(3,4);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkTSize<SkScalar>::Make(3,4);
|
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
SkPath p, p2;
|
|
|
|
SkRect bounds, bounds2;
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
2009-06-03 02:35:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
2009-03-02 05:36:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
|
|
|
|
REPORTER_ASSERT(reporter, !p.isInverseFillType());
|
|
|
|
REPORTER_ASSERT(reporter, p == p2);
|
|
|
|
REPORTER_ASSERT(reporter, !(p != p2));
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
|
2009-06-03 02:35:01 +00:00
|
|
|
|
|
|
|
p.setIsConvex(false);
|
|
|
|
p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
|
|
|
|
check_convex_bounds(reporter, p, bounds);
|
2011-02-07 19:39:09 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
p.reset();
|
|
|
|
p.setIsConvex(false);
|
|
|
|
p.addOval(bounds);
|
|
|
|
check_convex_bounds(reporter, p, bounds);
|
2011-02-07 19:39:09 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
p.reset();
|
|
|
|
p.setIsConvex(false);
|
2009-03-02 05:36:20 +00:00
|
|
|
p.addRect(bounds);
|
2009-06-03 02:35:01 +00:00
|
|
|
check_convex_bounds(reporter, p, bounds);
|
2009-03-02 05:36:20 +00:00
|
|
|
|
|
|
|
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);
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
|
|
|
|
p.offset(SK_Scalar1*3, SK_Scalar1*4);
|
2009-04-01 18:31:44 +00:00
|
|
|
REPORTER_ASSERT(reporter, bounds == p.getBounds());
|
2009-03-02 05:36:20 +00:00
|
|
|
|
|
|
|
#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);
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
// 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);
|
2011-02-07 19:39:09 +00:00
|
|
|
|
|
|
|
// 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());
|
2009-03-02 05:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
|