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

Side by Side Diff: src/pathops/SkLineParameters.h

Issue 15338003: path ops -- rewrite angle sort (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « src/pathops/SkIntersections.cpp ('k') | src/pathops/SkOpAngle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkPathOpsCubic.h" 7 #include "SkPathOpsCubic.h"
8 #include "SkPathOpsLine.h" 8 #include "SkPathOpsLine.h"
9 #include "SkPathOpsQuad.h" 9 #include "SkPathOpsQuad.h"
10 10
11 // Sources 11 // Sources
12 // computer-aided design - volume 22 number 9 november 1990 pp 538 - 549 12 // computer-aided design - volume 22 number 9 november 1990 pp 538 - 549
13 // online at http://cagd.cs.byu.edu/~tom/papers/bezclip.pdf 13 // online at http://cagd.cs.byu.edu/~tom/papers/bezclip.pdf
14 14
15 // This turns a line segment into a parameterized line, of the form 15 // This turns a line segment into a parameterized line, of the form
16 // ax + by + c = 0 16 // ax + by + c = 0
17 // When a^2 + b^2 == 1, the line is normalized. 17 // When a^2 + b^2 == 1, the line is normalized.
18 // The distance to the line for (x, y) is d(x,y) = ax + by + c 18 // The distance to the line for (x, y) is d(x,y) = ax + by + c
19 // 19 //
20 // Note that the distances below are not necessarily normalized. To get the true 20 // Note that the distances below are not necessarily normalized. To get the true
21 // distance, it's necessary to either call normalize() after xxxEndPoints(), or 21 // distance, it's necessary to either call normalize() after xxxEndPoints(), or
22 // divide the result of xxxDistance() by sqrt(normalSquared()) 22 // divide the result of xxxDistance() by sqrt(normalSquared())
23 23
24 class SkLineParameters { 24 class SkLineParameters {
25 public: 25 public:
26 void cubicEndPoints(const SkDCubic& pts) { 26 void cubicEndPoints(const SkDCubic& pts) {
27 cubicEndPoints(pts, 0, 3); 27 cubicEndPoints(pts, 0, 1);
28 if (dx() == 0 && dy() == 0) {
29 cubicEndPoints(pts, 0, 2);
30 if (dx() == 0 && dy() == 0) {
31 cubicEndPoints(pts, 0, 3);
32 }
33 }
28 } 34 }
29 35
30 void cubicEndPoints(const SkDCubic& pts, int s, int e) { 36 void cubicEndPoints(const SkDCubic& pts, int s, int e) {
31 a = approximately_pin(pts[s].fY - pts[e].fY); 37 a = pts[s].fY - pts[e].fY;
32 b = approximately_pin(pts[e].fX - pts[s].fX); 38 b = pts[e].fX - pts[s].fX;
33 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY; 39 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY;
34 } 40 }
35 41
36 void lineEndPoints(const SkDLine& pts) { 42 void lineEndPoints(const SkDLine& pts) {
37 a = approximately_pin(pts[0].fY - pts[1].fY); 43 a = pts[0].fY - pts[1].fY;
38 b = approximately_pin(pts[1].fX - pts[0].fX); 44 b = pts[1].fX - pts[0].fX;
39 c = pts[0].fX * pts[1].fY - pts[1].fX * pts[0].fY; 45 c = pts[0].fX * pts[1].fY - pts[1].fX * pts[0].fY;
40 } 46 }
41 47
42 void quadEndPoints(const SkDQuad& pts) { 48 void quadEndPoints(const SkDQuad& pts) {
43 quadEndPoints(pts, 0, 2); 49 quadEndPoints(pts, 0, 1);
50 if (dx() == 0 && dy() == 0) {
51 quadEndPoints(pts, 0, 2);
52 }
44 } 53 }
45 54
46 void quadEndPoints(const SkDQuad& pts, int s, int e) { 55 void quadEndPoints(const SkDQuad& pts, int s, int e) {
47 a = approximately_pin(pts[s].fY - pts[e].fY); 56 a = pts[s].fY - pts[e].fY;
48 b = approximately_pin(pts[e].fX - pts[s].fX); 57 b = pts[e].fX - pts[s].fX;
49 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY; 58 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY;
50 } 59 }
51 60
52 double normalSquared() const { 61 double normalSquared() const {
53 return a * a + b * b; 62 return a * a + b * b;
54 } 63 }
55 64
56 bool normalize() { 65 bool normalize() {
57 double normal = sqrt(normalSquared()); 66 double normal = sqrt(normalSquared());
58 if (approximately_zero(normal)) { 67 if (approximately_zero(normal)) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 110
102 double dy() const { 111 double dy() const {
103 return -a; 112 return -a;
104 } 113 }
105 114
106 private: 115 private:
107 double a; 116 double a;
108 double b; 117 double b;
109 double c; 118 double c;
110 }; 119 };
OLDNEW
« no previous file with comments | « src/pathops/SkIntersections.cpp ('k') | src/pathops/SkOpAngle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698