aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PathOpsTestCommon.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-03-24 13:55:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-24 13:55:33 -0700
commit0dc4dd6dda9a7912f696b46d9c02155ec1d1ba5f (patch)
tree994c85a8e418986415175ddccc71adf924df3846 /tests/PathOpsTestCommon.cpp
parent82dec0e16ae10026194ce45b67af931700510450 (diff)
Revert of pathops version two (patchset #16 id:150001 of https://codereview.chromium.org/1002693002/)
Reason for revert: ASAN investigation Original issue's description: > pathops version two > > R=reed@google.com > > marked 'no commit' to attempt to get trybots to run > > TBR=reed@google.com > > Committed: https://skia.googlesource.com/skia/+/ccec0f958ffc71a9986d236bc2eb335cb2111119 TBR=caryclark@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1029993002
Diffstat (limited to 'tests/PathOpsTestCommon.cpp')
-rw-r--r--tests/PathOpsTestCommon.cpp131
1 files changed, 11 insertions, 120 deletions
diff --git a/tests/PathOpsTestCommon.cpp b/tests/PathOpsTestCommon.cpp
index f1cba8ed8b..60a12ee56e 100644
--- a/tests/PathOpsTestCommon.cpp
+++ b/tests/PathOpsTestCommon.cpp
@@ -9,129 +9,11 @@
#include "SkPathOpsCubic.h"
#include "SkPathOpsLine.h"
#include "SkPathOpsQuad.h"
-#include "SkReduceOrder.h"
-#include "SkTSort.h"
-
-static double calc_t_div(const SkDCubic& cubic, double precision, double start) {
- const double adjust = sqrt(3.) / 36;
- SkDCubic sub;
- const SkDCubic* cPtr;
- if (start == 0) {
- cPtr = &cubic;
- } else {
- // OPTIMIZE: special-case half-split ?
- sub = cubic.subDivide(start, 1);
- cPtr = &sub;
- }
- const SkDCubic& c = *cPtr;
- double dx = c[3].fX - 3 * (c[2].fX - c[1].fX) - c[0].fX;
- double dy = c[3].fY - 3 * (c[2].fY - c[1].fY) - c[0].fY;
- double dist = sqrt(dx * dx + dy * dy);
- double tDiv3 = precision / (adjust * dist);
- double t = SkDCubeRoot(tDiv3);
- if (start > 0) {
- t = start + (1 - start) * t;
- }
- return t;
-}
-
-static bool add_simple_ts(const SkDCubic& cubic, double precision, SkTArray<double, true>* ts) {
- double tDiv = calc_t_div(cubic, precision, 0);
- if (tDiv >= 1) {
- return true;
- }
- if (tDiv >= 0.5) {
- ts->push_back(0.5);
- return true;
- }
- return false;
-}
-
-static void addTs(const SkDCubic& cubic, double precision, double start, double end,
- SkTArray<double, true>* ts) {
- double tDiv = calc_t_div(cubic, precision, 0);
- double parts = ceil(1.0 / tDiv);
- for (double index = 0; index < parts; ++index) {
- double newT = start + (index / parts) * (end - start);
- if (newT > 0 && newT < 1) {
- ts->push_back(newT);
- }
- }
-}
-
-static void toQuadraticTs(const SkDCubic* cubic, double precision, SkTArray<double, true>* ts) {
- SkReduceOrder reducer;
- int order = reducer.reduce(*cubic, SkReduceOrder::kAllow_Quadratics);
- if (order < 3) {
- return;
- }
- double inflectT[5];
- int inflections = cubic->findInflections(inflectT);
- SkASSERT(inflections <= 2);
- if (!cubic->endsAreExtremaInXOrY()) {
- inflections += cubic->findMaxCurvature(&inflectT[inflections]);
- SkASSERT(inflections <= 5);
- }
- SkTQSort<double>(inflectT, &inflectT[inflections - 1]);
- // OPTIMIZATION: is this filtering common enough that it needs to be pulled out into its
- // own subroutine?
- while (inflections && approximately_less_than_zero(inflectT[0])) {
- memmove(inflectT, &inflectT[1], sizeof(inflectT[0]) * --inflections);
- }
- int start = 0;
- int next = 1;
- while (next < inflections) {
- if (!approximately_equal(inflectT[start], inflectT[next])) {
- ++start;
- ++next;
- continue;
- }
- memmove(&inflectT[start], &inflectT[next], sizeof(inflectT[0]) * (--inflections - start));
- }
-
- while (inflections && approximately_greater_than_one(inflectT[inflections - 1])) {
- --inflections;
- }
- SkDCubicPair pair;
- if (inflections == 1) {
- pair = cubic->chopAt(inflectT[0]);
- int orderP1 = reducer.reduce(pair.first(), SkReduceOrder::kNo_Quadratics);
- if (orderP1 < 2) {
- --inflections;
- } else {
- int orderP2 = reducer.reduce(pair.second(), SkReduceOrder::kNo_Quadratics);
- if (orderP2 < 2) {
- --inflections;
- }
- }
- }
- if (inflections == 0 && add_simple_ts(*cubic, precision, ts)) {
- return;
- }
- if (inflections == 1) {
- pair = cubic->chopAt(inflectT[0]);
- addTs(pair.first(), precision, 0, inflectT[0], ts);
- addTs(pair.second(), precision, inflectT[0], 1, ts);
- return;
- }
- if (inflections > 1) {
- SkDCubic part = cubic->subDivide(0, inflectT[0]);
- addTs(part, precision, 0, inflectT[0], ts);
- int last = inflections - 1;
- for (int idx = 0; idx < last; ++idx) {
- part = cubic->subDivide(inflectT[idx], inflectT[idx + 1]);
- addTs(part, precision, inflectT[idx], inflectT[idx + 1], ts);
- }
- part = cubic->subDivide(inflectT[last], 1);
- addTs(part, precision, inflectT[last], 1, ts);
- return;
- }
- addTs(*cubic, precision, 0, 1, ts);
-}
+#include "SkPathOpsTriangle.h"
void CubicToQuads(const SkDCubic& cubic, double precision, SkTArray<SkDQuad, true>& quads) {
SkTArray<double, true> ts;
- toQuadraticTs(&cubic, precision, &ts);
+ cubic.toQuadraticTs(precision, &ts);
if (ts.count() <= 0) {
SkDQuad quad = cubic.toQuad();
quads.push_back(quad);
@@ -298,6 +180,15 @@ bool ValidQuad(const SkDQuad& quad) {
return true;
}
+bool ValidTriangle(const SkDTriangle& triangle) {
+ for (int index = 0; index < 3; ++index) {
+ if (!ValidPoint(triangle.fPts[index])) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool ValidVector(const SkDVector& v) {
if (SkDoubleIsNaN(v.fX)) {
return false;