From 908cc8071cfe1ab9647b01cc1bf6eabc363676ab Mon Sep 17 00:00:00 2001 From: John Stiles Date: Mon, 27 Jun 2022 17:48:58 -0400 Subject: [PATCH] Revert "experimental alternative isconvex" This reverts commit 64284e14827d8768e54582c0d8c81d0d33594f7c. Reason for revert: unused code Original change's description: > experimental alternative isconvex > > Bug: skia: > Change-Id: I55175a95d37aad9a656cd211fc6c7238bdb7d674 > Reviewed-on: https://skia-review.googlesource.com/c/173361 > Commit-Queue: Mike Reed > Reviewed-by: Mike Reed Change-Id: Ib00acfc0964ecfd2fe01689c0d46d0773d5c5258 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/553588 Commit-Queue: John Stiles Reviewed-by: Michael Ludwig Reviewed-by: Jim Van Verth --- src/utils/SkPolyUtils.cpp | 112 -------------------------------------- src/utils/SkPolyUtils.h | 3 - tests/PolyUtilsTest.cpp | 34 ------------ 3 files changed, 149 deletions(-) diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp index 9f08d10047..08a342a6cc 100644 --- a/src/utils/SkPolyUtils.cpp +++ b/src/utils/SkPolyUtils.cpp @@ -1764,115 +1764,3 @@ bool SkTriangulateSimplePolygon(const SkPoint* polygonVerts, uint16_t* indexMap, return true; } - -/////////// - -static double crs(SkVector a, SkVector b) { - return a.fX * b.fY - a.fY * b.fX; -} - -static int sign(SkScalar v) { - return v < 0 ? -1 : (v > 0); -} - -struct SignTracker { - int fSign; - int fSignChanges; - - void reset() { - fSign = 0; - fSignChanges = 0; - } - - void init(int s) { - SkASSERT(fSignChanges == 0); - SkASSERT(s == 1 || s == -1 || s == 0); - fSign = s; - fSignChanges = 1; - } - - void update(int s) { - if (s) { - if (fSign != s) { - fSignChanges += 1; - fSign = s; - } - } - } -}; - -struct ConvexTracker { - SkVector fFirst, fPrev; - SignTracker fDSign, fCSign; - int fVecCounter; - bool fIsConcave; - - ConvexTracker() { this->reset(); } - - void reset() { - fPrev = {0, 0}; - fDSign.reset(); - fCSign.reset(); - fVecCounter = 0; - fIsConcave = false; - } - - void addVec(SkPoint p1, SkPoint p0) { - this->addVec(p1 - p0); - } - void addVec(SkVector v) { - if (v.fX == 0 && v.fY == 0) { - return; - } - - fVecCounter += 1; - if (fVecCounter == 1) { - fFirst = fPrev = v; - fDSign.update(sign(v.fX)); - return; - } - - SkScalar d = v.fX; - SkScalar c = crs(fPrev, v); - int sign_c; - if (c) { - sign_c = sign(c); - } else { - if (d >= 0) { - sign_c = fCSign.fSign; - } else { - sign_c = -fCSign.fSign; - } - } - - fDSign.update(sign(d)); - fCSign.update(sign_c); - fPrev = v; - - if (fDSign.fSignChanges > 3 || fCSign.fSignChanges > 1) { - fIsConcave = true; - } - } - - void finalCross() { - this->addVec(fFirst); - } -}; - -bool SkIsPolyConvex_experimental(const SkPoint pts[], int count) { - if (count <= 3) { - return true; - } - - ConvexTracker tracker; - - for (int i = 0; i < count - 1; ++i) { - tracker.addVec(pts[i + 1], pts[i]); - if (tracker.fIsConcave) { - return false; - } - } - tracker.addVec(pts[0], pts[count - 1]); - tracker.finalCross(); - return !tracker.fIsConcave; -} diff --git a/src/utils/SkPolyUtils.h b/src/utils/SkPolyUtils.h index 7133d88240..8fdc214511 100644 --- a/src/utils/SkPolyUtils.h +++ b/src/utils/SkPolyUtils.h @@ -110,7 +110,4 @@ bool SkIsConvexPolygon(const SkPoint* polygonVerts, int polygonSize); bool SkTriangulateSimplePolygon(const SkPoint* polygonVerts, uint16_t* indexMap, int polygonSize, SkTDArray* triangleIndices); -// Experiment: doesn't handle really big floats (returns false), always returns true for count <= 3 -bool SkIsPolyConvex_experimental(const SkPoint[], int count); - #endif diff --git a/tests/PolyUtilsTest.cpp b/tests/PolyUtilsTest.cpp index 89459efbb5..5bd96978bc 100644 --- a/tests/PolyUtilsTest.cpp +++ b/tests/PolyUtilsTest.cpp @@ -414,37 +414,3 @@ DEF_TEST(PolyUtils, reporter) { REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), &triangleIndices)); } - -struct PtSet { - const SkPoint* fPts; - int fN; -}; - -DEF_TEST(IsPolyConvex_experimental, r) { - #define PTSET(array) {array, std::size(array)} - - const SkPoint g0[] = { {0, 0}, {10, 0}, {10, 10}, {0, 10} }; - const PtSet convex[] = { PTSET(g0) }; - for (auto& set : convex) { - REPORTER_ASSERT(r, SkIsPolyConvex_experimental(set.fPts, set.fN)); - } - - const SkPoint b0[] = { {0, 0}, {10, 0}, {0, 10}, {10, 10} }; - const SkPoint b1[] = { - {24.8219f, 8.05052f}, - {26.0616f, 24.4895f}, {8.49582f, 16.815f}, - {27.3047f, 7.75211f}, - {21.927f, 27.2051f}, - }; - const SkPoint b2[] = { - {20, 20}, {20, 50}, {80, 50}, {20, 50}, {20, 80}, - }; - const PtSet concave[] = { PTSET(b0), PTSET(b1), PTSET(b2) }; - for (auto& set : concave) { - if (SkIsPolyConvex_experimental(set.fPts, set.fN)) { - REPORTER_ASSERT(r, !SkIsPolyConvex_experimental(set.fPts, set.fN)); - } - } - -} -