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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkPathOpsLine.h"
8
9 #if 0 // uncalled
10 bool SkDLine::implicitLine(double* slope, double* axisIntercept) const {
11 SkDVector delta = tangent();
12 bool moreHorizontal = fabs(delta.fX) > fabs(delta.fY);
13 if (moreHorizontal) {
14 *slope = delta.fY / delta.fX;
15 *axisIntercept = fPts[0].fY - *slope * fPts[0].fX;
16 } else {
17 *slope = delta.fX / delta.fY;
18 *axisIntercept = fPts[0].fX - *slope * fPts[0].fY;
19 }
20 return moreHorizontal;
21 }
22 #endif
23
24 #if 0 // uncalled
25 int SkDLine::reduceOrder(SkDLine* reduced) const {
26 reduced->fPts[0] = fPts[0];
27 int different = fPts[0] != fPts[1];
28 reduced->fPts[1] = fPts[different];
29 return 1 + different;
30 }
31 #endif
32
33 SkDLine SkDLine::subDivide(double t1, double t2) const {
34 SkDVector delta = tangent();
35 SkDLine dst = {{{
36 fPts[0].fX - t1 * delta.fX, fPts[0].fY - t1 * delta.fY}, {
37 fPts[0].fX - t2 * delta.fX, fPts[0].fY - t2 * delta.fY}}};
38 return dst;
39 }
40
41 // may have this below somewhere else already:
42 // copying here because I thought it was clever
43
44 // Copyright 2001, softSurfer (www.softsurfer.com)
45 // This code may be freely used and modified for any purpose
46 // providing that this copyright notice is included with it.
47 // SoftSurfer makes no warranty for this code, and cannot be held
48 // liable for any real or imagined damage resulting from its use.
49 // Users of this code must verify correctness for their application.
50
51 // Assume that a class is already given for the object:
52 // Point with coordinates {float x, y;}
53 //===================================================================
54
55 // isLeft(): tests if a point is Left|On|Right of an infinite line.
56 // Input: three points P0, P1, and P2
57 // Return: >0 for P2 left of the line through P0 and P1
58 // =0 for P2 on the line
59 // <0 for P2 right of the line
60 // See: the January 2001 Algorithm on Area of Triangles
61 // return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y)) ;
62 double SkDLine::isLeft(const SkDPoint& pt) const {
63 SkDVector p0 = fPts[1] - fPts[0];
64 SkDVector p2 = pt - fPts[0];
65 return p0.cross(p2);
66 }
67
68 #if 0 // uncalled
69 double SkDLine::tAt(const SkDPoint& pt) const {
70 SkDVector dxy = fPts[1] - fPts[0];
71 if (fabs(dxy.fX) > fabs(dxy.fY)) {
72 if (approximately_zero(dxy.fX)) {
73 return 0;
74 }
75 return (pt.fX - fPts[0].fX) / dxy.fX;
76 }
77 if (approximately_zero(dxy.fY)) {
78 return 0;
79 }
80 return (pt.fY - fPts[0].fY) / dxy.fY;
81 }
82 #endif
83
84 SkDPoint SkDLine::xyAtT(double t) const {
85 double one_t = 1 - t;
86 SkDPoint result = { one_t * fPts[0].fX + t * fPts[1].fX, one_t * fPts[0].fY + t * fPts[1].fY };
87 return result;
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698