aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkInsetConvexPolygon.h
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2017-04-11 15:29:14 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-11 20:26:46 +0000
commitda96550d3941cb794a799c73506a1c5b695c70a1 (patch)
tree3123707b3e7d82398de0ebb9f75466906a2e6928 /src/utils/SkInsetConvexPolygon.h
parent1119dc366e15ef737d05d3a087410ea40c508101 (diff)
Add perspective shadows
Bug: skia: Change-Id: I1972f85f593828c982ea08143e1ed7eb70345eaa Reviewed-on: https://skia-review.googlesource.com/10296 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/utils/SkInsetConvexPolygon.h')
-rwxr-xr-xsrc/utils/SkInsetConvexPolygon.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/utils/SkInsetConvexPolygon.h b/src/utils/SkInsetConvexPolygon.h
index 3ab7558a25..1d5a19c176 100755
--- a/src/utils/SkInsetConvexPolygon.h
+++ b/src/utils/SkInsetConvexPolygon.h
@@ -8,20 +8,49 @@
#ifndef SkInsetConvexPolygon_DEFINED
#define SkInsetConvexPolygon_DEFINED
+#include <functional>
+
#include "SkTDArray.h"
#include "SkPoint.h"
- /**
+/**
* Generates a polygon that is inset a given distance from the boundary of a given convex polygon.
*
* @param inputPolygonVerts Array of points representing the vertices of the original polygon.
* It should be convex and have no coincident points.
* @param inputPolygonSize Number of vertices in the original polygon.
- * @param insetDistance How far we wish to inset the polygon. This should be a positive value.
+ * @param insetDistanceFunc How far we wish to inset the polygon for a given index in the array.
+ * This should return a positive value.
* @param insetPolygon The resulting inset polygon, if any.
* @return true if an inset polygon exists, false otherwise.
*/
bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
- SkScalar insetDistance, SkTDArray<SkPoint>* insetPolygon);
+ std::function<SkScalar(int index)> insetDistanceFunc,
+ SkTDArray<SkPoint>* insetPolygon);
+
+inline bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
+ SkScalar inset,
+ SkTDArray<SkPoint>* insetPolygon) {
+ return SkInsetConvexPolygon(inputPolygonVerts, inputPolygonSize,
+ [inset](int) { return inset; },
+ insetPolygon);
+}
+
+/**
+ * Offset a segment by the given distance at each point.
+ * Uses the outer tangents of two circles centered on each endpoint.
+ * See: https://en.wikipedia.org/wiki/Tangent_lines_to_circles
+ *
+ * @param p0 First endpoint.
+ * @param p1 Second endpoint.
+ * @param d0 Offset distance from first endpoint.
+ * @param d1 Offset distance from second endpoint.
+ * @param side Indicates whether we want to offset to the left (1) or right (-1) side of segment.
+ * @param offset0 First endpoint of offset segment.
+ * @param offset1 Second endpoint of offset segment.
+ * @return true if an offset segment exists, false otherwise.
+ */
+bool SkOffsetSegment(const SkPoint& p0, const SkPoint& p1, SkScalar d0, SkScalar d1,
+ int side, SkPoint* offset0, SkPoint* offset1);
#endif