2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-10-15 15:35:29 +00:00
|
|
|
|
2012-09-14 15:18:41 +00:00
|
|
|
#include "SkCanvas.h"
|
2011-09-07 12:23:41 +00:00
|
|
|
#include "SkPaint.h"
|
2011-05-15 04:08:24 +00:00
|
|
|
#include "SkParse.h"
|
2012-01-10 18:44:37 +00:00
|
|
|
#include "SkParsePath.h"
|
2015-06-10 21:23:15 +00:00
|
|
|
#include "SkPathPriv.h"
|
2012-05-29 12:03:46 +00:00
|
|
|
#include "SkPathEffect.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkRRect.h"
|
2012-01-04 21:05:51 +00:00
|
|
|
#include "SkRandom.h"
|
2011-09-21 19:05:12 +00:00
|
|
|
#include "SkReader32.h"
|
2010-02-11 11:09:39 +00:00
|
|
|
#include "SkSize.h"
|
2014-06-24 15:30:15 +00:00
|
|
|
#include "SkStream.h"
|
2012-09-14 15:18:41 +00:00
|
|
|
#include "SkSurface.h"
|
2013-08-07 19:17:53 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "SkWriter32.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2012-09-14 15:18:41 +00:00
|
|
|
|
2014-12-15 20:28:33 +00:00
|
|
|
static void set_radii(SkVector radii[4], int index, float rad) {
|
|
|
|
sk_bzero(radii, sizeof(SkVector) * 4);
|
|
|
|
radii[index].set(rad, rad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
|
|
|
|
const SkVector radii[4]) {
|
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectRadii(bounds, radii);
|
|
|
|
REPORTER_ASSERT(reporter, bounds == rrect.rect());
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
// this line should not assert in the debug build (from validate)
|
|
|
|
path.addRRect(rrect);
|
|
|
|
REPORTER_ASSERT(reporter, bounds == path.getBounds());
|
|
|
|
}
|
|
|
|
|
2015-03-02 18:07:56 +00:00
|
|
|
static void test_skbug_3469(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
path.quadTo(20, 50, 80, 50);
|
|
|
|
path.quadTo(20, 50, 20, 80);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isConvex());
|
|
|
|
}
|
|
|
|
|
2014-12-15 20:28:33 +00:00
|
|
|
static void test_skbug_3239(skiatest::Reporter* reporter) {
|
|
|
|
const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
|
|
|
|
const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
|
|
|
|
const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
|
|
|
|
|
|
|
|
const float rad = 33436320;
|
|
|
|
|
|
|
|
const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
|
|
|
|
const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
|
|
|
|
|
|
|
|
SkVector radii[4];
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
set_radii(radii, i, rad);
|
|
|
|
test_add_rrect(reporter, rectx, radii);
|
|
|
|
test_add_rrect(reporter, recty, radii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 16:04:42 +00:00
|
|
|
static void make_path_crbug364224(SkPath* path) {
|
|
|
|
path->reset();
|
|
|
|
path->moveTo(3.747501373f, 2.724499941f);
|
|
|
|
path->lineTo(3.747501373f, 3.75f);
|
|
|
|
path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
|
|
|
|
path->lineTo(0.7475013733f, 4.0f);
|
|
|
|
path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
|
|
|
|
path->lineTo(0.4975013733f, 1.0f);
|
|
|
|
path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
|
|
|
|
path->lineTo(3.497501373f, 0.75f);
|
|
|
|
path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
|
|
|
|
path->lineTo(3.715001345f, 0.5512499809f);
|
|
|
|
path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
|
|
|
|
path->lineTo(0.7475013733f, 0.4999999702f);
|
|
|
|
path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
|
|
|
|
path->lineTo(0.2475013733f, 3.75f);
|
|
|
|
path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
|
|
|
|
path->lineTo(3.497501373f, 4.25f);
|
|
|
|
path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
|
|
|
|
path->lineTo(3.997501373f, 2.474750042f);
|
|
|
|
path->lineTo(3.747501373f, 2.724499941f);
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path_crbug364224_simplified(SkPath* path) {
|
|
|
|
path->moveTo(3.747501373f, 2.724499941f);
|
|
|
|
path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_path_crbug364224() {
|
|
|
|
SkPath path;
|
|
|
|
SkPaint paint;
|
2014-12-10 15:24:28 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
|
2014-05-05 16:04:42 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
make_path_crbug364224_simplified(&path);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
make_path_crbug364224(&path);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
Fallback to moveTo when unable to find the first tangent in cubicTo
When calling cubicTo(a, b, c) and if the distance between fPrevPt and a
is too small, b is used instead of a to calculate the first tangent,
even if the distance between fPrevPt and b is too small.
In debug mode, this is causing an assertion to fail in
SkPathStroker::preJoinTo() and, in Release, the use of an
unitialized value.
The first patch set is adding a failing test.
The second one add the fix to SkPathStroker::cubicTo()
BUG=skia:2820
R=bsalomon@chromium.org, junov@chromium.org, reed@google.com, caryclark@google.com, bsalomon@google.com
Author: piotaixr@chromium.org
Review URL: https://codereview.chromium.org/460813002
2014-08-26 18:59:04 +00:00
|
|
|
/**
|
|
|
|
* In debug mode, this path was causing an assertion to fail in
|
|
|
|
* SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
|
|
|
|
*/
|
|
|
|
static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
|
|
|
|
SkPoint orig, p1, p2, p3;
|
|
|
|
orig = SkPoint::Make(1.f, 1.f);
|
|
|
|
p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
|
|
|
|
p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
|
|
|
|
p3 = SkPoint::Make(2.f, 2.f);
|
|
|
|
|
|
|
|
path->reset();
|
|
|
|
path->moveTo(orig);
|
|
|
|
path->cubicTo(p1, p2, p3);
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
|
|
|
|
SkPath path;
|
|
|
|
make_path_crbugskia2820(&path, reporter);
|
|
|
|
|
|
|
|
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
|
|
|
|
stroke.setStrokeStyle(2 * SK_Scalar1);
|
|
|
|
stroke.applyToPath(&path, path);
|
|
|
|
}
|
|
|
|
|
2013-10-15 15:35:29 +00:00
|
|
|
static void make_path0(SkPath* path) {
|
|
|
|
// from * https://code.google.com/p/skia/issues/detail?id=1706
|
|
|
|
|
|
|
|
path->moveTo(146.939f, 1012.84f);
|
|
|
|
path->lineTo(181.747f, 1009.18f);
|
|
|
|
path->lineTo(182.165f, 1013.16f);
|
|
|
|
path->lineTo(147.357f, 1016.82f);
|
|
|
|
path->lineTo(146.939f, 1012.84f);
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_path1(SkPath* path) {
|
|
|
|
path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*PathProc)(SkPath*);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Regression test: we used to crash (overwrite internal storage) during
|
|
|
|
* construction of the region when the path was INVERSE. That is now fixed,
|
|
|
|
* so test these regions (which used to assert/crash).
|
|
|
|
*
|
|
|
|
* https://code.google.com/p/skia/issues/detail?id=1706
|
|
|
|
*/
|
|
|
|
static void test_path_to_region(skiatest::Reporter* reporter) {
|
|
|
|
PathProc procs[] = {
|
|
|
|
make_path0,
|
|
|
|
make_path1,
|
|
|
|
};
|
2013-10-16 07:02:24 +00:00
|
|
|
|
2013-10-15 15:35:29 +00:00
|
|
|
SkRegion clip;
|
|
|
|
clip.setRect(0, 0, 1255, 1925);
|
2013-10-16 07:02:24 +00:00
|
|
|
|
2013-10-15 15:35:29 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
|
|
|
|
SkPath path;
|
|
|
|
procs[i](&path);
|
2013-10-16 07:02:24 +00:00
|
|
|
|
2013-10-15 15:35:29 +00:00
|
|
|
SkRegion rgn;
|
|
|
|
rgn.setPath(path, clip);
|
|
|
|
path.toggleInverseFillType();
|
|
|
|
rgn.setPath(path, clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 13:06:06 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#define SUPPRESS_VISIBILITY_WARNING
|
|
|
|
#else
|
|
|
|
#define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
|
|
|
|
#endif
|
|
|
|
|
2013-08-09 19:48:26 +00:00
|
|
|
static void test_path_close_issue1474(skiatest::Reporter* reporter) {
|
|
|
|
// This test checks that r{Line,Quad,Conic,Cubic}To following a close()
|
|
|
|
// are relative to the point we close to, not relative to the point we close from.
|
|
|
|
SkPath path;
|
|
|
|
SkPoint last;
|
|
|
|
|
|
|
|
// Test rLineTo().
|
|
|
|
path.rLineTo(0, 100);
|
|
|
|
path.rLineTo(100, 0);
|
|
|
|
path.close(); // Returns us back to 0,0.
|
|
|
|
path.rLineTo(50, 50); // This should go to 50,50.
|
|
|
|
|
|
|
|
path.getLastPt(&last);
|
|
|
|
REPORTER_ASSERT(reporter, 50 == last.fX);
|
|
|
|
REPORTER_ASSERT(reporter, 50 == last.fY);
|
|
|
|
|
|
|
|
// Test rQuadTo().
|
|
|
|
path.rewind();
|
|
|
|
path.rLineTo(0, 100);
|
|
|
|
path.rLineTo(100, 0);
|
|
|
|
path.close();
|
|
|
|
path.rQuadTo(50, 50, 75, 75);
|
|
|
|
|
|
|
|
path.getLastPt(&last);
|
|
|
|
REPORTER_ASSERT(reporter, 75 == last.fX);
|
|
|
|
REPORTER_ASSERT(reporter, 75 == last.fY);
|
|
|
|
|
|
|
|
// Test rConicTo().
|
|
|
|
path.rewind();
|
|
|
|
path.rLineTo(0, 100);
|
|
|
|
path.rLineTo(100, 0);
|
|
|
|
path.close();
|
|
|
|
path.rConicTo(50, 50, 85, 85, 2);
|
|
|
|
|
|
|
|
path.getLastPt(&last);
|
|
|
|
REPORTER_ASSERT(reporter, 85 == last.fX);
|
|
|
|
REPORTER_ASSERT(reporter, 85 == last.fY);
|
|
|
|
|
|
|
|
// Test rCubicTo().
|
|
|
|
path.rewind();
|
|
|
|
path.rLineTo(0, 100);
|
|
|
|
path.rLineTo(100, 0);
|
|
|
|
path.close();
|
|
|
|
path.rCubicTo(50, 50, 85, 85, 95, 95);
|
|
|
|
|
|
|
|
path.getLastPt(&last);
|
|
|
|
REPORTER_ASSERT(reporter, 95 == last.fX);
|
|
|
|
REPORTER_ASSERT(reporter, 95 == last.fY);
|
|
|
|
}
|
|
|
|
|
2013-10-30 18:57:55 +00:00
|
|
|
static void test_gen_id(skiatest::Reporter* reporter) {
|
|
|
|
SkPath a, b;
|
|
|
|
REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
|
|
|
|
|
|
|
|
a.moveTo(0, 0);
|
|
|
|
const uint32_t z = a.getGenerationID();
|
|
|
|
REPORTER_ASSERT(reporter, z != b.getGenerationID());
|
|
|
|
|
|
|
|
a.reset();
|
|
|
|
REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
|
|
|
|
|
|
|
|
a.moveTo(1, 1);
|
|
|
|
const uint32_t y = a.getGenerationID();
|
|
|
|
REPORTER_ASSERT(reporter, z != y);
|
|
|
|
|
|
|
|
b.moveTo(2, 2);
|
|
|
|
const uint32_t x = b.getGenerationID();
|
|
|
|
REPORTER_ASSERT(reporter, x != y && x != z);
|
|
|
|
|
|
|
|
a.swap(b);
|
|
|
|
REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
|
|
|
|
|
|
|
|
b = a;
|
|
|
|
REPORTER_ASSERT(reporter, b.getGenerationID() == x);
|
|
|
|
|
|
|
|
SkPath c(a);
|
|
|
|
REPORTER_ASSERT(reporter, c.getGenerationID() == x);
|
|
|
|
|
|
|
|
c.lineTo(3, 3);
|
|
|
|
const uint32_t w = c.getGenerationID();
|
|
|
|
REPORTER_ASSERT(reporter, b.getGenerationID() == x);
|
|
|
|
REPORTER_ASSERT(reporter, a.getGenerationID() == x);
|
|
|
|
REPORTER_ASSERT(reporter, w != x);
|
|
|
|
|
2015-02-17 17:09:53 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2013-10-30 18:57:55 +00:00
|
|
|
static bool kExpectGenIDToIgnoreFill = false;
|
|
|
|
#else
|
|
|
|
static bool kExpectGenIDToIgnoreFill = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
c.toggleInverseFillType();
|
|
|
|
const uint32_t v = c.getGenerationID();
|
|
|
|
REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
|
|
|
|
|
|
|
|
c.rewind();
|
|
|
|
REPORTER_ASSERT(reporter, v != c.getGenerationID());
|
|
|
|
}
|
|
|
|
|
2013-05-08 21:08:21 +00:00
|
|
|
// This used to assert in the debug build, as the edges did not all line-up.
|
|
|
|
static void test_bad_cubic_crbug234190() {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(13.8509f, 3.16858f);
|
|
|
|
path.cubicTo(-2.35893e+08f, -4.21044e+08f,
|
|
|
|
-2.38991e+08f, -4.26573e+08f,
|
|
|
|
-2.41016e+08f, -4.30188e+08f);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2014-12-10 15:24:28 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
|
2013-05-08 21:08:21 +00:00
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2013-04-10 18:44:00 +00:00
|
|
|
static void test_bad_cubic_crbug229478() {
|
|
|
|
const SkPoint pts[] = {
|
2013-04-11 07:01:45 +00:00
|
|
|
{ 4595.91064f, -11596.9873f },
|
|
|
|
{ 4597.2168f, -11595.9414f },
|
|
|
|
{ 4598.52344f, -11594.8955f },
|
|
|
|
{ 4599.83008f, -11593.8496f },
|
2013-04-10 18:44:00 +00:00
|
|
|
};
|
2013-04-11 07:01:45 +00:00
|
|
|
|
2013-04-10 18:44:00 +00:00
|
|
|
SkPath path;
|
|
|
|
path.moveTo(pts[0]);
|
|
|
|
path.cubicTo(pts[1], pts[2], pts[3]);
|
2013-04-11 07:01:45 +00:00
|
|
|
|
2013-04-10 18:44:00 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
2013-04-11 07:01:45 +00:00
|
|
|
|
2013-04-10 18:44:00 +00:00
|
|
|
SkPath dst;
|
|
|
|
// Before the fix, this would infinite-recurse, and run out of stack
|
|
|
|
// because we would keep trying to subdivide a degenerate cubic segment.
|
|
|
|
paint.getFillPath(path, &dst, NULL);
|
|
|
|
}
|
|
|
|
|
2013-01-18 17:49:28 +00:00
|
|
|
static void build_path_170666(SkPath& path) {
|
|
|
|
path.moveTo(17.9459f, 21.6344f);
|
|
|
|
path.lineTo(139.545f, -47.8105f);
|
|
|
|
path.lineTo(139.545f, -47.8105f);
|
|
|
|
path.lineTo(131.07f, -47.3888f);
|
|
|
|
path.lineTo(131.07f, -47.3888f);
|
|
|
|
path.lineTo(122.586f, -46.9532f);
|
|
|
|
path.lineTo(122.586f, -46.9532f);
|
|
|
|
path.lineTo(18076.6f, 31390.9f);
|
|
|
|
path.lineTo(18076.6f, 31390.9f);
|
|
|
|
path.lineTo(18085.1f, 31390.5f);
|
|
|
|
path.lineTo(18085.1f, 31390.5f);
|
|
|
|
path.lineTo(18076.6f, 31390.9f);
|
|
|
|
path.lineTo(18076.6f, 31390.9f);
|
|
|
|
path.lineTo(17955, 31460.3f);
|
|
|
|
path.lineTo(17955, 31460.3f);
|
|
|
|
path.lineTo(17963.5f, 31459.9f);
|
|
|
|
path.lineTo(17963.5f, 31459.9f);
|
|
|
|
path.lineTo(17971.9f, 31459.5f);
|
|
|
|
path.lineTo(17971.9f, 31459.5f);
|
|
|
|
path.lineTo(17.9551f, 21.6205f);
|
|
|
|
path.lineTo(17.9551f, 21.6205f);
|
|
|
|
path.lineTo(9.47091f, 22.0561f);
|
|
|
|
path.lineTo(9.47091f, 22.0561f);
|
|
|
|
path.lineTo(17.9459f, 21.6344f);
|
|
|
|
path.lineTo(17.9459f, 21.6344f);
|
|
|
|
path.close();path.moveTo(0.995934f, 22.4779f);
|
|
|
|
path.lineTo(0.986725f, 22.4918f);
|
|
|
|
path.lineTo(0.986725f, 22.4918f);
|
|
|
|
path.lineTo(17955, 31460.4f);
|
|
|
|
path.lineTo(17955, 31460.4f);
|
|
|
|
path.lineTo(17971.9f, 31459.5f);
|
|
|
|
path.lineTo(17971.9f, 31459.5f);
|
|
|
|
path.lineTo(18093.6f, 31390.1f);
|
|
|
|
path.lineTo(18093.6f, 31390.1f);
|
|
|
|
path.lineTo(18093.6f, 31390);
|
|
|
|
path.lineTo(18093.6f, 31390);
|
|
|
|
path.lineTo(139.555f, -47.8244f);
|
|
|
|
path.lineTo(139.555f, -47.8244f);
|
|
|
|
path.lineTo(122.595f, -46.9671f);
|
|
|
|
path.lineTo(122.595f, -46.9671f);
|
|
|
|
path.lineTo(0.995934f, 22.4779f);
|
|
|
|
path.lineTo(0.995934f, 22.4779f);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(5.43941f, 25.5223f);
|
|
|
|
path.lineTo(798267, -28871.1f);
|
|
|
|
path.lineTo(798267, -28871.1f);
|
|
|
|
path.lineTo(3.12512e+06f, -113102);
|
|
|
|
path.lineTo(3.12512e+06f, -113102);
|
|
|
|
path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
|
|
|
|
path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
|
|
|
|
path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
|
|
|
|
path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
|
|
|
|
path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
|
|
|
|
path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
|
|
|
|
path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
|
|
|
|
path.lineTo(2.78271e+08f, -1.00733e+07f);
|
|
|
|
path.lineTo(2.78271e+08f, -1.00733e+07f);
|
|
|
|
path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
|
|
|
|
path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
|
|
|
|
path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
|
|
|
|
path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
|
|
|
|
path.lineTo(2.77473e+08f, -1.00444e+07f);
|
|
|
|
path.lineTo(2.77473e+08f, -1.00444e+07f);
|
|
|
|
path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
|
|
|
|
path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
|
|
|
|
path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
|
|
|
|
path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
|
|
|
|
path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
|
|
|
|
path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
|
|
|
|
path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
|
|
|
|
path.lineTo(798284, -28872);
|
|
|
|
path.lineTo(798284, -28872);
|
|
|
|
path.lineTo(22.4044f, 24.6677f);
|
|
|
|
path.lineTo(22.4044f, 24.6677f);
|
|
|
|
path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
|
|
|
|
path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void build_path_simple_170666(SkPath& path) {
|
|
|
|
path.moveTo(126.677f, 24.1591f);
|
|
|
|
path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This used to assert in the SK_DEBUG build, as the clip step would fail with
|
|
|
|
// too-few interations in our cubic-line intersection code. That code now runs
|
|
|
|
// 24 interations (instead of 16).
|
2013-02-27 19:17:41 +00:00
|
|
|
static void test_crbug_170666() {
|
2013-01-18 17:49:28 +00:00
|
|
|
SkPath path;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2014-12-10 15:24:28 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
|
2013-01-19 07:05:38 +00:00
|
|
|
|
2013-01-18 17:49:28 +00:00
|
|
|
build_path_simple_170666(path);
|
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
2013-01-19 07:05:38 +00:00
|
|
|
|
2013-01-18 17:49:28 +00:00
|
|
|
build_path_170666(path);
|
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
static void test_addrect(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.lineTo(0, 0);
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, path.isRect(NULL));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.lineTo(FLT_EPSILON, FLT_EPSILON);
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isRect(NULL));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.quadTo(0, 0, 0, 0);
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isRect(NULL));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.conicTo(0, 0, 0, 0, 0.5f);
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isRect(NULL));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.cubicTo(0, 0, 0, 0, 0, 0);
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isRect(NULL));
|
|
|
|
}
|
|
|
|
|
2012-10-24 21:04:04 +00:00
|
|
|
// Make sure we stay non-finite once we get there (unless we reset or rewind).
|
|
|
|
static void test_addrect_isfinite(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
2012-10-25 02:01:20 +00:00
|
|
|
|
2012-10-24 21:04:04 +00:00
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
|
|
|
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(SK_ScalarInfinity, 42);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isFinite());
|
|
|
|
|
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isFinite());
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
2012-10-25 02:01:20 +00:00
|
|
|
|
2012-10-24 21:04:04 +00:00
|
|
|
path.addRect(SkRect::MakeWH(50, 100));
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
|
|
|
}
|
|
|
|
|
2013-01-15 15:51:59 +00:00
|
|
|
static void build_big_path(SkPath* path, bool reducedCase) {
|
|
|
|
if (reducedCase) {
|
|
|
|
path->moveTo(577330, 1971.72f);
|
|
|
|
path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
|
|
|
|
} else {
|
|
|
|
path->moveTo(60.1631f, 7.70567f);
|
|
|
|
path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
|
|
|
|
path->lineTo(577379, 1977.77f);
|
|
|
|
path->quadTo(577364, 1979.57f, 577325, 1980.26f);
|
|
|
|
path->quadTo(577286, 1980.95f, 577245, 1980.13f);
|
|
|
|
path->quadTo(577205, 1979.3f, 577187, 1977.45f);
|
|
|
|
path->quadTo(577168, 1975.6f, 577183, 1973.8f);
|
|
|
|
path->quadTo(577198, 1972, 577238, 1971.31f);
|
|
|
|
path->quadTo(577277, 1970.62f, 577317, 1971.45f);
|
|
|
|
path->quadTo(577330, 1971.72f, 577341, 1972.11f);
|
|
|
|
path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
|
|
|
|
path->moveTo(306.718f, -32.912f);
|
|
|
|
path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void test_clipped_cubic() {
|
2014-12-10 15:24:28 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
|
2013-01-15 15:51:59 +00:00
|
|
|
|
|
|
|
// This path used to assert, because our cubic-chopping code incorrectly
|
|
|
|
// moved control points after the chop. This test should be run in SK_DEBUG
|
|
|
|
// mode to ensure that we no long assert.
|
|
|
|
SkPath path;
|
|
|
|
for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
|
|
|
|
build_big_path(&path, SkToBool(doReducedCase));
|
2013-01-16 07:05:56 +00:00
|
|
|
|
2013-01-15 15:51:59 +00:00
|
|
|
SkPaint paint;
|
|
|
|
for (int doAA = 0; doAA <= 1; ++doAA) {
|
|
|
|
paint.setAntiAlias(SkToBool(doAA));
|
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 15:18:41 +00:00
|
|
|
// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
|
|
|
|
// which triggered an assert, from a tricky cubic. This test replicates that
|
|
|
|
// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
|
|
|
|
// assert in the SK_DEBUG build.
|
2013-02-27 19:17:41 +00:00
|
|
|
static void test_tricky_cubic() {
|
2012-09-14 15:18:41 +00:00
|
|
|
const SkPoint pts[] = {
|
2012-09-15 02:01:41 +00:00
|
|
|
{ SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
|
|
|
|
{ SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
|
|
|
|
{ SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
|
|
|
|
{ SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
|
2012-09-14 15:18:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(pts[0]);
|
|
|
|
path.cubicTo(pts[1], pts[2], pts[3]);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2014-12-10 15:24:28 +00:00
|
|
|
SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130);
|
2012-09-14 15:18:41 +00:00
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
|
|
|
surface->unref();
|
|
|
|
}
|
2009-03-02 05:36:20 +00:00
|
|
|
|
2012-08-10 14:10:45 +00:00
|
|
|
// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
|
|
|
|
//
|
|
|
|
static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.quadTo(157, 366, 286, 208);
|
|
|
|
path.arcTo(37, 442, 315, 163, 957494590897113.0f);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-08-10 14:10:45 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(1000*1000, 1000*1000);
|
|
|
|
|
|
|
|
// Be sure that path::transform correctly updates isFinite and the bounds
|
|
|
|
// if the transformation overflows. The previous bug was that isFinite was
|
|
|
|
// set to true in this case, but the bounds were not set to empty (which
|
|
|
|
// they should be).
|
|
|
|
while (path.isFinite()) {
|
|
|
|
REPORTER_ASSERT(reporter, path.getBounds().isFinite());
|
|
|
|
REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
|
|
|
|
path.transform(matrix);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
|
|
|
|
|
|
|
|
matrix.setTranslate(SK_Scalar1, SK_Scalar1);
|
|
|
|
path.transform(matrix);
|
|
|
|
// we need to still be non-finite
|
|
|
|
REPORTER_ASSERT(reporter, !path.isFinite());
|
|
|
|
REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
|
|
|
|
}
|
|
|
|
|
2012-10-19 02:01:19 +00:00
|
|
|
static void add_corner_arc(SkPath* path, const SkRect& rect,
|
|
|
|
SkScalar xIn, SkScalar yIn,
|
2012-10-18 15:26:12 +00:00
|
|
|
int startAngle)
|
|
|
|
{
|
|
|
|
|
|
|
|
SkScalar rx = SkMinScalar(rect.width(), xIn);
|
|
|
|
SkScalar ry = SkMinScalar(rect.height(), yIn);
|
|
|
|
|
|
|
|
SkRect arcRect;
|
|
|
|
arcRect.set(-rx, -ry, rx, ry);
|
|
|
|
switch (startAngle) {
|
|
|
|
case 0:
|
|
|
|
arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
|
|
|
|
}
|
|
|
|
|
2012-10-19 02:01:19 +00:00
|
|
|
static void make_arb_round_rect(SkPath* path, const SkRect& r,
|
2012-10-18 15:26:12 +00:00
|
|
|
SkScalar xCorner, SkScalar yCorner) {
|
|
|
|
// we are lazy here and use the same x & y for each corner
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 270);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 0);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 90);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 180);
|
2012-10-23 16:56:56 +00:00
|
|
|
path->close();
|
2012-10-18 15:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Chrome creates its own round rects with each corner possibly being different.
|
|
|
|
// Performance will suffer if they are not convex.
|
|
|
|
// Note: PathBench::ArbRoundRectBench performs almost exactly
|
|
|
|
// the same test (but with drawing)
|
|
|
|
static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-10-18 15:26:12 +00:00
|
|
|
SkRect r;
|
|
|
|
|
|
|
|
for (int i = 0; i < 5000; ++i) {
|
|
|
|
|
2012-10-23 16:56:56 +00:00
|
|
|
SkScalar size = rand.nextUScalar1() * 30;
|
|
|
|
if (size < SK_Scalar1) {
|
2012-10-18 15:26:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r.fLeft = rand.nextUScalar1() * 300;
|
|
|
|
r.fTop = rand.nextUScalar1() * 300;
|
2012-10-23 16:56:56 +00:00
|
|
|
r.fRight = r.fLeft + 2 * size;
|
|
|
|
r.fBottom = r.fTop + 2 * size;
|
2012-10-18 15:26:12 +00:00
|
|
|
|
|
|
|
SkPath temp;
|
|
|
|
|
|
|
|
make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, temp.isConvex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 16:56:56 +00:00
|
|
|
// Chrome will sometimes create a 0 radius round rect. The degenerate
|
|
|
|
// quads prevent the path from being converted to a rect
|
|
|
|
// Note: PathBench::ArbRoundRectBench performs almost exactly
|
|
|
|
// the same test (but with drawing)
|
|
|
|
static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-10-23 16:56:56 +00:00
|
|
|
SkRect r;
|
|
|
|
|
|
|
|
for (int i = 0; i < 5000; ++i) {
|
|
|
|
|
|
|
|
SkScalar size = rand.nextUScalar1() * 30;
|
|
|
|
if (size < SK_Scalar1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
r.fLeft = rand.nextUScalar1() * 300;
|
|
|
|
r.fTop = rand.nextUScalar1() * 300;
|
|
|
|
r.fRight = r.fLeft + 2 * size;
|
|
|
|
r.fBottom = r.fTop + 2 * size;
|
|
|
|
|
|
|
|
SkPath temp;
|
|
|
|
|
|
|
|
make_arb_round_rect(&temp, r, 0, 0);
|
|
|
|
|
|
|
|
SkRect result;
|
|
|
|
REPORTER_ASSERT(reporter, temp.isRect(&result));
|
|
|
|
REPORTER_ASSERT(reporter, r == result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
static void test_rect_isfinite(skiatest::Reporter* reporter) {
|
|
|
|
const SkScalar inf = SK_ScalarInfinity;
|
2013-04-12 11:59:41 +00:00
|
|
|
const SkScalar negInf = SK_ScalarNegativeInfinity;
|
2012-07-26 15:20:36 +00:00
|
|
|
const SkScalar nan = SK_ScalarNaN;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
SkRect r;
|
|
|
|
r.setEmpty();
|
|
|
|
REPORTER_ASSERT(reporter, r.isFinite());
|
2013-04-12 11:59:41 +00:00
|
|
|
r.set(0, 0, inf, negInf);
|
2012-07-26 15:20:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, !r.isFinite());
|
|
|
|
r.set(0, 0, nan, 0);
|
|
|
|
REPORTER_ASSERT(reporter, !r.isFinite());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
SkPoint pts[] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SK_Scalar1, 0 },
|
|
|
|
{ 0, SK_Scalar1 },
|
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
bool isFine = r.setBoundsCheck(pts, 3);
|
|
|
|
REPORTER_ASSERT(reporter, isFine);
|
|
|
|
REPORTER_ASSERT(reporter, !r.isEmpty());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
pts[1].set(inf, 0);
|
|
|
|
isFine = r.setBoundsCheck(pts, 3);
|
|
|
|
REPORTER_ASSERT(reporter, !isFine);
|
|
|
|
REPORTER_ASSERT(reporter, r.isEmpty());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
pts[1].set(nan, 0);
|
|
|
|
isFine = r.setBoundsCheck(pts, 3);
|
|
|
|
REPORTER_ASSERT(reporter, !isFine);
|
|
|
|
REPORTER_ASSERT(reporter, r.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_path_isfinite(skiatest::Reporter* reporter) {
|
|
|
|
const SkScalar inf = SK_ScalarInfinity;
|
2013-01-08 20:31:53 +00:00
|
|
|
const SkScalar negInf = SK_ScalarNegativeInfinity;
|
2012-07-26 15:20:36 +00:00
|
|
|
const SkScalar nan = SK_ScalarNaN;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
SkPath path;
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(SK_Scalar1, 0);
|
|
|
|
REPORTER_ASSERT(reporter, path.isFinite());
|
|
|
|
|
|
|
|
path.reset();
|
2013-01-08 20:31:53 +00:00
|
|
|
path.moveTo(inf, negInf);
|
2012-07-26 15:20:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path.isFinite());
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(nan, 0);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isFinite());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_isfinite(skiatest::Reporter* reporter) {
|
|
|
|
test_rect_isfinite(reporter);
|
|
|
|
test_path_isfinite(reporter);
|
|
|
|
}
|
|
|
|
|
2012-05-29 19:54:52 +00:00
|
|
|
// assert that we always
|
|
|
|
// start with a moveTo
|
|
|
|
// only have 1 moveTo
|
|
|
|
// only have Lines after that
|
|
|
|
// end with a single close
|
|
|
|
// only have (at most) 1 close
|
|
|
|
//
|
|
|
|
static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
|
2013-02-27 19:17:41 +00:00
|
|
|
const SkPoint srcPts[], bool expectClose) {
|
2012-05-29 19:54:52 +00:00
|
|
|
SkPath::RawIter iter(path);
|
|
|
|
SkPoint pts[4];
|
|
|
|
|
|
|
|
bool firstTime = true;
|
|
|
|
bool foundClose = false;
|
|
|
|
for (;;) {
|
|
|
|
switch (iter.next(pts)) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, firstTime);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
|
|
|
|
srcPts++;
|
|
|
|
firstTime = false;
|
|
|
|
break;
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, !firstTime);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
|
|
|
|
srcPts++;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
2013-08-22 15:37:26 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
|
2012-05-29 19:54:52 +00:00
|
|
|
break;
|
2013-05-31 15:17:50 +00:00
|
|
|
case SkPath::kConic_Verb:
|
2013-08-22 15:37:26 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
|
2013-05-31 15:17:50 +00:00
|
|
|
break;
|
2012-05-29 19:54:52 +00:00
|
|
|
case SkPath::kCubic_Verb:
|
2013-08-22 15:37:26 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
|
2012-05-29 19:54:52 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, !firstTime);
|
|
|
|
REPORTER_ASSERT(reporter, !foundClose);
|
|
|
|
REPORTER_ASSERT(reporter, expectClose);
|
|
|
|
foundClose = true;
|
|
|
|
break;
|
|
|
|
case SkPath::kDone_Verb:
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DONE:
|
|
|
|
REPORTER_ASSERT(reporter, foundClose == expectClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_addPoly(skiatest::Reporter* reporter) {
|
|
|
|
SkPoint pts[32];
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 19:54:52 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
|
|
|
|
pts[i].fX = rand.nextSScalar1();
|
|
|
|
pts[i].fY = rand.nextSScalar1();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int doClose = 0; doClose <= 1; ++doClose) {
|
|
|
|
for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
|
|
|
|
SkPath path;
|
2014-12-12 23:11:17 +00:00
|
|
|
path.addPoly(pts, SkToInt(count), SkToBool(doClose));
|
2013-02-27 19:17:41 +00:00
|
|
|
test_poly(reporter, path, pts, SkToBool(doClose));
|
2012-05-29 19:54:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
static void test_strokerec(skiatest::Reporter* reporter) {
|
|
|
|
SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
|
|
|
|
REPORTER_ASSERT(reporter, rec.isFillStyle());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
rec.setHairlineStyle();
|
|
|
|
REPORTER_ASSERT(reporter, rec.isHairlineStyle());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
rec.setStrokeStyle(SK_Scalar1, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
rec.setStrokeStyle(SK_Scalar1, true);
|
|
|
|
REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
rec.setStrokeStyle(0, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-29 12:03:46 +00:00
|
|
|
rec.setStrokeStyle(0, true);
|
|
|
|
REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
|
|
|
|
}
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
// Set this for paths that don't have a consistent direction such as a bowtie.
|
|
|
|
// (cheapComputeDirection is not expected to catch these.)
|
2015-06-10 21:23:15 +00:00
|
|
|
const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDirection>(-1);
|
2012-11-13 14:36:42 +00:00
|
|
|
|
|
|
|
static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection expected) {
|
2012-11-13 14:36:42 +00:00
|
|
|
if (expected == kDontCheckDir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
|
|
|
|
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir;
|
|
|
|
if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) {
|
2012-11-13 14:36:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, dir == expected);
|
|
|
|
} else {
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expected);
|
2012-02-17 13:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:44:37 +00:00
|
|
|
static void test_direction(skiatest::Reporter* reporter) {
|
|
|
|
size_t i;
|
|
|
|
SkPath path;
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, NULL));
|
|
|
|
REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
|
|
|
|
REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
|
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kUnknown_FirstDirection));
|
2012-01-10 18:44:37 +00:00
|
|
|
|
|
|
|
static const char* gDegen[] = {
|
|
|
|
"M 10 10",
|
|
|
|
"M 10 10 M 20 20",
|
|
|
|
"M 10 10 L 20 20",
|
|
|
|
"M 10 10 L 10 10 L 10 10",
|
|
|
|
"M 10 10 Q 10 10 10 10",
|
|
|
|
"M 10 10 C 10 10 10 10 10 10",
|
|
|
|
};
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
|
|
|
|
path.reset();
|
|
|
|
bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
|
|
|
|
REPORTER_ASSERT(reporter, valid);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, NULL));
|
2012-01-10 18:44:37 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-10 18:44:37 +00:00
|
|
|
static const char* gCW[] = {
|
2012-01-11 21:03:05 +00:00
|
|
|
"M 10 10 L 10 10 Q 20 10 20 20",
|
2012-01-10 18:44:37 +00:00
|
|
|
"M 10 10 C 20 10 20 20 20 20",
|
2012-01-31 15:42:29 +00:00
|
|
|
"M 20 10 Q 20 20 30 20 L 10 20", // test double-back at y-max
|
2012-07-10 18:28:12 +00:00
|
|
|
// rect with top two corners replaced by cubics with identical middle
|
|
|
|
// control points
|
2012-11-13 13:47:39 +00:00
|
|
|
"M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
|
|
|
|
"M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
|
2012-01-10 18:44:37 +00:00
|
|
|
};
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
|
|
|
|
path.reset();
|
|
|
|
bool valid = SkParsePath::FromSVGString(gCW[i], &path);
|
|
|
|
REPORTER_ASSERT(reporter, valid);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
|
2012-01-10 18:44:37 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-10 18:44:37 +00:00
|
|
|
static const char* gCCW[] = {
|
2012-01-11 21:03:05 +00:00
|
|
|
"M 10 10 L 10 10 Q 20 10 20 -20",
|
2012-01-10 18:44:37 +00:00
|
|
|
"M 10 10 C 20 10 20 -20 20 -20",
|
2012-01-31 15:42:29 +00:00
|
|
|
"M 20 10 Q 20 20 10 20 L 30 20", // test double-back at y-max
|
2012-07-10 18:28:12 +00:00
|
|
|
// rect with top two corners replaced by cubics with identical middle
|
|
|
|
// control points
|
2012-11-13 13:47:39 +00:00
|
|
|
"M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
|
|
|
|
"M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
|
2012-01-10 18:44:37 +00:00
|
|
|
};
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
|
|
|
|
path.reset();
|
|
|
|
bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
|
|
|
|
REPORTER_ASSERT(reporter, valid);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
|
2012-01-10 18:44:37 +00:00
|
|
|
}
|
2012-01-30 20:51:25 +00:00
|
|
|
|
|
|
|
// Test two donuts, each wound a different direction. Only the outer contour
|
|
|
|
// determines the cheap direction
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
|
2012-02-17 13:38:26 +00:00
|
|
|
|
2012-01-30 20:51:25 +00:00
|
|
|
path.reset();
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
|
2012-02-17 13:38:26 +00:00
|
|
|
|
|
|
|
// triangle with one point really far from the origin.
|
|
|
|
path.reset();
|
|
|
|
// the first point is roughly 1.05e10, 1.05e10
|
2013-11-25 19:44:07 +00:00
|
|
|
path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
|
2012-02-23 14:54:49 +00:00
|
|
|
path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
|
|
|
|
path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
|
2013-11-14 16:53:22 +00:00
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.conicTo(20, 0, 20, 20, 0.5f);
|
|
|
|
path.close();
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
|
2013-11-14 16:53:22 +00:00
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.lineTo(1, 1e7f);
|
|
|
|
path.lineTo(1e7f, 2e7f);
|
|
|
|
path.close();
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
|
2012-01-10 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 19:29:14 +00:00
|
|
|
static void add_rect(SkPath* path, const SkRect& r) {
|
|
|
|
path->moveTo(r.fLeft, r.fTop);
|
|
|
|
path->lineTo(r.fRight, r.fTop);
|
|
|
|
path->lineTo(r.fRight, r.fBottom);
|
|
|
|
path->lineTo(r.fLeft, r.fBottom);
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_bounds(skiatest::Reporter* reporter) {
|
|
|
|
static const SkRect rects[] = {
|
2011-11-14 19:34:57 +00:00
|
|
|
{ SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
|
|
|
|
{ SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
|
2011-11-14 19:29:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPath path0, path1;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
|
|
|
|
path0.addRect(rects[i]);
|
|
|
|
add_rect(&path1, rects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
|
|
|
|
}
|
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
static void stroke_cubic(const SkPoint pts[4]) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(pts[0]);
|
|
|
|
path.cubicTo(pts[1], pts[2], pts[3]);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SK_Scalar1 * 2);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
SkPath fill;
|
|
|
|
paint.getFillPath(path, &fill);
|
|
|
|
}
|
|
|
|
|
|
|
|
// just ensure this can run w/o any SkASSERTS firing in the debug build
|
|
|
|
// we used to assert due to differences in how we determine a degenerate vector
|
|
|
|
// but that was fixed with the introduction of SkPoint::CanNormalize
|
|
|
|
static void stroke_tiny_cubic() {
|
|
|
|
SkPoint p0[] = {
|
|
|
|
{ 372.0f, 92.0f },
|
|
|
|
{ 372.0f, 92.0f },
|
|
|
|
{ 372.0f, 92.0f },
|
|
|
|
{ 372.0f, 92.0f },
|
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
stroke_cubic(p0);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
SkPoint p1[] = {
|
|
|
|
{ 372.0f, 92.0f },
|
|
|
|
{ 372.0007f, 92.000755f },
|
|
|
|
{ 371.99927f, 92.003922f },
|
|
|
|
{ 371.99826f, 92.003899f },
|
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-07 12:23:41 +00:00
|
|
|
stroke_cubic(p1);
|
|
|
|
}
|
|
|
|
|
2011-07-13 17:44:36 +00:00
|
|
|
static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2012-04-06 20:01:46 +00:00
|
|
|
SkPath::Iter iter(path, SkToBool(i));
|
2011-07-13 17:44:36 +00:00
|
|
|
SkPoint mv;
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb v;
|
|
|
|
int nMT = 0;
|
|
|
|
int nCL = 0;
|
2011-07-28 21:10:29 +00:00
|
|
|
mv.set(0, 0);
|
2011-07-13 17:44:36 +00:00
|
|
|
while (SkPath::kDone_Verb != (v = iter.next(pts))) {
|
|
|
|
switch (v) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
mv = pts[0];
|
|
|
|
++nMT;
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, mv == pts[0]);
|
|
|
|
++nCL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we force a close on the interator we should have a close
|
|
|
|
// for every moveTo
|
|
|
|
REPORTER_ASSERT(reporter, !i || nMT == nCL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_close(skiatest::Reporter* reporter) {
|
|
|
|
SkPath closePt;
|
|
|
|
closePt.moveTo(0, 0);
|
|
|
|
closePt.close();
|
|
|
|
check_close(reporter, closePt);
|
|
|
|
|
|
|
|
SkPath openPt;
|
|
|
|
openPt.moveTo(0, 0);
|
|
|
|
check_close(reporter, openPt);
|
|
|
|
|
|
|
|
SkPath empty;
|
|
|
|
check_close(reporter, empty);
|
|
|
|
empty.close();
|
|
|
|
check_close(reporter, empty);
|
|
|
|
|
|
|
|
SkPath rect;
|
|
|
|
rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
|
|
|
|
check_close(reporter, rect);
|
|
|
|
rect.close();
|
|
|
|
check_close(reporter, rect);
|
|
|
|
|
|
|
|
SkPath quad;
|
|
|
|
quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
|
|
|
|
check_close(reporter, quad);
|
|
|
|
quad.close();
|
|
|
|
check_close(reporter, quad);
|
|
|
|
|
|
|
|
SkPath cubic;
|
2012-08-23 18:14:13 +00:00
|
|
|
quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
|
2011-07-13 17:44:36 +00:00
|
|
|
10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
|
|
|
|
check_close(reporter, cubic);
|
|
|
|
cubic.close();
|
|
|
|
check_close(reporter, cubic);
|
|
|
|
|
|
|
|
SkPath line;
|
|
|
|
line.moveTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
|
|
|
|
check_close(reporter, line);
|
|
|
|
line.close();
|
|
|
|
check_close(reporter, line);
|
|
|
|
|
|
|
|
SkPath rect2;
|
|
|
|
rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
|
|
|
|
rect2.close();
|
|
|
|
rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
|
|
|
|
check_close(reporter, rect2);
|
|
|
|
rect2.close();
|
|
|
|
check_close(reporter, rect2);
|
|
|
|
|
|
|
|
SkPath oval3;
|
|
|
|
oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
|
|
|
|
oval3.close();
|
|
|
|
oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
|
|
|
|
check_close(reporter, oval3);
|
|
|
|
oval3.close();
|
|
|
|
check_close(reporter, oval3);
|
|
|
|
|
|
|
|
SkPath moves;
|
|
|
|
moves.moveTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
|
|
|
|
moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
|
|
|
|
moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
|
|
|
|
check_close(reporter, moves);
|
2011-09-07 12:23:41 +00:00
|
|
|
|
|
|
|
stroke_tiny_cubic();
|
2011-07-13 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
|
|
|
|
SkPath::Convexity expected) {
|
2012-11-13 14:36:42 +00:00
|
|
|
SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
|
|
|
|
SkPath::Convexity c = copy.getConvexity();
|
2011-05-15 04:38:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, c == expected);
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:02:34 +00:00
|
|
|
static void test_path_crbug389050(skiatest::Reporter* reporter) {
|
|
|
|
SkPath tinyConvexPolygon;
|
|
|
|
tinyConvexPolygon.moveTo(600.131559f, 800.112512f);
|
|
|
|
tinyConvexPolygon.lineTo(600.161735f, 800.118627f);
|
|
|
|
tinyConvexPolygon.lineTo(600.148962f, 800.142338f);
|
|
|
|
tinyConvexPolygon.lineTo(600.134891f, 800.137724f);
|
|
|
|
tinyConvexPolygon.close();
|
|
|
|
tinyConvexPolygon.getConvexity();
|
|
|
|
check_convexity(reporter, tinyConvexPolygon, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, tinyConvexPolygon, SkPathPriv::kCW_FirstDirection);
|
2015-03-02 21:02:34 +00:00
|
|
|
|
|
|
|
SkPath platTriangle;
|
|
|
|
platTriangle.moveTo(0, 0);
|
|
|
|
platTriangle.lineTo(200, 0);
|
|
|
|
platTriangle.lineTo(100, 0.04f);
|
|
|
|
platTriangle.close();
|
|
|
|
platTriangle.getConvexity();
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
|
2015-03-02 21:02:34 +00:00
|
|
|
|
|
|
|
platTriangle.reset();
|
|
|
|
platTriangle.moveTo(0, 0);
|
|
|
|
platTriangle.lineTo(200, 0);
|
|
|
|
platTriangle.lineTo(100, 0.03f);
|
|
|
|
platTriangle.close();
|
|
|
|
platTriangle.getConvexity();
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
|
2015-03-02 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
static void test_convexity2(skiatest::Reporter* reporter) {
|
|
|
|
SkPath pt;
|
|
|
|
pt.moveTo(0, 0);
|
|
|
|
pt.close();
|
2011-05-16 14:16:04 +00:00
|
|
|
check_convexity(reporter, pt, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, pt, SkPathPriv::kUnknown_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath line;
|
2011-12-20 16:33:30 +00:00
|
|
|
line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
|
|
|
|
line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
line.close();
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, line, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, line, SkPathPriv::kUnknown_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath triLeft;
|
|
|
|
triLeft.moveTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
triLeft.lineTo(SK_Scalar1, 0);
|
|
|
|
triLeft.lineTo(SK_Scalar1, SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
triLeft.close();
|
|
|
|
check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, triLeft, SkPathPriv::kCW_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath triRight;
|
|
|
|
triRight.moveTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
triRight.lineTo(-SK_Scalar1, 0);
|
|
|
|
triRight.lineTo(SK_Scalar1, SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
triRight.close();
|
|
|
|
check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, triRight, SkPathPriv::kCCW_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath square;
|
|
|
|
square.moveTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
square.lineTo(SK_Scalar1, 0);
|
|
|
|
square.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
square.lineTo(0, SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
square.close();
|
|
|
|
check_convexity(reporter, square, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, square, SkPathPriv::kCW_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath redundantSquare;
|
|
|
|
redundantSquare.moveTo(0, 0);
|
|
|
|
redundantSquare.lineTo(0, 0);
|
|
|
|
redundantSquare.lineTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
redundantSquare.lineTo(SK_Scalar1, 0);
|
|
|
|
redundantSquare.lineTo(SK_Scalar1, 0);
|
|
|
|
redundantSquare.lineTo(SK_Scalar1, 0);
|
|
|
|
redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
redundantSquare.lineTo(0, SK_Scalar1);
|
|
|
|
redundantSquare.lineTo(0, SK_Scalar1);
|
|
|
|
redundantSquare.lineTo(0, SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
redundantSquare.close();
|
|
|
|
check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, redundantSquare, SkPathPriv::kCW_FirstDirection);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath bowTie;
|
|
|
|
bowTie.moveTo(0, 0);
|
|
|
|
bowTie.lineTo(0, 0);
|
|
|
|
bowTie.lineTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
bowTie.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
bowTie.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
bowTie.lineTo(SK_Scalar1, SK_Scalar1);
|
|
|
|
bowTie.lineTo(SK_Scalar1, 0);
|
|
|
|
bowTie.lineTo(SK_Scalar1, 0);
|
|
|
|
bowTie.lineTo(SK_Scalar1, 0);
|
|
|
|
bowTie.lineTo(0, SK_Scalar1);
|
|
|
|
bowTie.lineTo(0, SK_Scalar1);
|
|
|
|
bowTie.lineTo(0, SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
bowTie.close();
|
|
|
|
check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_direction(reporter, bowTie, kDontCheckDir);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath spiral;
|
|
|
|
spiral.moveTo(0, 0);
|
2011-12-20 16:33:30 +00:00
|
|
|
spiral.lineTo(100*SK_Scalar1, 0);
|
|
|
|
spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
|
|
|
|
spiral.lineTo(0, 100*SK_Scalar1);
|
|
|
|
spiral.lineTo(0, 50*SK_Scalar1);
|
|
|
|
spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
|
|
|
|
spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
spiral.close();
|
2011-05-15 20:25:17 +00:00
|
|
|
check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_direction(reporter, spiral, kDontCheckDir);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:38:34 +00:00
|
|
|
SkPath dent;
|
2011-12-20 16:33:30 +00:00
|
|
|
dent.moveTo(0, 0);
|
|
|
|
dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
|
|
|
|
dent.lineTo(0, 100*SK_Scalar1);
|
|
|
|
dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
|
|
|
|
dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
|
2011-05-15 04:38:34 +00:00
|
|
|
dent.close();
|
|
|
|
check_convexity(reporter, dent, SkPath::kConcave_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, dent, SkPathPriv::kCW_FirstDirection);
|
2014-05-22 14:58:53 +00:00
|
|
|
|
|
|
|
// http://skbug.com/2235
|
|
|
|
SkPath strokedSin;
|
|
|
|
for (int i = 0; i < 2000; i++) {
|
|
|
|
SkScalar x = SkIntToScalar(i) / 2;
|
|
|
|
SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
|
|
|
|
if (0 == i) {
|
|
|
|
strokedSin.moveTo(x, y);
|
|
|
|
} else {
|
|
|
|
strokedSin.lineTo(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
|
|
|
|
stroke.setStrokeStyle(2 * SK_Scalar1);
|
|
|
|
stroke.applyToPath(&strokedSin, strokedSin);
|
|
|
|
check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
|
|
|
|
check_direction(reporter, strokedSin, kDontCheckDir);
|
2014-09-16 16:43:31 +00:00
|
|
|
|
|
|
|
// http://crbug.com/412640
|
|
|
|
SkPath degenerateConcave;
|
|
|
|
degenerateConcave.moveTo(148.67912f, 191.875f);
|
|
|
|
degenerateConcave.lineTo(470.37695f, 7.5f);
|
|
|
|
degenerateConcave.lineTo(148.67912f, 191.875f);
|
|
|
|
degenerateConcave.lineTo(41.446522f, 376.25f);
|
|
|
|
degenerateConcave.lineTo(-55.971577f, 460.0f);
|
|
|
|
degenerateConcave.lineTo(41.446522f, 376.25f);
|
|
|
|
check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_direction(reporter, degenerateConcave, SkPathPriv::kUnknown_FirstDirection);
|
2014-11-17 20:11:42 +00:00
|
|
|
|
|
|
|
// http://crbug.com/433683
|
|
|
|
SkPath badFirstVector;
|
|
|
|
badFirstVector.moveTo(501.087708f, 319.610352f);
|
|
|
|
badFirstVector.lineTo(501.087708f, 319.610352f);
|
|
|
|
badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
|
|
|
|
badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
|
|
|
|
badFirstVector.lineTo(301.557678f, 98.044601f);
|
|
|
|
badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
|
|
|
|
badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
|
|
|
|
badFirstVector.lineTo(504.912292f, 316.389648f);
|
|
|
|
badFirstVector.lineTo(501.087708f, 319.610352f);
|
|
|
|
badFirstVector.close();
|
|
|
|
check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
|
2011-05-15 04:38:34 +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);
|
|
|
|
}
|
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
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) {
|
|
|
|
SkPath path;
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, SkPath::kConvex_Convexity);
|
2012-01-10 18:59:22 +00:00
|
|
|
path.addCircle(0, 0, SkIntToScalar(10));
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, SkPath::kConvex_Convexity);
|
2012-01-10 18:59:22 +00:00
|
|
|
path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, SkPath::kConcave_Convexity);
|
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
path.reset();
|
2012-01-10 18:59:22 +00:00
|
|
|
path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
|
2012-11-13 14:36:42 +00:00
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
path.reset();
|
2012-01-10 18:59:22 +00:00
|
|
|
path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, SkPath::kConvex_Convexity);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
static const struct {
|
2015-06-10 21:23:15 +00:00
|
|
|
const char* fPathStr;
|
|
|
|
SkPath::Convexity fExpectedConvexity;
|
|
|
|
SkPathPriv::FirstDirection fExpectedDirection;
|
2011-05-15 04:08:24 +00:00
|
|
|
} gRec[] = {
|
2015-06-10 21:23:15 +00:00
|
|
|
{ "", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
|
|
|
|
{ "0 0", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
|
|
|
|
{ "0 0 10 10", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
|
|
|
|
{ "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPathPriv::kUnknown_FirstDirection },
|
|
|
|
{ "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPathPriv::kCW_FirstDirection },
|
|
|
|
{ "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPathPriv::kCCW_FirstDirection },
|
2012-11-13 14:36:42 +00:00
|
|
|
{ "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
|
2015-06-10 21:23:15 +00:00
|
|
|
{ "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPathPriv::kCW_FirstDirection },
|
2011-05-15 04:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
SkPath path;
|
|
|
|
setFromString(&path, gRec[i].fPathStr);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_convexity(reporter, path, gRec[i].fExpectedConvexity);
|
|
|
|
check_direction(reporter, path, gRec[i].fExpectedDirection);
|
2013-11-14 16:53:22 +00:00
|
|
|
// check after setting the initial convex and direction
|
|
|
|
if (kDontCheckDir != gRec[i].fExpectedDirection) {
|
|
|
|
SkPath copy(path);
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir;
|
|
|
|
bool foundDir = SkPathPriv::CheapComputeFirstDirection(copy, &dir);
|
|
|
|
REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPathPriv::kUnknown_FirstDirection)
|
2013-11-14 16:53:22 +00:00
|
|
|
^ foundDir);
|
|
|
|
REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
|
|
|
|
check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
|
|
|
|
check_direction(reporter, path, gRec[i].fExpectedDirection);
|
2011-05-15 04:08:24 +00:00
|
|
|
}
|
2014-12-08 12:57:38 +00:00
|
|
|
|
|
|
|
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[] = {
|
|
|
|
{ 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]);
|
|
|
|
|
|
|
|
for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
|
|
|
|
int i = (int) (index % nonFinitePtsCount);
|
|
|
|
int f = (int) (index % finitePtsCount);
|
|
|
|
int g = (int) ((f + 1) % finitePtsCount);
|
|
|
|
path.reset();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
check_convexity(reporter, path, SkPath::kUnknown_Convexity);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
|
|
|
|
int f = (int) (index % finitePtsCount);
|
|
|
|
int g = (int) ((f + 1) % finitePtsCount);
|
|
|
|
path.reset();
|
|
|
|
int curveSelect = index % 11;
|
|
|
|
switch (curveSelect) {
|
|
|
|
case 0: path.moveTo(finitePts[f]); break;
|
|
|
|
case 1: path.lineTo(finitePts[f]); break;
|
|
|
|
case 2: path.quadTo(finitePts[f], finitePts[f]); break;
|
|
|
|
case 3: path.quadTo(finitePts[f], finitePts[g]); break;
|
|
|
|
case 4: path.quadTo(finitePts[g], finitePts[f]); break;
|
|
|
|
case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
|
|
|
|
case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
|
|
|
|
case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
|
|
|
|
case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
|
|
|
|
case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
|
|
|
|
case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
|
|
|
|
}
|
|
|
|
check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
|
|
|
|
: SkPath::kUnknown_Convexity);
|
|
|
|
}
|
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-10 14:05:43 +00:00
|
|
|
static void test_isLine(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
SkPoint pts[2];
|
|
|
|
const SkScalar value = SkIntToScalar(5);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(NULL));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-10 14:05:43 +00:00
|
|
|
// set some non-zero values
|
|
|
|
pts[0].set(value, value);
|
|
|
|
pts[1].set(value, value);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(pts));
|
|
|
|
// check that pts was untouched
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].equals(value, value));
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].equals(value, value));
|
|
|
|
|
|
|
|
const SkScalar moveX = SkIntToScalar(1);
|
|
|
|
const SkScalar moveY = SkIntToScalar(2);
|
2013-11-14 16:53:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, value != moveX && value != moveY);
|
2012-05-10 14:05:43 +00:00
|
|
|
|
|
|
|
path.moveTo(moveX, moveY);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(NULL));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(pts));
|
|
|
|
// check that pts was untouched
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].equals(value, value));
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].equals(value, value));
|
|
|
|
|
|
|
|
const SkScalar lineX = SkIntToScalar(2);
|
|
|
|
const SkScalar lineY = SkIntToScalar(2);
|
2013-11-14 16:53:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, value != lineX && value != lineY);
|
2012-05-10 14:05:43 +00:00
|
|
|
|
|
|
|
path.lineTo(lineX, lineY);
|
|
|
|
REPORTER_ASSERT(reporter, path.isLine(NULL));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
|
|
|
|
REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
|
|
|
|
REPORTER_ASSERT(reporter, path.isLine(pts));
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
|
|
|
|
|
|
|
|
path.lineTo(0, 0); // too many points/verbs
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(NULL));
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(pts));
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
|
2013-11-14 16:53:22 +00:00
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.quadTo(1, 1, 2, 2);
|
|
|
|
REPORTER_ASSERT(reporter, !path.isLine(NULL));
|
2012-05-10 14:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 21:51:38 +00:00
|
|
|
static void test_conservativelyContains(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
// kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
|
|
|
|
static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
|
|
|
|
// A circle that bounds kBaseRect (with a significant amount of slop)
|
|
|
|
SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
|
2013-11-14 16:53:22 +00:00
|
|
|
circleR = SkScalarMul(circleR, 1.75f) / 2;
|
2012-11-13 21:51:38 +00:00
|
|
|
static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
|
|
|
|
|
|
|
|
// round-rect radii
|
|
|
|
static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
|
2012-11-14 02:01:22 +00:00
|
|
|
|
2012-11-19 13:06:06 +00:00
|
|
|
static const struct SUPPRESS_VISIBILITY_WARNING {
|
2012-11-13 21:51:38 +00:00
|
|
|
SkRect fQueryRect;
|
|
|
|
bool fInRect;
|
|
|
|
bool fInCircle;
|
|
|
|
bool fInRR;
|
2013-11-14 16:53:22 +00:00
|
|
|
bool fInCubicRR;
|
2012-11-13 21:51:38 +00:00
|
|
|
} kQueries[] = {
|
2013-11-14 16:53:22 +00:00
|
|
|
{kBaseRect, true, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// rect well inside of kBaseRect
|
2013-11-25 19:44:07 +00:00
|
|
|
{SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
|
|
|
|
kBaseRect.fTop + 0.25f*kBaseRect.height(),
|
|
|
|
kBaseRect.fRight - 0.25f*kBaseRect.width(),
|
|
|
|
kBaseRect.fBottom - 0.25f*kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
true, true, true, true},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// rects with edges off by one from kBaseRect's edges
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
|
|
|
|
kBaseRect.width(), kBaseRect.height() + 1),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
|
|
|
|
kBaseRect.width() + 1, kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
|
|
|
|
kBaseRect.width() + 1, kBaseRect.height() + 1),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
|
|
|
|
kBaseRect.width(), kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
|
|
|
|
kBaseRect.width(), kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
|
|
|
|
kBaseRect.width() + 2, kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
|
|
|
|
kBaseRect.width() + 2, kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// zero-w/h rects at each corner of kBaseRect
|
2013-11-14 16:53:22 +00:00
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// far away rect
|
|
|
|
{SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
|
|
|
|
SkIntToScalar(10), SkIntToScalar(10)),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, false, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// very large rect containing kBaseRect
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
|
|
|
|
kBaseRect.fTop - 5 * kBaseRect.height(),
|
|
|
|
11 * kBaseRect.width(), 11 * kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, false, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// skinny rect that spans same y-range as kBaseRect
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
|
|
|
|
SkIntToScalar(1), kBaseRect.height()),
|
2013-11-14 16:53:22 +00:00
|
|
|
true, true, true, true},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// short rect that spans same x-range as kBaseRect
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
|
2013-11-14 16:53:22 +00:00
|
|
|
true, true, true, true},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// skinny rect that spans slightly larger y-range than kBaseRect
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
|
|
|
|
SkIntToScalar(1), kBaseRect.height() + 1),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
|
|
|
|
// short rect that spans slightly larger x-range than kBaseRect
|
|
|
|
{SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
|
|
|
|
kBaseRect.width() + 1, SkScalar(1)),
|
2013-11-14 16:53:22 +00:00
|
|
|
false, true, false, false},
|
2012-11-13 21:51:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int inv = 0; inv < 4; ++inv) {
|
2012-11-19 13:06:06 +00:00
|
|
|
for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
|
2012-11-13 21:51:38 +00:00
|
|
|
SkRect qRect = kQueries[q].fQueryRect;
|
|
|
|
if (inv & 0x1) {
|
|
|
|
SkTSwap(qRect.fLeft, qRect.fRight);
|
|
|
|
}
|
|
|
|
if (inv & 0x2) {
|
|
|
|
SkTSwap(qRect.fTop, qRect.fBottom);
|
|
|
|
}
|
|
|
|
for (int d = 0; d < 2; ++d) {
|
|
|
|
SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
|
|
|
|
path.reset();
|
|
|
|
path.addRect(kBaseRect, dir);
|
|
|
|
REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
|
|
|
|
path.conservativelyContainsRect(qRect));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
|
|
|
|
REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
|
|
|
|
path.conservativelyContainsRect(qRect));
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
|
|
|
|
REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
|
|
|
|
path.conservativelyContainsRect(qRect));
|
2013-11-14 16:53:22 +00:00
|
|
|
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
|
|
|
|
path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
|
|
|
|
kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
|
|
|
|
kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
|
|
|
|
path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
|
|
|
|
path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
|
|
|
|
path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
|
|
|
|
path.close();
|
|
|
|
REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
|
|
|
|
path.conservativelyContainsRect(qRect));
|
|
|
|
|
2012-11-13 21:51:38 +00:00
|
|
|
}
|
|
|
|
// Slightly non-convex shape, shouldn't contain any rects.
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(0, 0);
|
2013-11-25 19:44:07 +00:00
|
|
|
path.lineTo(SkIntToScalar(50), 0.05f);
|
2012-11-13 21:51:38 +00:00
|
|
|
path.lineTo(SkIntToScalar(100), 0);
|
|
|
|
path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
path.lineTo(0, SkIntToScalar(100));
|
|
|
|
path.close();
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(SkIntToScalar(100), 0);
|
|
|
|
path.lineTo(0, SkIntToScalar(100));
|
|
|
|
|
|
|
|
// inside, on along top edge
|
|
|
|
REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10))));
|
|
|
|
// above
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
|
|
|
|
SkRect::MakeXYWH(SkIntToScalar(50),
|
|
|
|
SkIntToScalar(-10),
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10))));
|
|
|
|
// to the left
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
|
|
|
|
SkIntToScalar(5),
|
|
|
|
SkIntToScalar(5),
|
|
|
|
SkIntToScalar(5))));
|
|
|
|
|
|
|
|
// outside the diagonal edge
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
|
|
|
|
SkIntToScalar(200),
|
|
|
|
SkIntToScalar(20),
|
|
|
|
SkIntToScalar(5))));
|
2013-08-01 15:35:06 +00:00
|
|
|
|
2014-08-28 21:04:55 +00:00
|
|
|
|
|
|
|
// Test that multiple move commands do not cause asserts.
|
|
|
|
|
|
|
|
// At the time of writing, this would not modify cached convexity. This caused an assert while
|
|
|
|
// checking conservative containment again. http://skbug.com/1460
|
|
|
|
path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
#if 0
|
|
|
|
REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10))));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Same as above path and first test but with an extra moveTo.
|
2013-08-01 15:35:06 +00:00
|
|
|
path.reset();
|
|
|
|
path.moveTo(100, 100);
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(SkIntToScalar(100), 0);
|
|
|
|
path.lineTo(0, SkIntToScalar(100));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10))));
|
|
|
|
|
2014-08-28 21:04:55 +00:00
|
|
|
// Test that multiple move commands do not cause asserts and that the function
|
|
|
|
// is not confused by the multiple moves.
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(SkIntToScalar(100), 0);
|
|
|
|
path.lineTo(0, SkIntToScalar(100));
|
|
|
|
path.moveTo(0, SkIntToScalar(200));
|
|
|
|
path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
|
|
|
|
path.lineTo(0, SkIntToScalar(300));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
|
|
|
|
SkRect::MakeXYWH(SkIntToScalar(50), 0,
|
|
|
|
SkIntToScalar(10),
|
|
|
|
SkIntToScalar(10))));
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
path.reset();
|
|
|
|
path.lineTo(100, 100);
|
|
|
|
REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
|
2012-11-13 21:51:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 15:14:04 +00:00
|
|
|
static void test_isRect_open_close(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
bool isClosed;
|
|
|
|
|
|
|
|
path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
|
|
|
|
path.close();
|
2014-01-15 18:00:57 +00:00
|
|
|
|
2015-01-05 18:13:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL));
|
2013-10-16 15:14:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, isClosed);
|
|
|
|
}
|
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// Simple isRect test is inline TestPath, below.
|
|
|
|
// test_isRect provides more extensive testing.
|
|
|
|
static void test_isRect(skiatest::Reporter* reporter) {
|
2013-10-16 15:14:04 +00:00
|
|
|
test_isRect_open_close(reporter);
|
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// passing tests (all moveTo / lineTo...
|
|
|
|
SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
|
|
|
SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
|
|
|
|
SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
|
|
|
|
SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
|
|
|
|
SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
|
|
|
|
SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
|
|
|
SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
|
|
|
|
SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
|
|
|
|
SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
2013-09-25 18:21:39 +00:00
|
|
|
SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
|
|
|
|
SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}};
|
2011-07-26 19:54:45 +00:00
|
|
|
SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
|
|
|
|
SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
|
|
|
SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
|
2012-11-21 13:56:20 +00:00
|
|
|
SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// failing tests
|
|
|
|
SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
|
|
|
|
SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
|
|
|
|
SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
|
|
|
|
SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
|
|
|
|
SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
|
|
|
|
SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
|
|
|
|
SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
|
|
|
|
SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
|
2012-11-21 13:56:20 +00:00
|
|
|
SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
|
|
|
|
SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
|
|
|
|
SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2014-01-15 18:00:57 +00:00
|
|
|
// no close, but we should detect them as fillably the same as a rect
|
|
|
|
SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
|
|
|
SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
|
|
|
|
SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
|
|
|
|
|
|
|
|
// like c2, but we double-back on ourselves
|
|
|
|
SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
|
|
|
|
// like c2, but we overshoot the start point
|
|
|
|
SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
|
|
|
|
SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
|
2011-07-26 19:54:45 +00:00
|
|
|
|
2013-09-25 18:21:39 +00:00
|
|
|
struct IsRectTest {
|
|
|
|
SkPoint *fPoints;
|
2014-12-12 23:11:17 +00:00
|
|
|
int fPointCount;
|
2013-09-25 18:21:39 +00:00
|
|
|
bool fClose;
|
|
|
|
bool fIsRect;
|
|
|
|
} tests[] = {
|
|
|
|
{ r1, SK_ARRAY_COUNT(r1), true, true },
|
|
|
|
{ r2, SK_ARRAY_COUNT(r2), true, true },
|
|
|
|
{ r3, SK_ARRAY_COUNT(r3), true, true },
|
|
|
|
{ r4, SK_ARRAY_COUNT(r4), true, true },
|
|
|
|
{ r5, SK_ARRAY_COUNT(r5), true, true },
|
|
|
|
{ r6, SK_ARRAY_COUNT(r6), true, true },
|
|
|
|
{ r7, SK_ARRAY_COUNT(r7), true, true },
|
|
|
|
{ r8, SK_ARRAY_COUNT(r8), true, true },
|
|
|
|
{ r9, SK_ARRAY_COUNT(r9), true, true },
|
|
|
|
{ ra, SK_ARRAY_COUNT(ra), true, true },
|
|
|
|
{ rb, SK_ARRAY_COUNT(rb), true, true },
|
|
|
|
{ rc, SK_ARRAY_COUNT(rc), true, true },
|
|
|
|
{ rd, SK_ARRAY_COUNT(rd), true, true },
|
|
|
|
{ re, SK_ARRAY_COUNT(re), true, true },
|
|
|
|
{ rf, SK_ARRAY_COUNT(rf), true, true },
|
|
|
|
|
|
|
|
{ f1, SK_ARRAY_COUNT(f1), true, false },
|
|
|
|
{ f2, SK_ARRAY_COUNT(f2), true, false },
|
|
|
|
{ f3, SK_ARRAY_COUNT(f3), true, false },
|
|
|
|
{ f4, SK_ARRAY_COUNT(f4), true, false },
|
|
|
|
{ f5, SK_ARRAY_COUNT(f5), true, false },
|
|
|
|
{ f6, SK_ARRAY_COUNT(f6), true, false },
|
|
|
|
{ f7, SK_ARRAY_COUNT(f7), true, false },
|
|
|
|
{ f8, SK_ARRAY_COUNT(f8), true, false },
|
|
|
|
{ f9, SK_ARRAY_COUNT(f9), true, false },
|
|
|
|
{ fa, SK_ARRAY_COUNT(fa), true, false },
|
|
|
|
{ fb, SK_ARRAY_COUNT(fb), true, false },
|
|
|
|
|
2014-01-15 18:00:57 +00:00
|
|
|
{ c1, SK_ARRAY_COUNT(c1), false, true },
|
|
|
|
{ c2, SK_ARRAY_COUNT(c2), false, true },
|
|
|
|
{ c3, SK_ARRAY_COUNT(c3), false, true },
|
|
|
|
|
|
|
|
{ d1, SK_ARRAY_COUNT(d1), false, false },
|
|
|
|
{ d2, SK_ARRAY_COUNT(d2), false, false },
|
|
|
|
{ d3, SK_ARRAY_COUNT(d3), false, false },
|
2011-07-26 19:54:45 +00:00
|
|
|
};
|
2013-09-25 18:21:39 +00:00
|
|
|
|
|
|
|
const size_t testCount = SK_ARRAY_COUNT(tests);
|
2014-12-12 23:11:17 +00:00
|
|
|
int index;
|
2011-07-26 19:54:45 +00:00
|
|
|
for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
|
|
|
|
SkPath path;
|
2013-09-25 18:21:39 +00:00
|
|
|
path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
|
|
|
|
for (index = 1; index < tests[testIndex].fPointCount; ++index) {
|
|
|
|
path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
|
2011-07-26 19:54:45 +00:00
|
|
|
}
|
2013-09-25 18:21:39 +00:00
|
|
|
if (tests[testIndex].fClose) {
|
2011-07-26 19:54:45 +00:00
|
|
|
path.close();
|
|
|
|
}
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
|
2012-11-21 15:18:06 +00:00
|
|
|
|
2013-09-25 18:21:39 +00:00
|
|
|
if (tests[testIndex].fIsRect) {
|
2012-11-19 13:06:06 +00:00
|
|
|
SkRect computed, expected;
|
2012-11-21 15:18:06 +00:00
|
|
|
bool isClosed;
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPath::Direction direction;
|
|
|
|
SkPathPriv::FirstDirection cheapDirection;
|
2015-01-05 18:13:46 +00:00
|
|
|
expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapComputeFirstDirection(path, &cheapDirection));
|
2015-01-05 18:13:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
|
|
|
|
REPORTER_ASSERT(reporter, expected == computed);
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(direction) == cheapDirection);
|
2012-11-21 15:18:06 +00:00
|
|
|
} else {
|
|
|
|
SkRect computed;
|
|
|
|
computed.set(123, 456, 789, 1011);
|
2015-01-05 18:13:46 +00:00
|
|
|
bool isClosed = (bool)-1;
|
|
|
|
SkPath::Direction direction = (SkPath::Direction) - 1;
|
|
|
|
REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
|
2012-11-21 15:18:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
|
|
|
|
REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
|
|
|
|
REPORTER_ASSERT(reporter, isClosed == (bool) -1);
|
|
|
|
REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
|
2012-11-19 13:06:06 +00:00
|
|
|
}
|
2011-07-26 19:54:45 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// fail, close then line
|
|
|
|
SkPath path1;
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2011-07-26 19:54:45 +00:00
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
path1.lineTo(1, 0);
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isRect(NULL));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// fail, move in the middle
|
|
|
|
path1.reset();
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2011-07-26 19:54:45 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.moveTo(1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isRect(NULL));
|
2011-07-26 19:54:45 +00:00
|
|
|
|
|
|
|
// fail, move on the edge
|
|
|
|
path1.reset();
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2011-07-26 19:54:45 +00:00
|
|
|
path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isRect(NULL));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// fail, quad
|
|
|
|
path1.reset();
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2011-07-26 19:54:45 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.quadTo(1, .5f, 1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isRect(NULL));
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-07-26 19:54:45 +00:00
|
|
|
// fail, cubic
|
|
|
|
path1.reset();
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2011-07-26 19:54:45 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
2013-09-25 18:21:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isRect(NULL));
|
2011-07-26 19:54:45 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 15:34:15 +00:00
|
|
|
static void test_isNestedFillRects(skiatest::Reporter* reporter) {
|
2012-11-19 13:06:06 +00:00
|
|
|
// passing tests (all moveTo / lineTo...
|
2013-05-17 12:50:27 +00:00
|
|
|
SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
|
2012-11-19 13:06:06 +00:00
|
|
|
SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
|
|
|
|
SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
|
|
|
|
SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
|
2013-05-17 12:50:27 +00:00
|
|
|
SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
|
2012-11-19 13:06:06 +00:00
|
|
|
SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
|
|
|
SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
|
|
|
|
SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
|
|
|
|
SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
2013-09-25 18:21:39 +00:00
|
|
|
SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
|
|
|
|
SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}}; // CW
|
2013-05-17 12:50:27 +00:00
|
|
|
SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
|
|
|
|
SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
|
|
|
|
SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
|
2012-11-19 13:06:06 +00:00
|
|
|
|
|
|
|
// failing tests
|
|
|
|
SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
|
|
|
|
SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
|
|
|
|
SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
|
|
|
|
SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
|
|
|
|
SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
|
|
|
|
SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
|
|
|
|
SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
|
|
|
|
SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
|
|
|
|
|
2015-04-08 15:34:15 +00:00
|
|
|
// success, no close is OK
|
2012-11-19 13:06:06 +00:00
|
|
|
SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
|
|
|
|
SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
|
|
|
|
|
2013-09-25 18:21:39 +00:00
|
|
|
struct IsNestedRectTest {
|
|
|
|
SkPoint *fPoints;
|
2014-12-12 23:11:17 +00:00
|
|
|
int fPointCount;
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection fDirection;
|
2013-09-25 18:21:39 +00:00
|
|
|
bool fClose;
|
|
|
|
bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
|
|
|
|
} tests[] = {
|
2015-06-10 21:23:15 +00:00
|
|
|
{ r1, SK_ARRAY_COUNT(r1), SkPathPriv::kCW_FirstDirection , true, true },
|
|
|
|
{ r2, SK_ARRAY_COUNT(r2), SkPathPriv::kCW_FirstDirection , true, true },
|
|
|
|
{ r3, SK_ARRAY_COUNT(r3), SkPathPriv::kCW_FirstDirection , true, true },
|
|
|
|
{ r4, SK_ARRAY_COUNT(r4), SkPathPriv::kCW_FirstDirection , true, true },
|
|
|
|
{ r5, SK_ARRAY_COUNT(r5), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ r6, SK_ARRAY_COUNT(r6), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ r7, SK_ARRAY_COUNT(r7), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ r8, SK_ARRAY_COUNT(r8), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ r9, SK_ARRAY_COUNT(r9), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ ra, SK_ARRAY_COUNT(ra), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ rb, SK_ARRAY_COUNT(rb), SkPathPriv::kCW_FirstDirection, true, true },
|
|
|
|
{ rc, SK_ARRAY_COUNT(rc), SkPathPriv::kCW_FirstDirection, true, true },
|
|
|
|
{ rd, SK_ARRAY_COUNT(rd), SkPathPriv::kCCW_FirstDirection, true, true },
|
|
|
|
{ re, SK_ARRAY_COUNT(re), SkPathPriv::kCW_FirstDirection, true, true },
|
|
|
|
|
|
|
|
{ f1, SK_ARRAY_COUNT(f1), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f2, SK_ARRAY_COUNT(f2), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f3, SK_ARRAY_COUNT(f3), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f4, SK_ARRAY_COUNT(f4), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f5, SK_ARRAY_COUNT(f5), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f6, SK_ARRAY_COUNT(f6), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f7, SK_ARRAY_COUNT(f7), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
{ f8, SK_ARRAY_COUNT(f8), SkPathPriv::kUnknown_FirstDirection, true, false },
|
|
|
|
|
|
|
|
{ c1, SK_ARRAY_COUNT(c1), SkPathPriv::kCW_FirstDirection, false, true },
|
|
|
|
{ c2, SK_ARRAY_COUNT(c2), SkPathPriv::kCW_FirstDirection, false, true },
|
2012-11-19 13:06:06 +00:00
|
|
|
};
|
2013-05-17 12:50:27 +00:00
|
|
|
|
2013-09-25 18:21:39 +00:00
|
|
|
const size_t testCount = SK_ARRAY_COUNT(tests);
|
2014-12-12 23:11:17 +00:00
|
|
|
int index;
|
2012-11-19 13:06:06 +00:00
|
|
|
for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
|
|
|
|
for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
|
|
|
|
SkPath path;
|
|
|
|
if (rectFirst) {
|
|
|
|
path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
2013-09-25 18:21:39 +00:00
|
|
|
path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
|
|
|
|
for (index = 1; index < tests[testIndex].fPointCount; ++index) {
|
|
|
|
path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
|
2012-11-19 13:06:06 +00:00
|
|
|
}
|
2013-09-25 18:21:39 +00:00
|
|
|
if (tests[testIndex].fClose) {
|
2012-11-19 13:06:06 +00:00
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
if (!rectFirst) {
|
|
|
|
path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
tests[testIndex].fIsNestedRect == path.isNestedFillRects(NULL));
|
2013-09-25 18:21:39 +00:00
|
|
|
if (tests[testIndex].fIsNestedRect) {
|
2012-11-19 13:06:06 +00:00
|
|
|
SkRect expected[2], computed[2];
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection expectedDirs[2];
|
|
|
|
SkPath::Direction computedDirs[2];
|
2012-11-19 13:06:06 +00:00
|
|
|
SkRect testBounds;
|
2013-09-25 18:21:39 +00:00
|
|
|
testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
|
2012-11-19 13:06:06 +00:00
|
|
|
expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
|
|
|
|
expected[1] = testBounds;
|
2013-05-17 12:50:27 +00:00
|
|
|
if (rectFirst) {
|
2015-06-10 21:23:15 +00:00
|
|
|
expectedDirs[0] = SkPathPriv::kCW_FirstDirection;
|
2013-05-17 12:50:27 +00:00
|
|
|
} else {
|
2015-06-10 21:23:15 +00:00
|
|
|
expectedDirs[0] = SkPathPriv::kCCW_FirstDirection;
|
2013-05-17 12:50:27 +00:00
|
|
|
}
|
2013-09-25 18:21:39 +00:00
|
|
|
expectedDirs[1] = tests[testIndex].fDirection;
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, path.isNestedFillRects(computed, computedDirs));
|
2012-11-19 13:06:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, expected[0] == computed[0]);
|
|
|
|
REPORTER_ASSERT(reporter, expected[1] == computed[1]);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectedDirs[0] == SkPathPriv::AsFirstDirection(computedDirs[0]));
|
|
|
|
REPORTER_ASSERT(reporter, expectedDirs[1] == SkPathPriv::AsFirstDirection(computedDirs[1]));
|
2012-11-19 13:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fail, close then line
|
|
|
|
SkPath path1;
|
|
|
|
if (rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2012-11-19 13:06:06 +00:00
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
path1.lineTo(1, 0);
|
|
|
|
if (!rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
|
|
|
|
// fail, move in the middle
|
|
|
|
path1.reset();
|
|
|
|
if (rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2012-11-19 13:06:06 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.moveTo(1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
if (!rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
|
|
|
|
// fail, move on the edge
|
|
|
|
path1.reset();
|
|
|
|
if (rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2012-11-19 13:06:06 +00:00
|
|
|
path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
if (!rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
|
|
|
|
// fail, quad
|
|
|
|
path1.reset();
|
|
|
|
if (rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2012-11-19 13:06:06 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.quadTo(1, .5f, 1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
if (!rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
|
|
|
|
// fail, cubic
|
|
|
|
path1.reset();
|
|
|
|
if (rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
|
|
|
|
}
|
|
|
|
path1.moveTo(r1[0].fX, r1[0].fY);
|
2014-12-12 23:11:17 +00:00
|
|
|
for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
|
2012-11-19 13:06:06 +00:00
|
|
|
if (index == 2) {
|
|
|
|
path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
|
|
|
|
}
|
|
|
|
path1.lineTo(r1[index].fX, r1[index].fY);
|
|
|
|
}
|
|
|
|
path1.close();
|
|
|
|
if (!rectFirst) {
|
|
|
|
path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
|
|
|
|
}
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-20 02:01:23 +00:00
|
|
|
|
2012-11-19 13:06:06 +00:00
|
|
|
// fail, not nested
|
|
|
|
path1.reset();
|
|
|
|
path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
|
|
|
|
path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !path1.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
}
|
2012-11-21 13:56:20 +00:00
|
|
|
|
2015-04-08 15:34:15 +00:00
|
|
|
// pass, constructed explicitly from manually closed rects specified as moves/lines.
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.lineTo(10, 0);
|
|
|
|
path.lineTo(10, 10);
|
|
|
|
path.lineTo(0, 10);
|
|
|
|
path.lineTo(0, 0);
|
|
|
|
path.moveTo(1, 1);
|
|
|
|
path.lineTo(9, 1);
|
|
|
|
path.lineTo(9, 9);
|
|
|
|
path.lineTo(1, 9);
|
|
|
|
path.lineTo(1, 1);
|
|
|
|
REPORTER_ASSERT(reporter, path.isNestedFillRects(NULL));
|
|
|
|
|
2012-11-21 13:56:20 +00:00
|
|
|
// pass, stroke rect
|
|
|
|
SkPath src, dst;
|
|
|
|
src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
|
|
|
|
SkPaint strokePaint;
|
|
|
|
strokePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
strokePaint.setStrokeWidth(2);
|
|
|
|
strokePaint.getFillPath(src, &dst);
|
2015-04-08 15:34:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, dst.isNestedFillRects(NULL));
|
2012-11-19 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 17:32:51 +00:00
|
|
|
static void write_and_read_back(skiatest::Reporter* reporter,
|
|
|
|
const SkPath& p) {
|
2014-01-14 20:51:26 +00:00
|
|
|
SkWriter32 writer;
|
2012-08-07 17:32:51 +00:00
|
|
|
writer.writePath(p);
|
2013-10-31 17:28:30 +00:00
|
|
|
size_t size = writer.bytesWritten();
|
2012-08-07 17:32:51 +00:00
|
|
|
SkAutoMalloc storage(size);
|
|
|
|
writer.flatten(storage.get());
|
|
|
|
SkReader32 reader(storage.get(), size);
|
|
|
|
|
|
|
|
SkPath readBack;
|
|
|
|
REPORTER_ASSERT(reporter, readBack != p);
|
|
|
|
reader.readPath(&readBack);
|
|
|
|
REPORTER_ASSERT(reporter, readBack == p);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
|
2012-08-07 17:32:51 +00:00
|
|
|
p.getConvexityOrUnknown());
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
|
|
|
|
|
|
|
|
const SkRect& origBounds = p.getBounds();
|
|
|
|
const SkRect& readBackBounds = readBack.getBounds();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, origBounds == readBackBounds);
|
|
|
|
}
|
|
|
|
|
2011-09-21 19:05:12 +00:00
|
|
|
static void test_flattening(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
|
|
|
|
static const SkPoint pts[] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(10) },
|
|
|
|
{ SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
|
|
|
|
{ 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
|
|
|
|
};
|
|
|
|
p.moveTo(pts[0]);
|
|
|
|
p.lineTo(pts[1]);
|
|
|
|
p.quadTo(pts[2], pts[3]);
|
|
|
|
p.cubicTo(pts[4], pts[5], pts[6]);
|
|
|
|
|
2012-08-07 17:32:51 +00:00
|
|
|
write_and_read_back(reporter, p);
|
2012-06-08 18:30:46 +00:00
|
|
|
|
|
|
|
// create a buffer that should be much larger than the path so we don't
|
|
|
|
// kill our stack if writer goes too far.
|
|
|
|
char buffer[1024];
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t size1 = p.writeToMemory(NULL);
|
|
|
|
size_t size2 = p.writeToMemory(buffer);
|
2012-06-08 18:30:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, size1 == size2);
|
|
|
|
|
|
|
|
SkPath p2;
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t size3 = p2.readFromMemory(buffer, 1024);
|
2012-06-08 18:30:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, size1 == size3);
|
|
|
|
REPORTER_ASSERT(reporter, p == p2);
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
size3 = p2.readFromMemory(buffer, 0);
|
|
|
|
REPORTER_ASSERT(reporter, !size3);
|
|
|
|
|
|
|
|
SkPath tooShort;
|
|
|
|
size3 = tooShort.readFromMemory(buffer, size1 - 1);
|
|
|
|
REPORTER_ASSERT(reporter, tooShort.isEmpty());
|
|
|
|
|
2012-06-08 18:30:46 +00:00
|
|
|
char buffer2[1024];
|
|
|
|
size3 = p2.writeToMemory(buffer2);
|
|
|
|
REPORTER_ASSERT(reporter, size1 == size3);
|
|
|
|
REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
|
2012-08-07 17:32:51 +00:00
|
|
|
|
|
|
|
// test persistence of the oval flag & convexity
|
|
|
|
{
|
|
|
|
SkPath oval;
|
|
|
|
SkRect rect = SkRect::MakeWH(10, 10);
|
|
|
|
oval.addOval(rect);
|
|
|
|
|
|
|
|
write_and_read_back(reporter, oval);
|
|
|
|
}
|
2011-09-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_transform(skiatest::Reporter* reporter) {
|
2013-12-03 17:15:36 +00:00
|
|
|
SkPath p;
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
#define CONIC_PERSPECTIVE_BUG_FIXED 0
|
2011-09-21 19:05:12 +00:00
|
|
|
static const SkPoint pts[] = {
|
2013-11-14 16:53:22 +00:00
|
|
|
{ 0, 0 }, // move
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(10) }, // line
|
|
|
|
{ SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
|
|
|
|
{ 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
|
|
|
|
#if CONIC_PERSPECTIVE_BUG_FIXED
|
|
|
|
{ 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
|
|
|
|
#endif
|
2011-09-21 19:05:12 +00:00
|
|
|
};
|
2013-11-14 16:53:22 +00:00
|
|
|
const int kPtCount = SK_ARRAY_COUNT(pts);
|
2013-12-03 17:15:36 +00:00
|
|
|
|
2011-09-21 19:05:12 +00:00
|
|
|
p.moveTo(pts[0]);
|
|
|
|
p.lineTo(pts[1]);
|
|
|
|
p.quadTo(pts[2], pts[3]);
|
|
|
|
p.cubicTo(pts[4], pts[5], pts[6]);
|
2013-11-14 16:53:22 +00:00
|
|
|
#if CONIC_PERSPECTIVE_BUG_FIXED
|
|
|
|
p.conicTo(pts[4], pts[5], 0.5f);
|
|
|
|
#endif
|
|
|
|
p.close();
|
2013-12-03 17:15:36 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
SkPath p1;
|
|
|
|
p.transform(matrix, &p1);
|
|
|
|
REPORTER_ASSERT(reporter, p == p1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
|
|
|
|
|
|
|
|
SkPath p1; // Leave p1 non-unique (i.e., the empty path)
|
|
|
|
|
2013-12-04 07:02:26 +00:00
|
|
|
p.transform(matrix, &p1);
|
2013-12-03 17:15:36 +00:00
|
|
|
SkPoint pts1[kPtCount];
|
2013-12-04 07:02:26 +00:00
|
|
|
int count = p1.getPoints(pts1, kPtCount);
|
2013-12-03 17:15:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, kPtCount == count);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
|
|
|
|
REPORTER_ASSERT(reporter, newPt == pts1[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
2015-01-21 03:58:36 +00:00
|
|
|
matrix.setPerspX(4);
|
2013-12-03 17:15:36 +00:00
|
|
|
|
|
|
|
SkPath p1;
|
|
|
|
p1.moveTo(SkPoint::Make(0, 0));
|
|
|
|
|
|
|
|
p.transform(matrix, &p1);
|
|
|
|
REPORTER_ASSERT(reporter, matrix.invert(&matrix));
|
|
|
|
p1.transform(matrix, NULL);
|
|
|
|
SkRect pBounds = p.getBounds();
|
|
|
|
SkRect p1Bounds = p1.getBounds();
|
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
|
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
|
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
|
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
|
2011-09-21 19:05:12 +00:00
|
|
|
}
|
2013-12-03 17:15:36 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
p.reset();
|
|
|
|
p.addCircle(0, 0, 1, SkPath::kCW_Direction);
|
2013-12-03 17:15:36 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
SkPath p1;
|
|
|
|
p1.moveTo(SkPoint::Make(0, 0));
|
|
|
|
|
|
|
|
p.transform(matrix, &p1);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCW_FirstDirection));
|
2013-12-03 17:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setScaleX(-1);
|
|
|
|
SkPath p1;
|
|
|
|
p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
|
|
|
|
|
|
|
|
p.transform(matrix, &p1);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCCW_FirstDirection));
|
2013-12-03 17:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
|
|
|
|
SkPath p1;
|
|
|
|
p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
|
|
|
|
|
|
|
|
p.transform(matrix, &p1);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kUnknown_FirstDirection));
|
2013-12-03 17:15:36 +00:00
|
|
|
}
|
2011-09-21 19:05:12 +00:00
|
|
|
}
|
|
|
|
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
static void test_zero_length_paths(skiatest::Reporter* reporter) {
|
2012-01-04 21:05:51 +00:00
|
|
|
SkPath p;
|
2012-06-13 17:05:43 +00:00
|
|
|
uint8_t verbs[32];
|
|
|
|
|
2012-11-19 13:06:06 +00:00
|
|
|
struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
|
2012-06-13 17:05:43 +00:00
|
|
|
const char* testPath;
|
|
|
|
const size_t numResultPts;
|
|
|
|
const SkRect resultBound;
|
|
|
|
const SkPath::Verb* resultVerbs;
|
|
|
|
const size_t numResultVerbs;
|
|
|
|
};
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
|
2012-06-13 17:05:43 +00:00
|
|
|
static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs8[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
|
|
|
|
};
|
|
|
|
static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs12[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
|
|
|
|
};
|
|
|
|
static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs16[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
|
|
|
|
};
|
|
|
|
static const struct zeroPathTestData gZeroLengthTests[] = {
|
|
|
|
{ "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
2012-06-13 17:41:00 +00:00
|
|
|
{ "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
|
2012-06-13 17:05:43 +00:00
|
|
|
{ "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
|
2012-06-13 17:41:00 +00:00
|
|
|
{ "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
|
|
|
|
{ "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
|
|
|
|
{ "M 1 1 L 1 1 M 2 1 L 2 1", 4, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs6, SK_ARRAY_COUNT(resultVerbs6) },
|
|
|
|
{ "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
|
|
|
|
{ "M 1 1 L 1 1 z M 2 1 L 2 1 z", 4, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs8, SK_ARRAY_COUNT(resultVerbs8) },
|
|
|
|
{ "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
|
|
|
|
{ "M 1 1 Q 1 1 1 1 M 2 1 Q 2 1 2 1", 6, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs10, SK_ARRAY_COUNT(resultVerbs10) },
|
|
|
|
{ "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
|
|
|
|
{ "M 1 1 Q 1 1 1 1 z M 2 1 Q 2 1 2 1 z", 6, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs12, SK_ARRAY_COUNT(resultVerbs12) },
|
|
|
|
{ "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
|
|
|
|
{ "M 1 1 C 1 1 1 1 1 1 M 2 1 C 2 1 2 1 2 1", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs14,
|
2012-06-13 17:05:43 +00:00
|
|
|
SK_ARRAY_COUNT(resultVerbs14)
|
|
|
|
},
|
2012-06-13 17:41:00 +00:00
|
|
|
{ "M 1 1 C 1 1 1 1 1 1 z", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs15, SK_ARRAY_COUNT(resultVerbs15) },
|
|
|
|
{ "M 1 1 C 1 1 1 1 1 1 z M 2 1 C 2 1 2 1 2 1 z", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs16,
|
2012-06-13 17:05:43 +00:00
|
|
|
SK_ARRAY_COUNT(resultVerbs16)
|
|
|
|
}
|
|
|
|
};
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
|
2012-06-13 17:05:43 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
|
|
|
|
p.reset();
|
|
|
|
bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
|
|
|
|
REPORTER_ASSERT(reporter, valid);
|
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
|
|
|
|
REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
|
|
|
|
for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
|
|
|
|
REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
|
|
|
|
}
|
2012-06-07 21:43:15 +00:00
|
|
|
}
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SegmentInfo {
|
|
|
|
SkPath fPath;
|
|
|
|
int fPointCount;
|
|
|
|
};
|
|
|
|
|
2011-09-21 12:29:05 +00:00
|
|
|
#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
static void test_segment_masks(skiatest::Reporter* reporter) {
|
2012-08-01 20:01:49 +00:00
|
|
|
SkPath p, p2;
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
p.moveTo(0, 0);
|
|
|
|
p.quadTo(100, 100, 200, 200);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
|
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
2012-08-01 20:01:49 +00:00
|
|
|
p2 = p;
|
|
|
|
REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
|
2012-01-04 21:05:51 +00:00
|
|
|
p.cubicTo(100, 100, 200, 200, 300, 300);
|
|
|
|
REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
|
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
2012-08-01 20:01:49 +00:00
|
|
|
p2 = p;
|
|
|
|
REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
p.reset();
|
|
|
|
p.moveTo(0, 0);
|
|
|
|
p.cubicTo(100, 100, 200, 200, 300, 300);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
|
2012-08-01 20:01:49 +00:00
|
|
|
p2 = p;
|
|
|
|
REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_iter(skiatest::Reporter* reporter) {
|
2012-06-13 17:05:43 +00:00
|
|
|
SkPath p;
|
2012-01-04 21:05:51 +00:00
|
|
|
SkPoint pts[4];
|
|
|
|
|
|
|
|
// Test an iterator with no path
|
|
|
|
SkPath::Iter noPathIter;
|
|
|
|
REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
|
2012-06-13 17:05:43 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
// Test that setting an empty path works
|
|
|
|
noPathIter.setPath(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
|
2012-06-13 17:05:43 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
// Test that close path makes no difference for an empty path
|
|
|
|
noPathIter.setPath(p, true);
|
|
|
|
REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
|
2012-06-13 17:05:43 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
// Test an iterator with an initial empty path
|
|
|
|
SkPath::Iter iter(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// Test that close path makes no difference
|
2012-06-13 17:05:43 +00:00
|
|
|
iter.setPath(p, true);
|
2012-01-04 21:05:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-06-13 17:05:43 +00:00
|
|
|
struct iterTestData {
|
|
|
|
const char* testPath;
|
|
|
|
const bool forceClose;
|
|
|
|
const bool consumeDegenerates;
|
|
|
|
const size_t* numResultPtsPerVerb;
|
|
|
|
const SkPoint* resultPts;
|
|
|
|
const SkPath::Verb* resultVerbs;
|
|
|
|
const size_t numResultVerbs;
|
|
|
|
};
|
2012-01-04 21:05:51 +00:00
|
|
|
|
2012-06-13 17:05:43 +00:00
|
|
|
static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
|
|
|
|
static const SkPath::Verb resultVerbs2[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
|
|
|
|
};
|
|
|
|
static const SkPath::Verb resultVerbs3[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
|
|
|
|
};
|
|
|
|
static const SkPath::Verb resultVerbs4[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
|
|
|
|
};
|
|
|
|
static const SkPath::Verb resultVerbs5[] = {
|
|
|
|
SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
|
|
|
|
};
|
|
|
|
static const size_t resultPtsSizes1[] = { 0 };
|
2012-06-13 18:29:20 +00:00
|
|
|
static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
|
|
|
|
static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
|
|
|
|
static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
|
|
|
|
static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
|
2012-06-13 17:41:00 +00:00
|
|
|
static const SkPoint* resultPts1 = 0;
|
2012-06-13 17:05:43 +00:00
|
|
|
static const SkPoint resultPts2[] = {
|
|
|
|
{ SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
|
|
|
|
};
|
|
|
|
static const SkPoint resultPts3[] = {
|
|
|
|
{ SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
|
|
|
|
{ 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
|
|
|
|
};
|
|
|
|
static const SkPoint resultPts4[] = {
|
|
|
|
{ SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
|
|
|
|
};
|
|
|
|
static const SkPoint resultPts5[] = {
|
|
|
|
{ SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
|
|
|
|
};
|
|
|
|
static const struct iterTestData gIterTests[] = {
|
|
|
|
{ "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
2012-06-13 17:41:00 +00:00
|
|
|
{ "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "M 1 0 M 1 0 M 3 0 M 4 0 M 5 0", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
2012-06-13 17:05:43 +00:00
|
|
|
{ "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "z M 1 0 z z M 2 0 z M 3 0 M 4 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "z M 1 0 z z M 2 0 z M 3 0 M 4 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
2012-06-13 17:41:00 +00:00
|
|
|
{ "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
|
|
|
|
{ "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
|
|
|
|
{ "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
|
|
|
|
{ "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
|
|
|
|
{ "M 1 0 L 1 0 M 0 0 z", true, false, resultPtsSizes5, resultPts5, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }
|
2012-06-13 17:05:43 +00:00
|
|
|
};
|
2012-01-04 21:05:51 +00:00
|
|
|
|
2012-06-13 17:05:43 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
|
|
|
|
p.reset();
|
|
|
|
bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
|
|
|
|
REPORTER_ASSERT(reporter, valid);
|
|
|
|
iter.setPath(p, gIterTests[i].forceClose);
|
|
|
|
int j = 0, l = 0;
|
|
|
|
do {
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
|
|
|
|
for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
|
|
|
|
REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
|
|
|
|
}
|
|
|
|
} while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
|
|
|
|
}
|
2012-01-04 21:05:51 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
p.reset();
|
|
|
|
iter.setPath(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, !iter.isClosedContour());
|
|
|
|
p.lineTo(1, 1);
|
|
|
|
p.close();
|
|
|
|
iter.setPath(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, iter.isClosedContour());
|
|
|
|
p.reset();
|
|
|
|
iter.setPath(p, true);
|
|
|
|
REPORTER_ASSERT(reporter, !iter.isClosedContour());
|
|
|
|
p.lineTo(1, 1);
|
|
|
|
iter.setPath(p, true);
|
|
|
|
REPORTER_ASSERT(reporter, iter.isClosedContour());
|
|
|
|
p.moveTo(0, 0);
|
|
|
|
p.lineTo(2, 2);
|
|
|
|
iter.setPath(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, !iter.isClosedContour());
|
|
|
|
|
|
|
|
// this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
|
|
|
|
// check to see if the result is correct.
|
|
|
|
for (int setNaN = 0; setNaN < 4; ++setNaN) {
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
|
|
|
|
p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
|
|
|
|
iter.setPath(p, true);
|
|
|
|
iter.next(pts, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
p.reset();
|
|
|
|
p.quadTo(0, 0, 0, 0);
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
|
|
|
|
|
|
|
|
p.reset();
|
|
|
|
p.conicTo(0, 0, 0, 0, 0.5f);
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
|
|
|
|
|
|
|
|
p.reset();
|
|
|
|
p.cubicTo(0, 0, 0, 0, 0, 0);
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
|
|
|
|
|
|
|
|
p.moveTo(1, 1); // add a trailing moveto
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
|
|
|
|
iter.setPath(p, false);
|
|
|
|
iter.next(pts, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
// The GM degeneratesegments.cpp test is more extensive
|
2015-02-23 19:17:01 +00:00
|
|
|
|
|
|
|
// Test out mixed degenerate and non-degenerate geometry with Conics
|
|
|
|
const SkVector radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 100, 100 } };
|
|
|
|
SkRect r = SkRect::MakeWH(100, 100);
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRectRadii(r, radii);
|
|
|
|
p.reset();
|
|
|
|
p.addRRect(rr);
|
|
|
|
iter.setPath(p, false);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kMove_Verb == iter.next(pts));
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts));
|
|
|
|
REPORTER_ASSERT(reporter, SK_ScalarRoot2Over2 == iter.conicWeight());
|
2012-01-04 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_raw_iter(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
SkPoint pts[4];
|
|
|
|
|
|
|
|
// Test an iterator with no path
|
|
|
|
SkPath::RawIter noPathIter;
|
|
|
|
REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
// Test that setting an empty path works
|
|
|
|
noPathIter.setPath(p);
|
|
|
|
REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
// Test an iterator with an initial empty path
|
|
|
|
SkPath::RawIter iter(p);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// Test that a move-only path returns the move.
|
|
|
|
p.moveTo(SK_Scalar1, 0);
|
|
|
|
iter.setPath(p);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == 0);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// No matter how many moves we add, we should get them all back
|
|
|
|
p.moveTo(SK_Scalar1*2, SK_Scalar1);
|
|
|
|
p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
|
|
|
|
iter.setPath(p);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == 0);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// Initial close is never ever stored
|
|
|
|
p.reset();
|
|
|
|
p.close();
|
|
|
|
iter.setPath(p);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// Move/close sequences
|
|
|
|
p.reset();
|
|
|
|
p.close(); // Not stored, no purpose
|
|
|
|
p.moveTo(SK_Scalar1, 0);
|
|
|
|
p.close();
|
|
|
|
p.close(); // Not stored, no purpose
|
|
|
|
p.moveTo(SK_Scalar1*2, SK_Scalar1);
|
|
|
|
p.close();
|
|
|
|
p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
|
|
|
|
p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
|
|
|
|
p.close();
|
|
|
|
iter.setPath(p);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == 0);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
|
|
|
|
|
|
|
|
// Generate random paths and verify
|
|
|
|
SkPoint randomPts[25];
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
for (int j = 0; j < 5; ++j) {
|
|
|
|
randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max of 10 segments, max 3 points per segment
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand(9876543);
|
2012-01-04 21:05:51 +00:00
|
|
|
SkPoint expectedPts[31]; // May have leading moveTo
|
2012-01-12 18:17:11 +00:00
|
|
|
SkPath::Verb expectedVerbs[22]; // May have leading moveTo
|
2012-01-04 21:05:51 +00:00
|
|
|
SkPath::Verb nextVerb;
|
2012-01-12 18:17:11 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
for (int i = 0; i < 500; ++i) {
|
|
|
|
p.reset();
|
|
|
|
bool lastWasClose = true;
|
|
|
|
bool haveMoveTo = false;
|
2012-01-12 18:17:11 +00:00
|
|
|
SkPoint lastMoveToPt = { 0, 0 };
|
2012-01-04 21:05:51 +00:00
|
|
|
int numPoints = 0;
|
|
|
|
int numVerbs = (rand.nextU() >> 16) % 10;
|
|
|
|
int numIterVerbs = 0;
|
|
|
|
for (int j = 0; j < numVerbs; ++j) {
|
|
|
|
do {
|
|
|
|
nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
|
|
|
|
} while (lastWasClose && nextVerb == SkPath::kClose_Verb);
|
|
|
|
switch (nextVerb) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
p.moveTo(expectedPts[numPoints]);
|
2012-01-12 18:17:11 +00:00
|
|
|
lastMoveToPt = expectedPts[numPoints];
|
2012-01-04 21:05:51 +00:00
|
|
|
numPoints += 1;
|
|
|
|
lastWasClose = false;
|
|
|
|
haveMoveTo = true;
|
|
|
|
break;
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
if (!haveMoveTo) {
|
2012-01-12 18:17:11 +00:00
|
|
|
expectedPts[numPoints++] = lastMoveToPt;
|
2012-01-04 21:05:51 +00:00
|
|
|
expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
|
|
|
|
haveMoveTo = true;
|
|
|
|
}
|
|
|
|
expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
p.lineTo(expectedPts[numPoints]);
|
|
|
|
numPoints += 1;
|
|
|
|
lastWasClose = false;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
if (!haveMoveTo) {
|
2012-01-12 18:17:11 +00:00
|
|
|
expectedPts[numPoints++] = lastMoveToPt;
|
2012-01-04 21:05:51 +00:00
|
|
|
expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
|
|
|
|
haveMoveTo = true;
|
|
|
|
}
|
|
|
|
expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
|
|
|
|
numPoints += 2;
|
|
|
|
lastWasClose = false;
|
|
|
|
break;
|
2013-05-31 15:17:50 +00:00
|
|
|
case SkPath::kConic_Verb:
|
|
|
|
if (!haveMoveTo) {
|
|
|
|
expectedPts[numPoints++] = lastMoveToPt;
|
|
|
|
expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
|
|
|
|
haveMoveTo = true;
|
|
|
|
}
|
|
|
|
expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
|
|
|
|
rand.nextUScalar1() * 4);
|
|
|
|
numPoints += 2;
|
|
|
|
lastWasClose = false;
|
|
|
|
break;
|
2012-01-04 21:05:51 +00:00
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
if (!haveMoveTo) {
|
2012-01-12 18:17:11 +00:00
|
|
|
expectedPts[numPoints++] = lastMoveToPt;
|
2012-01-04 21:05:51 +00:00
|
|
|
expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
|
|
|
|
haveMoveTo = true;
|
|
|
|
}
|
|
|
|
expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
|
|
|
|
p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
|
|
|
|
expectedPts[numPoints + 2]);
|
|
|
|
numPoints += 3;
|
|
|
|
lastWasClose = false;
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
p.close();
|
2012-01-12 18:17:11 +00:00
|
|
|
haveMoveTo = false;
|
2012-01-04 21:05:51 +00:00
|
|
|
lastWasClose = true;
|
|
|
|
break;
|
2013-05-31 15:17:50 +00:00
|
|
|
default:
|
2013-08-22 15:37:26 +00:00
|
|
|
SkDEBUGFAIL("unexpected verb");
|
2012-01-04 21:05:51 +00:00
|
|
|
}
|
|
|
|
expectedVerbs[numIterVerbs++] = nextVerb;
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
iter.setPath(p);
|
|
|
|
numVerbs = numIterVerbs;
|
|
|
|
numIterVerbs = 0;
|
|
|
|
int numIterPts = 0;
|
|
|
|
SkPoint lastMoveTo;
|
|
|
|
SkPoint lastPt;
|
|
|
|
lastMoveTo.set(0, 0);
|
|
|
|
lastPt.set(0, 0);
|
|
|
|
while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
|
|
|
|
REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
|
|
|
|
numIterVerbs++;
|
|
|
|
switch (nextVerb) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, numIterPts < numPoints);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
|
|
|
|
lastPt = lastMoveTo = pts[0];
|
|
|
|
numIterPts += 1;
|
|
|
|
break;
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0] == lastPt);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
|
|
|
|
lastPt = pts[1];
|
|
|
|
numIterPts += 1;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
2013-05-31 15:17:50 +00:00
|
|
|
case SkPath::kConic_Verb:
|
2012-01-04 21:05:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0] == lastPt);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
|
|
|
|
REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
|
|
|
|
lastPt = pts[2];
|
|
|
|
numIterPts += 2;
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0] == lastPt);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
|
|
|
|
REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
|
|
|
|
REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
|
|
|
|
lastPt = pts[3];
|
|
|
|
numIterPts += 3;
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
lastPt = lastMoveTo;
|
|
|
|
break;
|
2013-05-31 15:17:50 +00:00
|
|
|
default:
|
2013-08-22 15:37:26 +00:00
|
|
|
SkDEBUGFAIL("unexpected verb");
|
2012-01-04 21:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, numIterPts == numPoints);
|
|
|
|
REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 13:29:52 +00:00
|
|
|
static void check_for_circle(skiatest::Reporter* reporter,
|
2012-11-13 14:36:42 +00:00
|
|
|
const SkPath& path,
|
|
|
|
bool expectedCircle,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection expectedDir) {
|
2013-12-03 16:43:54 +00:00
|
|
|
SkRect rect = SkRect::MakeEmpty();
|
2012-11-13 14:36:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDir));
|
2012-11-13 21:46:06 +00:00
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
if (expectedCircle) {
|
2012-04-18 13:29:52 +00:00
|
|
|
REPORTER_ASSERT(reporter, rect.height() == rect.width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_skew(skiatest::Reporter* reporter,
|
2012-11-13 14:36:42 +00:00
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-04-18 13:29:52 +00:00
|
|
|
SkPath tmp;
|
|
|
|
|
|
|
|
SkMatrix m;
|
|
|
|
m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
|
|
|
|
path.transform(m, &tmp);
|
2012-11-13 14:36:42 +00:00
|
|
|
// this matrix reverses the direction.
|
2015-06-10 21:23:15 +00:00
|
|
|
if (SkPathPriv::kCCW_FirstDirection == dir) {
|
|
|
|
dir = SkPathPriv::kCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
} else {
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::kCW_FirstDirection == dir);
|
|
|
|
dir = SkPathPriv::kCCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
}
|
|
|
|
check_for_circle(reporter, tmp, false, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_translate(skiatest::Reporter* reporter,
|
2012-11-13 14:36:42 +00:00
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-04-18 13:29:52 +00:00
|
|
|
SkPath tmp;
|
|
|
|
|
|
|
|
// translate at small offset
|
|
|
|
SkMatrix m;
|
|
|
|
m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
|
|
|
|
path.transform(m, &tmp);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
tmp.reset();
|
|
|
|
m.reset();
|
|
|
|
|
|
|
|
// translate at a relatively big offset
|
|
|
|
m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
|
|
|
|
path.transform(m, &tmp);
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_rotate(skiatest::Reporter* reporter,
|
2012-11-13 14:36:42 +00:00
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-04-18 13:29:52 +00:00
|
|
|
for (int angle = 0; angle < 360; ++angle) {
|
|
|
|
SkPath tmp;
|
|
|
|
SkMatrix m;
|
|
|
|
m.setRotate(SkIntToScalar(angle));
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
// TODO: a rotated circle whose rotated angle is not a multiple of 90
|
2012-04-18 13:29:52 +00:00
|
|
|
// degrees is not an oval anymore, this can be improved. we made this
|
|
|
|
// for the simplicity of our implementation.
|
|
|
|
if (angle % 90 == 0) {
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
} else {
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, tmp, false, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
static void test_circle_mirror_x(skiatest::Reporter* reporter,
|
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-11-13 14:36:42 +00:00
|
|
|
SkPath tmp;
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.setScaleX(-SK_Scalar1);
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
|
2015-06-10 21:23:15 +00:00
|
|
|
if (SkPathPriv::kCW_FirstDirection == dir) {
|
|
|
|
dir = SkPathPriv::kCCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
} else {
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
|
|
|
|
dir = SkPathPriv::kCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_mirror_y(skiatest::Reporter* reporter,
|
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-11-13 14:36:42 +00:00
|
|
|
SkPath tmp;
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.setScaleY(-SK_Scalar1);
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
|
2015-06-10 21:23:15 +00:00
|
|
|
if (SkPathPriv::kCW_FirstDirection == dir) {
|
|
|
|
dir = SkPathPriv::kCCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
} else {
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
|
|
|
|
dir = SkPathPriv::kCW_FirstDirection;
|
2012-11-13 14:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_mirror_xy(skiatest::Reporter* reporter,
|
|
|
|
const SkPath& path,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPathPriv::FirstDirection dir) {
|
2012-11-13 14:36:42 +00:00
|
|
|
SkPath tmp;
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.setScaleX(-SK_Scalar1);
|
|
|
|
m.setScaleY(-SK_Scalar1);
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
|
|
|
|
check_for_circle(reporter, tmp, true, dir);
|
|
|
|
}
|
|
|
|
|
2012-04-18 13:29:52 +00:00
|
|
|
static void test_circle_with_direction(skiatest::Reporter* reporter,
|
2015-06-10 21:23:15 +00:00
|
|
|
SkPath::Direction inDir) {
|
|
|
|
const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir);
|
2012-04-18 13:29:52 +00:00
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
// circle at origin
|
2015-06-10 21:23:15 +00:00
|
|
|
path.addCircle(0, 0, SkIntToScalar(20), inDir);
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, path, true, dir);
|
|
|
|
test_circle_rotate(reporter, path, dir);
|
|
|
|
test_circle_translate(reporter, path, dir);
|
|
|
|
test_circle_skew(reporter, path, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// circle at an offset at (10, 10)
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
|
2015-06-10 21:23:15 +00:00
|
|
|
SkIntToScalar(20), inDir);
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
check_for_circle(reporter, path, true, dir);
|
|
|
|
test_circle_rotate(reporter, path, dir);
|
|
|
|
test_circle_translate(reporter, path, dir);
|
|
|
|
test_circle_skew(reporter, path, dir);
|
|
|
|
test_circle_mirror_x(reporter, path, dir);
|
|
|
|
test_circle_mirror_y(reporter, path, dir);
|
|
|
|
test_circle_mirror_xy(reporter, path, dir);
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
|
|
|
|
SkPath path;
|
|
|
|
SkPath circle;
|
|
|
|
SkPath rect;
|
|
|
|
SkPath empty;
|
|
|
|
|
2015-06-10 21:23:15 +00:00
|
|
|
const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
|
|
|
|
const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
|
2012-11-13 14:36:42 +00:00
|
|
|
|
|
|
|
circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
|
2012-04-18 13:29:52 +00:00
|
|
|
rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
|
|
|
|
SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
|
|
|
|
|
|
|
|
SkMatrix translate;
|
|
|
|
translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
// Although all the path concatenation related operations leave
|
|
|
|
// the path a circle, most mark it as a non-circle for simplicity
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// empty + circle (translate)
|
|
|
|
path = empty;
|
|
|
|
path.addPath(circle, translate);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDir));
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// circle + empty (translate)
|
|
|
|
path = circle;
|
|
|
|
path.addPath(empty, translate);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleDir));
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// test reverseAddPath
|
|
|
|
path = circle;
|
|
|
|
path.reverseAddPath(rect);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDirOpposite));
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_circle(skiatest::Reporter* reporter) {
|
|
|
|
test_circle_with_direction(reporter, SkPath::kCW_Direction);
|
|
|
|
test_circle_with_direction(reporter, SkPath::kCCW_Direction);
|
|
|
|
|
|
|
|
// multiple addCircle()
|
|
|
|
SkPath path;
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// some extra lineTo() would make isOval() fail
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
|
|
|
|
path.lineTo(0, 0);
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
// not back to the original point
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
|
|
|
|
path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
|
2015-06-10 21:23:15 +00:00
|
|
|
check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
|
2012-04-18 13:29:52 +00:00
|
|
|
|
|
|
|
test_circle_with_add_paths(reporter);
|
2013-11-14 16:53:22 +00:00
|
|
|
|
|
|
|
// test negative radius
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(0, 0, -1, SkPath::kCW_Direction);
|
|
|
|
REPORTER_ASSERT(reporter, path.isEmpty());
|
2012-04-18 13:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_oval(skiatest::Reporter* reporter) {
|
|
|
|
SkRect rect;
|
|
|
|
SkMatrix m;
|
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
|
|
|
|
path.addOval(rect);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, path.isOval(NULL));
|
|
|
|
|
|
|
|
m.setRotate(SkIntToScalar(90));
|
|
|
|
SkPath tmp;
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
// an oval rotated 90 degrees is still an oval.
|
|
|
|
REPORTER_ASSERT(reporter, tmp.isOval(NULL));
|
|
|
|
|
|
|
|
m.reset();
|
|
|
|
m.setRotate(SkIntToScalar(30));
|
|
|
|
tmp.reset();
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
// an oval rotated 30 degrees is not an oval anymore.
|
|
|
|
REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
|
|
|
|
|
|
|
|
// since empty path being transformed.
|
|
|
|
path.reset();
|
|
|
|
tmp.reset();
|
|
|
|
m.reset();
|
|
|
|
path.transform(m, &tmp);
|
|
|
|
REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
|
|
|
|
|
|
|
|
// empty path is not an oval
|
|
|
|
tmp.reset();
|
|
|
|
REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
|
|
|
|
|
|
|
|
// only has moveTo()s
|
|
|
|
tmp.reset();
|
|
|
|
tmp.moveTo(0, 0);
|
|
|
|
tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
|
|
|
|
|
|
|
|
// mimic WebKit's calling convention,
|
|
|
|
// call moveTo() first and then call addOval()
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.addOval(rect);
|
|
|
|
REPORTER_ASSERT(reporter, path.isOval(NULL));
|
|
|
|
|
|
|
|
// copy path
|
|
|
|
path.reset();
|
|
|
|
tmp.reset();
|
|
|
|
tmp.addOval(rect);
|
|
|
|
path = tmp;
|
|
|
|
REPORTER_ASSERT(reporter, path.isOval(NULL));
|
|
|
|
}
|
|
|
|
|
2013-06-21 15:13:34 +00:00
|
|
|
static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
|
|
|
|
SkPath empty;
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2009-03-02 05:36:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == p.countPoints());
|
2012-06-07 21:43:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == p.countVerbs());
|
2011-09-21 12:29:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
|
2011-05-16 14:16:04 +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());
|
2013-06-21 15:13:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, p == empty);
|
|
|
|
REPORTER_ASSERT(reporter, !(p != empty));
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
|
|
|
|
SkPath::Direction dir) {
|
2013-11-08 15:51:12 +00:00
|
|
|
REPORTER_ASSERT(reporter, path->isConvex());
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
|
2013-11-08 15:51:12 +00:00
|
|
|
path->setConvexity(SkPath::kUnknown_Convexity);
|
|
|
|
REPORTER_ASSERT(reporter, path->isConvex());
|
|
|
|
path->reset();
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:57:38 +00:00
|
|
|
static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
|
|
|
|
SkPath::Direction dir) {
|
|
|
|
REPORTER_ASSERT(reporter, path->isConvex());
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
|
2014-12-08 12:57:38 +00:00
|
|
|
path->setConvexity(SkPath::kUnknown_Convexity);
|
|
|
|
REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
|
|
|
|
path->reset();
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:51:12 +00:00
|
|
|
static void test_rrect(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
SkRRect rr;
|
|
|
|
SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
|
|
|
|
SkRect r = {10, 20, 30, 40};
|
|
|
|
rr.setRectRadii(r, radii);
|
|
|
|
p.addRRect(rr);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
2013-11-08 15:51:12 +00:00
|
|
|
p.addRRect(rr, SkPath::kCCW_Direction);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
|
2013-11-08 15:51:12 +00:00
|
|
|
p.addRoundRect(r, &radii[0].fX);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
2013-11-08 15:51:12 +00:00
|
|
|
p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
|
2013-11-08 15:51:12 +00:00
|
|
|
p.addRoundRect(r, radii[1].fX, radii[1].fY);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
2013-11-08 15:51:12 +00:00
|
|
|
p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
|
|
|
|
SkVector save = radii[i];
|
|
|
|
radii[i].set(0, 0);
|
|
|
|
rr.setRectRadii(r, radii);
|
|
|
|
p.addRRect(rr);
|
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
|
|
|
radii[i] = save;
|
|
|
|
}
|
|
|
|
p.addRoundRect(r, 0, 0);
|
|
|
|
SkRect returnedRect;
|
|
|
|
REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
|
|
|
|
REPORTER_ASSERT(reporter, returnedRect == r);
|
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
|
|
|
SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
|
|
|
|
rr.setRectRadii(r, zeroRadii);
|
|
|
|
p.addRRect(rr);
|
|
|
|
bool closed;
|
|
|
|
SkPath::Direction dir;
|
2015-01-05 18:13:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.isRect(NULL, &closed, &dir));
|
2013-11-14 16:53:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, closed);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
|
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
|
|
|
p.addRRect(rr, SkPath::kCW_Direction);
|
|
|
|
p.addRRect(rr, SkPath::kCW_Direction);
|
|
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
|
|
p.reset();
|
|
|
|
p.addRRect(rr, SkPath::kCCW_Direction);
|
|
|
|
p.addRRect(rr, SkPath::kCCW_Direction);
|
|
|
|
REPORTER_ASSERT(reporter, !p.isConvex());
|
|
|
|
p.reset();
|
|
|
|
SkRect emptyR = {10, 20, 10, 30};
|
|
|
|
rr.setRectRadii(emptyR, radii);
|
|
|
|
p.addRRect(rr);
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
|
|
SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
|
|
|
|
rr.setRectRadii(largeR, radii);
|
|
|
|
p.addRRect(rr);
|
2014-12-08 12:57:38 +00:00
|
|
|
test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
|
2015-02-10 16:46:22 +00:00
|
|
|
|
|
|
|
// we check for non-finites
|
2013-11-14 16:53:22 +00:00
|
|
|
SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
|
|
|
|
rr.setRectRadii(infR, radii);
|
2015-02-10 16:46:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, rr.isEmpty());
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
|
|
|
|
p.addRoundRect(tinyR, 5e-11f, 5e-11f);
|
|
|
|
test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_arc(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
SkRect emptyOval = {10, 20, 30, 20};
|
|
|
|
REPORTER_ASSERT(reporter, emptyOval.isEmpty());
|
|
|
|
p.addArc(emptyOval, 1, 2);
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
|
|
p.reset();
|
|
|
|
SkRect oval = {10, 20, 30, 40};
|
|
|
|
p.addArc(oval, 1, 0);
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
|
|
p.reset();
|
|
|
|
SkPath cwOval;
|
|
|
|
cwOval.addOval(oval);
|
|
|
|
p.addArc(oval, 1, 360);
|
|
|
|
REPORTER_ASSERT(reporter, p == cwOval);
|
|
|
|
p.reset();
|
|
|
|
SkPath ccwOval;
|
|
|
|
ccwOval.addOval(oval, SkPath::kCCW_Direction);
|
|
|
|
p.addArc(oval, 1, -360);
|
|
|
|
REPORTER_ASSERT(reporter, p == ccwOval);
|
|
|
|
p.reset();
|
|
|
|
p.addArc(oval, 1, 180);
|
|
|
|
REPORTER_ASSERT(reporter, p.isConvex());
|
2015-06-10 21:23:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p, SkPathPriv::kCW_FirstDirection));
|
2013-11-14 16:53:22 +00:00
|
|
|
p.setConvexity(SkPath::kUnknown_Convexity);
|
|
|
|
REPORTER_ASSERT(reporter, p.isConvex());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
|
|
|
|
SkScalar x0, SkScalar y0) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb v = iter->next(pts);
|
|
|
|
REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fX == x0);
|
|
|
|
REPORTER_ASSERT(reporter, pts[0].fY == y0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
|
|
|
|
SkScalar x1, SkScalar y1) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb v = iter->next(pts);
|
|
|
|
REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].fX == x1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].fY == y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
|
|
|
|
SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb v = iter->next(pts);
|
|
|
|
REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].fX == x1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[1].fY == y1);
|
|
|
|
REPORTER_ASSERT(reporter, pts[2].fX == x2);
|
|
|
|
REPORTER_ASSERT(reporter, pts[2].fY == y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb v = iter->next(pts);
|
|
|
|
REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
|
|
|
|
check_done(reporter, p, iter);
|
|
|
|
p->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
|
|
|
|
SkScalar x0, SkScalar y0) {
|
|
|
|
SkPath::RawIter iter(*p);
|
|
|
|
check_move(reporter, &iter, x0, y0);
|
|
|
|
check_done_and_reset(reporter, p, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
|
|
|
|
SkScalar x1, SkScalar y1) {
|
|
|
|
SkPath::RawIter iter(*p);
|
|
|
|
check_move(reporter, &iter, 0, 0);
|
|
|
|
check_line(reporter, &iter, x1, y1);
|
|
|
|
check_done_and_reset(reporter, p, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
|
|
|
|
SkScalar x1, SkScalar y1) {
|
|
|
|
SkPath::RawIter iter(*p);
|
|
|
|
check_move(reporter, &iter, 0, 0);
|
|
|
|
check_line(reporter, &iter, x1, y1);
|
|
|
|
check_done(reporter, p, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
|
|
|
|
SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
|
|
|
|
SkPath::RawIter iter(*p);
|
|
|
|
check_move(reporter, &iter, 0, 0);
|
|
|
|
check_line(reporter, &iter, x1, y1);
|
|
|
|
check_line(reporter, &iter, x2, y2);
|
|
|
|
check_done_and_reset(reporter, p, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
|
|
|
|
SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
|
|
|
|
SkPath::RawIter iter(*p);
|
|
|
|
check_move(reporter, &iter, 0, 0);
|
|
|
|
check_quad(reporter, &iter, x1, y1, x2, y2);
|
|
|
|
check_done_and_reset(reporter, p, &iter);
|
2013-11-08 15:51:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 21:54:43 +00:00
|
|
|
static bool nearly_equal(const SkRect& a, const SkRect& b) {
|
|
|
|
return SkScalarNearlyEqual(a.fLeft, b.fLeft) &&
|
|
|
|
SkScalarNearlyEqual(a.fTop, b.fTop) &&
|
|
|
|
SkScalarNearlyEqual(a.fRight, b.fRight) &&
|
|
|
|
SkScalarNearlyEqual(a.fBottom, b.fBottom);
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
static void test_arcTo(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
p.arcTo(0, 0, 1, 2, 1);
|
|
|
|
check_path_is_line_and_reset(reporter, &p, 0, 0);
|
|
|
|
p.arcTo(1, 2, 1, 2, 1);
|
|
|
|
check_path_is_line_and_reset(reporter, &p, 1, 2);
|
|
|
|
p.arcTo(1, 2, 3, 4, 0);
|
|
|
|
check_path_is_line_and_reset(reporter, &p, 1, 2);
|
|
|
|
p.arcTo(1, 2, 0, 0, 1);
|
|
|
|
check_path_is_line_and_reset(reporter, &p, 1, 2);
|
|
|
|
p.arcTo(1, 0, 1, 1, 1);
|
|
|
|
SkPoint pt;
|
|
|
|
REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
|
|
|
|
p.reset();
|
|
|
|
p.arcTo(1, 0, 1, -1, 1);
|
|
|
|
REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
|
|
|
|
p.reset();
|
|
|
|
SkRect oval = {1, 2, 3, 4};
|
|
|
|
p.arcTo(oval, 0, 0, true);
|
|
|
|
check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
|
|
|
|
p.arcTo(oval, 0, 0, false);
|
|
|
|
check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
|
|
|
|
p.arcTo(oval, 360, 0, true);
|
|
|
|
check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
|
|
|
|
p.arcTo(oval, 360, 0, false);
|
|
|
|
check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
|
2015-02-09 21:54:43 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
|
2013-11-25 19:44:07 +00:00
|
|
|
p.arcTo(oval, 0, sweep, false);
|
2015-02-09 21:54:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
|
2013-11-14 16:53:22 +00:00
|
|
|
sweep += delta;
|
|
|
|
delta /= 2;
|
|
|
|
}
|
|
|
|
for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
|
2013-11-25 19:44:07 +00:00
|
|
|
p.arcTo(oval, 0, sweep, false);
|
2015-02-09 21:54:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
|
2013-11-14 16:53:22 +00:00
|
|
|
sweep -= delta;
|
|
|
|
delta /= 2;
|
|
|
|
}
|
|
|
|
SkRect noOvalWidth = {1, 2, 0, 3};
|
|
|
|
p.reset();
|
|
|
|
p.arcTo(noOvalWidth, 0, 360, false);
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
|
|
|
|
|
|
SkRect noOvalHeight = {1, 2, 3, 1};
|
|
|
|
p.reset();
|
|
|
|
p.arcTo(noOvalHeight, 0, 360, false);
|
|
|
|
REPORTER_ASSERT(reporter, p.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_addPath(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p, q;
|
|
|
|
p.lineTo(1, 2);
|
|
|
|
q.moveTo(4, 4);
|
|
|
|
q.lineTo(7, 8);
|
|
|
|
q.conicTo(8, 7, 6, 5, 0.5f);
|
|
|
|
q.quadTo(6, 7, 8, 6);
|
|
|
|
q.cubicTo(5, 6, 7, 8, 7, 5);
|
|
|
|
q.close();
|
|
|
|
p.addPath(q, -4, -4);
|
|
|
|
SkRect expected = {0, 0, 4, 4};
|
|
|
|
REPORTER_ASSERT(reporter, p.getBounds() == expected);
|
|
|
|
p.reset();
|
|
|
|
p.reverseAddPath(q);
|
|
|
|
SkRect reverseExpected = {4, 4, 8, 8};
|
|
|
|
REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
|
|
|
|
}
|
|
|
|
|
2014-02-11 21:16:29 +00:00
|
|
|
static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
|
|
|
|
SkPath p, q;
|
|
|
|
if (explicitMoveTo) {
|
|
|
|
p.moveTo(1, 1);
|
|
|
|
}
|
|
|
|
p.lineTo(1, 2);
|
|
|
|
if (explicitMoveTo) {
|
|
|
|
q.moveTo(2, 1);
|
|
|
|
}
|
|
|
|
q.lineTo(2, 2);
|
|
|
|
p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
|
|
|
|
uint8_t verbs[4];
|
|
|
|
int verbcount = p.getVerbs(verbs, 4);
|
|
|
|
REPORTER_ASSERT(reporter, verbcount == 4);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
|
|
|
|
REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_extendClosedPath(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p, q;
|
|
|
|
p.moveTo(1, 1);
|
|
|
|
p.lineTo(1, 2);
|
|
|
|
p.lineTo(2, 2);
|
|
|
|
p.close();
|
|
|
|
q.moveTo(2, 1);
|
|
|
|
q.lineTo(2, 3);
|
|
|
|
p.addPath(q, SkPath::kExtend_AddPathMode);
|
|
|
|
uint8_t verbs[7];
|
|
|
|
int verbcount = p.getVerbs(verbs, 7);
|
|
|
|
REPORTER_ASSERT(reporter, verbcount == 7);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
|
|
|
|
REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
|
|
|
|
|
|
|
|
SkPoint pt;
|
|
|
|
REPORTER_ASSERT(reporter, p.getLastPt(&pt));
|
|
|
|
REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
|
|
|
|
REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
|
|
|
|
SkPath p, q, r;
|
|
|
|
// case 1: dst is empty
|
|
|
|
p.moveTo(2, 1);
|
|
|
|
p.lineTo(2, 3);
|
|
|
|
q.addPath(p, mode);
|
|
|
|
REPORTER_ASSERT(reporter, q == p);
|
|
|
|
// case 2: src is empty
|
|
|
|
p.addPath(r, mode);
|
|
|
|
REPORTER_ASSERT(reporter, q == p);
|
|
|
|
// case 3: src and dst are empty
|
|
|
|
q.reset();
|
|
|
|
q.addPath(r, mode);
|
|
|
|
REPORTER_ASSERT(reporter, q.isEmpty());
|
2014-02-12 03:02:04 +00:00
|
|
|
}
|
2014-02-11 21:16:29 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
static void test_conicTo_special_case(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
p.conicTo(1, 2, 3, 4, -1);
|
|
|
|
check_path_is_line_and_reset(reporter, &p, 3, 4);
|
|
|
|
p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
|
|
|
|
check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
|
|
|
|
p.conicTo(1, 2, 3, 4, 1);
|
|
|
|
check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_get_point(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
SkPoint pt = p.getPoint(0);
|
|
|
|
REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
|
|
|
|
REPORTER_ASSERT(reporter, !p.getLastPt(NULL));
|
|
|
|
REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
|
|
|
|
p.setLastPt(10, 10);
|
|
|
|
pt = p.getPoint(0);
|
|
|
|
REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
|
|
|
|
REPORTER_ASSERT(reporter, p.getLastPt(NULL));
|
|
|
|
p.rMoveTo(10, 10);
|
|
|
|
REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_contains(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
|
|
|
p.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(0, 0));
|
|
|
|
p.setFillType(SkPath::kWinding_FillType);
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(0, 0));
|
|
|
|
p.moveTo(4, 4);
|
|
|
|
p.lineTo(6, 8);
|
|
|
|
p.lineTo(8, 4);
|
|
|
|
// test quick reject
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(4, 0));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(0, 4));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(4, 10));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(10, 4));
|
|
|
|
// test various crossings in x
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(5, 7));
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(6, 7));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(7, 7));
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(4, 4);
|
|
|
|
p.lineTo(8, 6);
|
|
|
|
p.lineTo(4, 8);
|
|
|
|
// test various crossings in y
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(7, 5));
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(7, 6));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(7, 7));
|
|
|
|
// test quads
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(4, 4);
|
|
|
|
p.quadTo(6, 6, 8, 8);
|
|
|
|
p.quadTo(6, 8, 4, 8);
|
|
|
|
p.quadTo(4, 6, 4, 4);
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(5, 6));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(6, 5));
|
|
|
|
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(6, 6);
|
|
|
|
p.quadTo(8, 8, 6, 8);
|
|
|
|
p.quadTo(4, 8, 4, 6);
|
|
|
|
p.quadTo(4, 4, 6, 6);
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(5, 6));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(6, 5));
|
|
|
|
|
|
|
|
#define CONIC_CONTAINS_BUG_FIXED 0
|
|
|
|
#if CONIC_CONTAINS_BUG_FIXED
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(4, 4);
|
|
|
|
p.conicTo(6, 6, 8, 8, 0.5f);
|
|
|
|
p.conicTo(6, 8, 4, 8, 0.5f);
|
|
|
|
p.conicTo(4, 6, 4, 4, 0.5f);
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(5, 6));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(6, 5));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// test cubics
|
|
|
|
SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
p.reset();
|
|
|
|
p.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
p.moveTo(pts[i].fX, pts[i].fY);
|
|
|
|
p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pts[i + 3].fX, pts[i + 3].fY);
|
|
|
|
p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pts[i + 6].fX, pts[i + 6].fY);
|
|
|
|
p.close();
|
|
|
|
REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
|
|
|
|
REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
class PathRefTest_Private {
|
|
|
|
public:
|
|
|
|
static void TestPathRef(skiatest::Reporter* reporter) {
|
|
|
|
static const int kRepeatCnt = 10;
|
2013-12-12 23:03:51 +00:00
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef));
|
2013-12-12 23:03:51 +00:00
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
SkPathRef::Editor ed(&pathRef);
|
2013-12-12 23:03:51 +00:00
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
{
|
|
|
|
ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
|
|
|
|
for (int i = 0; i < kRepeatCnt; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
|
|
|
|
}
|
|
|
|
ed.resetToSize(0, 0, 0);
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
{
|
|
|
|
ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
|
|
|
|
for (int i = 0; i < kRepeatCnt; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
|
|
|
|
}
|
|
|
|
ed.resetToSize(0, 0, 0);
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
{
|
|
|
|
ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
|
|
|
|
REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
|
|
|
|
for (int i = 0; i < kRepeatCnt; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
|
|
|
|
}
|
|
|
|
ed.resetToSize(0, 0, 0);
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
{
|
|
|
|
SkScalar* weights = NULL;
|
|
|
|
ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
|
|
|
|
REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, weights);
|
2013-12-13 19:36:25 +00:00
|
|
|
for (int i = 0; i < kRepeatCnt; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
|
|
|
|
}
|
|
|
|
ed.resetToSize(0, 0, 0);
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 19:36:25 +00:00
|
|
|
{
|
|
|
|
ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
|
|
|
|
REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
|
|
|
|
REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
|
|
|
|
for (int i = 0; i < kRepeatCnt; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
|
|
|
|
}
|
|
|
|
ed.resetToSize(0, 0, 0);
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-13 19:36:25 +00:00
|
|
|
};
|
2013-12-12 23:03:51 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
static void test_operatorEqual(skiatest::Reporter* reporter) {
|
|
|
|
SkPath a;
|
|
|
|
SkPath b;
|
|
|
|
REPORTER_ASSERT(reporter, a == a);
|
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
|
|
|
a.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
REPORTER_ASSERT(reporter, a != b);
|
|
|
|
a.reset();
|
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
|
|
|
a.lineTo(1, 1);
|
|
|
|
REPORTER_ASSERT(reporter, a != b);
|
|
|
|
a.reset();
|
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
|
|
|
a.lineTo(1, 1);
|
|
|
|
b.lineTo(1, 2);
|
|
|
|
REPORTER_ASSERT(reporter, a != b);
|
|
|
|
a.reset();
|
|
|
|
a.lineTo(1, 2);
|
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
|
|
|
}
|
|
|
|
|
2014-06-24 15:30:15 +00:00
|
|
|
static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
|
2014-09-15 16:26:09 +00:00
|
|
|
bool dumpAsHex, const char* str) {
|
2014-06-24 15:30:15 +00:00
|
|
|
SkDynamicMemoryWStream wStream;
|
2014-09-15 16:26:09 +00:00
|
|
|
path.dump(&wStream, force, dumpAsHex);
|
2014-06-24 15:30:15 +00:00
|
|
|
SkAutoDataUnref data(wStream.copyToData());
|
|
|
|
REPORTER_ASSERT(reporter, data->size() == strlen(str));
|
2014-11-14 17:22:40 +00:00
|
|
|
if (strlen(str) > 0) {
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, data->data() == NULL || !memcmp(data->data(), str, strlen(str)));
|
|
|
|
}
|
2014-06-24 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_dump(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p;
|
2014-09-15 16:26:09 +00:00
|
|
|
compare_dump(reporter, p, false, false, "");
|
|
|
|
compare_dump(reporter, p, true, false, "");
|
2014-06-24 15:30:15 +00:00
|
|
|
p.moveTo(1, 2);
|
|
|
|
p.lineTo(3, 4);
|
2014-09-15 16:26:09 +00:00
|
|
|
compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.lineTo(3, 4);\n");
|
|
|
|
compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.lineTo(3, 4);\n"
|
|
|
|
"path.lineTo(1, 2);\n"
|
|
|
|
"path.close();\n");
|
2014-06-24 15:30:15 +00:00
|
|
|
p.reset();
|
|
|
|
p.moveTo(1, 2);
|
|
|
|
p.quadTo(3, 4, 5, 6);
|
2014-09-15 16:26:09 +00:00
|
|
|
compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.quadTo(3, 4, 5, 6);\n");
|
2014-06-24 15:30:15 +00:00
|
|
|
p.reset();
|
|
|
|
p.moveTo(1, 2);
|
|
|
|
p.conicTo(3, 4, 5, 6, 0.5f);
|
2014-09-15 16:26:09 +00:00
|
|
|
compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.conicTo(3, 4, 5, 6, 0.5f);\n");
|
2014-06-24 15:30:15 +00:00
|
|
|
p.reset();
|
|
|
|
p.moveTo(1, 2);
|
|
|
|
p.cubicTo(3, 4, 5, 6, 7, 8);
|
2014-09-15 16:26:09 +00:00
|
|
|
compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.cubicTo(3, 4, 5, 6, 7, 8);\n");
|
|
|
|
p.reset();
|
|
|
|
p.moveTo(1, 2);
|
|
|
|
p.lineTo(3, 4);
|
2014-10-23 20:08:56 +00:00
|
|
|
compare_dump(reporter, p, false, true,
|
|
|
|
"path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
|
|
|
|
"path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
|
2014-09-15 16:26:09 +00:00
|
|
|
p.reset();
|
|
|
|
p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
|
|
|
|
p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
|
|
|
|
compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
|
|
|
|
"path.lineTo(3, 4);\n");
|
2014-06-24 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
class PathTest_Private {
|
|
|
|
public:
|
|
|
|
static void TestPathTo(skiatest::Reporter* reporter) {
|
|
|
|
SkPath p, q;
|
|
|
|
p.lineTo(4, 4);
|
|
|
|
p.reversePathTo(q);
|
|
|
|
check_path_is_line(reporter, &p, 4, 4);
|
|
|
|
q.moveTo(-4, -4);
|
|
|
|
p.reversePathTo(q);
|
|
|
|
check_path_is_line(reporter, &p, 4, 4);
|
|
|
|
q.lineTo(7, 8);
|
|
|
|
q.conicTo(8, 7, 6, 5, 0.5f);
|
|
|
|
q.quadTo(6, 7, 8, 6);
|
|
|
|
q.cubicTo(5, 6, 7, 8, 7, 5);
|
|
|
|
q.close();
|
|
|
|
p.reversePathTo(q);
|
|
|
|
SkRect reverseExpected = {-4, -4, 8, 8};
|
|
|
|
REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-15 18:00:57 +00:00
|
|
|
DEF_TEST(Paths, reporter) {
|
2014-05-05 16:04:42 +00:00
|
|
|
test_path_crbug364224();
|
|
|
|
|
2013-06-21 15:13:34 +00:00
|
|
|
SkTSize<SkScalar>::Make(3,4);
|
|
|
|
|
|
|
|
SkPath p, empty;
|
|
|
|
SkRect bounds, bounds2;
|
|
|
|
test_empty(reporter, p);
|
2009-03-02 05:36:20 +00:00
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
|
2009-04-02 16:59:40 +00:00
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
// this triggers a code path in SkPath::operator= which is otherwise unexercised
|
|
|
|
SkPath& self = p;
|
|
|
|
p = self;
|
|
|
|
|
|
|
|
// this triggers a code path in SkPath::swap which is otherwise unexercised
|
|
|
|
p.swap(self);
|
|
|
|
|
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.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
|
|
|
|
check_convex_bounds(reporter, p, bounds);
|
2011-09-21 12:29:05 +00:00
|
|
|
// we have quads or cubics
|
2014-12-17 16:21:04 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
2011-02-07 19:39:09 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
p.reset();
|
2013-06-21 15:13:34 +00:00
|
|
|
test_empty(reporter, p);
|
2011-09-21 12:29:05 +00:00
|
|
|
|
2009-06-03 02:35:01 +00:00
|
|
|
p.addOval(bounds);
|
|
|
|
check_convex_bounds(reporter, p, bounds);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
2011-02-07 19:39:09 +00:00
|
|
|
|
2013-06-21 15:13:34 +00:00
|
|
|
p.rewind();
|
|
|
|
test_empty(reporter, p);
|
|
|
|
|
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);
|
2011-09-21 12:29:05 +00:00
|
|
|
// we have only lines
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p.isEmpty());
|
2009-03-02 05:36:20 +00:00
|
|
|
|
2013-06-21 15:13:34 +00:00
|
|
|
REPORTER_ASSERT(reporter, p != empty);
|
|
|
|
REPORTER_ASSERT(reporter, !(p == empty));
|
2009-03-02 05:36:20 +00:00
|
|
|
|
2012-06-07 21:43:15 +00:00
|
|
|
// do getPoints and getVerbs return the right result
|
|
|
|
REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
|
|
|
|
REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
|
2009-03-02 05:36:20 +00:00
|
|
|
SkPoint pts[4];
|
|
|
|
int count = p.getPoints(pts, 4);
|
|
|
|
REPORTER_ASSERT(reporter, count == 4);
|
2012-06-07 21:43:15 +00:00
|
|
|
uint8_t verbs[6];
|
|
|
|
verbs[5] = 0xff;
|
|
|
|
p.getVerbs(verbs, 5);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
|
|
|
|
REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
|
|
|
|
REPORTER_ASSERT(reporter, 0xff == verbs[5]);
|
2009-03-02 05:36:20 +00:00
|
|
|
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
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, p.isRect(NULL));
|
2011-07-26 19:54:45 +00:00
|
|
|
bounds2.setEmpty();
|
2009-03-02 05:36:20 +00:00
|
|
|
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));
|
|
|
|
|
2014-12-29 19:36:39 +00:00
|
|
|
// Test an edge case w.r.t. the bound returned by isRect (i.e., the
|
|
|
|
// path has a trailing moveTo. Please see crbug.com\445368)
|
|
|
|
{
|
|
|
|
SkRect r;
|
|
|
|
p.reset();
|
|
|
|
p.addRect(bounds);
|
|
|
|
REPORTER_ASSERT(reporter, p.isRect(&r));
|
|
|
|
REPORTER_ASSERT(reporter, r == bounds);
|
|
|
|
// add a moveTo outside of our bounds
|
|
|
|
p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
|
|
|
|
REPORTER_ASSERT(reporter, p.isRect(&r));
|
|
|
|
REPORTER_ASSERT(reporter, r == bounds);
|
|
|
|
}
|
|
|
|
|
2013-11-14 16:53:22 +00:00
|
|
|
test_operatorEqual(reporter);
|
2012-05-10 14:05:43 +00:00
|
|
|
test_isLine(reporter);
|
|
|
|
test_isRect(reporter);
|
2015-04-08 15:34:15 +00:00
|
|
|
test_isNestedFillRects(reporter);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
test_zero_length_paths(reporter);
|
2012-01-11 21:03:05 +00:00
|
|
|
test_direction(reporter);
|
2011-05-15 04:08:24 +00:00
|
|
|
test_convexity(reporter);
|
2011-05-15 04:38:34 +00:00
|
|
|
test_convexity2(reporter);
|
2012-11-13 21:51:38 +00:00
|
|
|
test_conservativelyContains(reporter);
|
2011-07-13 17:44:36 +00:00
|
|
|
test_close(reporter);
|
2012-01-04 21:05:51 +00:00
|
|
|
test_segment_masks(reporter);
|
2011-09-21 19:05:12 +00:00
|
|
|
test_flattening(reporter);
|
|
|
|
test_transform(reporter);
|
2011-11-14 19:34:57 +00:00
|
|
|
test_bounds(reporter);
|
2012-01-04 21:05:51 +00:00
|
|
|
test_iter(reporter);
|
|
|
|
test_raw_iter(reporter);
|
2012-04-18 13:29:52 +00:00
|
|
|
test_circle(reporter);
|
|
|
|
test_oval(reporter);
|
2012-05-29 12:03:46 +00:00
|
|
|
test_strokerec(reporter);
|
2012-05-29 19:54:52 +00:00
|
|
|
test_addPoly(reporter);
|
2012-07-26 15:20:36 +00:00
|
|
|
test_isfinite(reporter);
|
2012-08-10 14:10:45 +00:00
|
|
|
test_isfinite_after_transform(reporter);
|
2012-10-18 15:26:12 +00:00
|
|
|
test_arb_round_rect_is_convex(reporter);
|
2012-10-23 16:56:56 +00:00
|
|
|
test_arb_zero_rad_round_rect_is_rect(reporter);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_addrect(reporter);
|
2012-10-24 21:04:04 +00:00
|
|
|
test_addrect_isfinite(reporter);
|
2013-02-27 19:17:41 +00:00
|
|
|
test_tricky_cubic();
|
|
|
|
test_clipped_cubic();
|
|
|
|
test_crbug_170666();
|
2013-04-10 18:44:00 +00:00
|
|
|
test_bad_cubic_crbug229478();
|
2013-05-08 21:08:21 +00:00
|
|
|
test_bad_cubic_crbug234190();
|
2013-10-30 18:57:55 +00:00
|
|
|
test_gen_id(reporter);
|
2013-08-09 19:48:26 +00:00
|
|
|
test_path_close_issue1474(reporter);
|
2013-10-15 15:44:35 +00:00
|
|
|
test_path_to_region(reporter);
|
2013-11-08 15:51:12 +00:00
|
|
|
test_rrect(reporter);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_arc(reporter);
|
|
|
|
test_arcTo(reporter);
|
|
|
|
test_addPath(reporter);
|
2014-02-11 21:16:29 +00:00
|
|
|
test_addPathMode(reporter, false, false);
|
|
|
|
test_addPathMode(reporter, true, false);
|
|
|
|
test_addPathMode(reporter, false, true);
|
|
|
|
test_addPathMode(reporter, true, true);
|
|
|
|
test_extendClosedPath(reporter);
|
|
|
|
test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
|
|
|
|
test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
|
2013-11-14 16:53:22 +00:00
|
|
|
test_conicTo_special_case(reporter);
|
|
|
|
test_get_point(reporter);
|
|
|
|
test_contains(reporter);
|
|
|
|
PathTest_Private::TestPathTo(reporter);
|
2013-12-13 19:36:25 +00:00
|
|
|
PathRefTest_Private::TestPathRef(reporter);
|
2014-06-24 15:30:15 +00:00
|
|
|
test_dump(reporter);
|
2015-03-02 21:02:34 +00:00
|
|
|
test_path_crbug389050(reporter);
|
Fallback to moveTo when unable to find the first tangent in cubicTo
When calling cubicTo(a, b, c) and if the distance between fPrevPt and a
is too small, b is used instead of a to calculate the first tangent,
even if the distance between fPrevPt and b is too small.
In debug mode, this is causing an assertion to fail in
SkPathStroker::preJoinTo() and, in Release, the use of an
unitialized value.
The first patch set is adding a failing test.
The second one add the fix to SkPathStroker::cubicTo()
BUG=skia:2820
R=bsalomon@chromium.org, junov@chromium.org, reed@google.com, caryclark@google.com, bsalomon@google.com
Author: piotaixr@chromium.org
Review URL: https://codereview.chromium.org/460813002
2014-08-26 18:59:04 +00:00
|
|
|
test_path_crbugskia2820(reporter);
|
2015-03-02 18:07:56 +00:00
|
|
|
test_skbug_3469(reporter);
|
2014-12-15 20:28:33 +00:00
|
|
|
test_skbug_3239(reporter);
|
2009-03-02 05:36:20 +00:00
|
|
|
}
|