Fix missing offsets in simple-polygon-offset-v
A previous change led to some offsets dropping out in this GM. It looks
like using a single offset value for reflex vertex checking isn't quite
the right solution.
Change-Id: If0fe41187e5fd48409a7276c542810a76dc1f6f8
Reviewed-on: https://skia-review.googlesource.com/145525
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp
index b2847b9..0d01660 100644
--- a/src/utils/SkPolyUtils.cpp
+++ b/src/utils/SkPolyUtils.cpp
@@ -486,7 +486,7 @@
///////////////////////////////////////////////////////////////////////////////////////////
// compute the number of points needed for a circular join when offsetting a reflex vertex
-bool SkComputeRadialSteps(const SkVector& v1, const SkVector& v2, SkScalar r,
+bool SkComputeRadialSteps(const SkVector& v1, const SkVector& v2, SkScalar offset,
SkScalar* rotSin, SkScalar* rotCos, int* n) {
const SkScalar kRecipPixelsPerArcSegment = 0.25f;
@@ -500,7 +500,7 @@
}
SkScalar theta = SkScalarATan2(rSin, rCos);
- SkScalar floatSteps = SkScalarAbs(r*theta*kRecipPixelsPerArcSegment);
+ SkScalar floatSteps = SkScalarAbs(offset*theta*kRecipPixelsPerArcSegment);
// limit the number of steps to at most max uint16_t (that's all we can index)
// knock one value off the top to account for rounding
if (floatSteps >= (1 << 16)-1) {
@@ -786,11 +786,12 @@
// build normals
SkAutoSTMalloc<64, SkVector> normal0(inputPolygonSize);
SkAutoSTMalloc<64, SkVector> normal1(inputPolygonSize);
- SkScalar baseOffset = offsetDistanceFunc(inputPolygonVerts[0]);
- SkScalar currOffset = baseOffset;
+ SkAutoSTMalloc<64, SkScalar> offset(inputPolygonSize);
+ SkScalar currOffset = offsetDistanceFunc(inputPolygonVerts[0]);
if (!SkScalarIsFinite(currOffset)) {
return false;
}
+ offset[0] = currOffset;
int numEdges = 0;
for (int currIndex = 0, prevIndex = inputPolygonSize - 1;
currIndex < inputPolygonSize;
@@ -800,13 +801,10 @@
}
int nextIndex = (currIndex + 1) % inputPolygonSize;
SkScalar nextOffset = offsetDistanceFunc(inputPolygonVerts[nextIndex]);
- // all offsets should either inset or outset
- if (currOffset*nextOffset < 0) {
- return false;
- }
if (!SkScalarIsFinite(nextOffset)) {
return false;
}
+ offset[nextIndex] = nextOffset;
if (!compute_offset_vectors(inputPolygonVerts[currIndex], inputPolygonVerts[nextIndex],
currOffset, nextOffset, winding,
&normal0[currIndex], &normal1[nextIndex])) {
@@ -814,12 +812,11 @@
}
if (currIndex > 0) {
// if reflex point, we need to add extra edges
- if (is_reflex_vertex(inputPolygonVerts, winding, baseOffset,
+ if (is_reflex_vertex(inputPolygonVerts, winding, currOffset,
prevIndex, currIndex, nextIndex)) {
SkScalar rotSin, rotCos;
int numSteps;
- if (!SkComputeRadialSteps(normal1[currIndex], normal0[currIndex],
- normal0[currIndex].length(),
+ if (!SkComputeRadialSteps(normal1[currIndex], normal0[currIndex], currOffset,
&rotSin, &rotCos, &numSteps)) {
return false;
}
@@ -830,7 +827,7 @@
currOffset = nextOffset;
}
// finish up the edge counting
- if (is_reflex_vertex(inputPolygonVerts, winding, baseOffset, inputPolygonSize-1, 0, 1)) {
+ if (is_reflex_vertex(inputPolygonVerts, winding, currOffset, inputPolygonSize-1, 0, 1)) {
SkScalar rotSin, rotCos;
int numSteps;
if (!SkComputeRadialSteps(normal1[0], normal0[0], currOffset,
@@ -848,12 +845,12 @@
prevIndex = currIndex, ++currIndex) {
int nextIndex = (currIndex + 1) % inputPolygonSize;
// if reflex point, fill in curve
- if (is_reflex_vertex(inputPolygonVerts, winding, baseOffset,
+ if (is_reflex_vertex(inputPolygonVerts, winding, offset[currIndex],
prevIndex, currIndex, nextIndex)) {
SkScalar rotSin, rotCos;
int numSteps;
SkVector prevNormal = normal1[currIndex];
- if (!SkComputeRadialSteps(prevNormal, normal0[currIndex], normal0[currIndex].length(),
+ if (!SkComputeRadialSteps(prevNormal, normal0[currIndex], offset[currIndex],
&rotSin, &rotCos, &numSteps)) {
return false;
}