Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/pathops/SkPathOpsCubic.h"
|
|
|
|
#include "src/pathops/SkPathOpsLine.h"
|
|
|
|
#include "src/pathops/SkPathOpsQuad.h"
|
|
|
|
#include "src/pathops/SkPathOpsRect.h"
|
|
|
|
#include "tests/PathOpsTestCommon.h"
|
|
|
|
#include "tests/Test.h"
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
|
2016-10-20 15:32:18 +00:00
|
|
|
static const QuadPts quadTests[] = {
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
{{{1, 1}, {2, 1}, {0, 2}}},
|
|
|
|
{{{0, 0}, {1, 1}, {3, 1}}},
|
|
|
|
{{{2, 0}, {1, 1}, {2, 2}}},
|
|
|
|
{{{4, 0}, {0, 1}, {4, 2}}},
|
|
|
|
{{{0, 0}, {0, 1}, {1, 1}}},
|
|
|
|
};
|
|
|
|
|
2016-10-20 15:32:18 +00:00
|
|
|
static const CubicPts cubicTests[] = {
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
{{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
|
|
|
|
{{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
|
|
|
|
{{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
|
|
|
|
};
|
|
|
|
|
2013-04-15 19:13:59 +00:00
|
|
|
static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
|
|
|
|
static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
|
2015-03-26 14:52:43 +00:00
|
|
|
static void setRawBounds(const SkDQuad& quad, SkDRect* rect) {
|
|
|
|
rect->set(quad[0]);
|
|
|
|
rect->add(quad[1]);
|
|
|
|
rect->add(quad[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) {
|
|
|
|
rect->set(cubic[0]);
|
|
|
|
rect->add(cubic[1]);
|
|
|
|
rect->add(cubic[2]);
|
|
|
|
rect->add(cubic[3]);
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsDRect, reporter) {
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
size_t index;
|
|
|
|
SkDRect rect, rect2;
|
|
|
|
for (index = 0; index < quadTests_count; ++index) {
|
2016-10-20 15:32:18 +00:00
|
|
|
const QuadPts& q = quadTests[index];
|
|
|
|
SkDQuad quad;
|
|
|
|
quad.debugSet(q.fPts);
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidQuad(quad));
|
2015-03-26 14:52:43 +00:00
|
|
|
setRawBounds(quad, &rect);
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
rect2.setBounds(quad);
|
2015-03-26 14:52:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rect.intersects(rect2));
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
// FIXME: add a recursive box subdivision method to verify that tight bounds is correct
|
|
|
|
SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
|
|
|
|
REPORTER_ASSERT(reporter, rect.contains(leftTop));
|
|
|
|
SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
|
|
|
|
REPORTER_ASSERT(reporter, rect.contains(rightBottom));
|
|
|
|
}
|
|
|
|
for (index = 0; index < cubicTests_count; ++index) {
|
2016-10-20 15:32:18 +00:00
|
|
|
const CubicPts& c = cubicTests[index];
|
|
|
|
SkDCubic cubic;
|
|
|
|
cubic.debugSet(c.fPts);
|
2013-07-16 16:11:16 +00:00
|
|
|
SkASSERT(ValidCubic(cubic));
|
2015-03-26 14:52:43 +00:00
|
|
|
setRawBounds(cubic, &rect);
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
rect2.setBounds(cubic);
|
2015-03-26 14:52:43 +00:00
|
|
|
REPORTER_ASSERT(reporter, rect.intersects(rect2));
|
Add base types for path ops
Paths contain lines, quads, and cubics, which are
collectively curves.
To work with path intersections, intermediary curves
are constructed. For now, those intermediates use
doubles to guarantee sufficient precision.
The DVector, DPoint, DLine, DQuad, and DCubic
structs encapsulate these intermediate curves.
The DRect and DTriangle structs are created to
describe intersectable areas of interest.
The Bounds struct inherits from SkRect to create
a SkScalar-based rectangle that intersects shared
edges.
This also includes common math equalities and
debugging that the remainder of path ops builds on,
as well as a temporary top-level interface in
include/pathops/SkPathOps.h.
Review URL: https://codereview.chromium.org/12827020
git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-04-08 11:47:37 +00:00
|
|
|
// FIXME: add a recursive box subdivision method to verify that tight bounds is correct
|
|
|
|
SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
|
|
|
|
REPORTER_ASSERT(reporter, rect.contains(leftTop));
|
|
|
|
SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
|
|
|
|
REPORTER_ASSERT(reporter, rect.contains(rightBottom));
|
|
|
|
}
|
|
|
|
}
|