Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Unified Diff: src/pathops/SkPathOpsLine.cpp

Issue 12827020: Add base types for path ops (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pathops/SkPathOpsLine.cpp
===================================================================
--- src/pathops/SkPathOpsLine.cpp (revision 0)
+++ src/pathops/SkPathOpsLine.cpp (revision 0)
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsLine.h"
+
+#if 0 // uncalled
+bool SkDLine::implicitLine(double* slope, double* axisIntercept) const {
+ SkDVector delta = tangent();
+ bool moreHorizontal = fabs(delta.fX) > fabs(delta.fY);
+ if (moreHorizontal) {
+ *slope = delta.fY / delta.fX;
+ *axisIntercept = fPts[0].fY - *slope * fPts[0].fX;
+ } else {
+ *slope = delta.fX / delta.fY;
+ *axisIntercept = fPts[0].fX - *slope * fPts[0].fY;
+ }
+ return moreHorizontal;
+}
+#endif
+
+#if 0 // uncalled
+int SkDLine::reduceOrder(SkDLine* reduced) const {
+ reduced->fPts[0] = fPts[0];
+ int different = fPts[0] != fPts[1];
+ reduced->fPts[1] = fPts[different];
+ return 1 + different;
+}
+#endif
+
+SkDLine SkDLine::subDivide(double t1, double t2) const {
+ SkDVector delta = tangent();
+ SkDLine dst = {{{
+ fPts[0].fX - t1 * delta.fX, fPts[0].fY - t1 * delta.fY}, {
+ fPts[0].fX - t2 * delta.fX, fPts[0].fY - t2 * delta.fY}}};
+ return dst;
+}
+
+// may have this below somewhere else already:
+// copying here because I thought it was clever
+
+// Copyright 2001, softSurfer (www.softsurfer.com)
+// This code may be freely used and modified for any purpose
+// providing that this copyright notice is included with it.
+// SoftSurfer makes no warranty for this code, and cannot be held
+// liable for any real or imagined damage resulting from its use.
+// Users of this code must verify correctness for their application.
+
+// Assume that a class is already given for the object:
+// Point with coordinates {float x, y;}
+//===================================================================
+
+// isLeft(): tests if a point is Left|On|Right of an infinite line.
+// Input: three points P0, P1, and P2
+// Return: >0 for P2 left of the line through P0 and P1
+// =0 for P2 on the line
+// <0 for P2 right of the line
+// See: the January 2001 Algorithm on Area of Triangles
+// return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y));
+double SkDLine::isLeft(const SkDPoint& pt) const {
+ SkDVector p0 = fPts[1] - fPts[0];
+ SkDVector p2 = pt - fPts[0];
+ return p0.cross(p2);
+}
+
+#if 0 // uncalled
+double SkDLine::tAt(const SkDPoint& pt) const {
+ SkDVector dxy = fPts[1] - fPts[0];
+ if (fabs(dxy.fX) > fabs(dxy.fY)) {
+ if (approximately_zero(dxy.fX)) {
+ return 0;
+ }
+ return (pt.fX - fPts[0].fX) / dxy.fX;
+ }
+ if (approximately_zero(dxy.fY)) {
+ return 0;
+ }
+ return (pt.fY - fPts[0].fY) / dxy.fY;
+}
+#endif
+
+SkDPoint SkDLine::xyAtT(double t) const {
+ double one_t = 1 - t;
+ SkDPoint result = { one_t * fPts[0].fX + t * fPts[1].fX, one_t * fPts[0].fY + t * fPts[1].fY };
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698