| OLD | NEW |
| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 void cubicEndPoints(const SkDCubic& pts, int s, int e) { | 36 void cubicEndPoints(const SkDCubic& pts, int s, int e) { |
| 37 a = pts[s].fY - pts[e].fY; | 37 a = pts[s].fY - pts[e].fY; |
| 38 b = pts[e].fX - pts[s].fX; | 38 b = pts[e].fX - pts[s].fX; |
| 39 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; |
| 40 } | 40 } |
| 41 | 41 |
| 42 double cubicPart(const SkDCubic& part) { |
| 43 cubicEndPoints(part); |
| 44 if (part[0] == part[1] || ((const SkDLine& ) part[0]).nearRay(part[2]))
{ |
| 45 return pointDistance(part[3]); |
| 46 } |
| 47 return pointDistance(part[2]); |
| 48 } |
| 49 |
| 42 void lineEndPoints(const SkDLine& pts) { | 50 void lineEndPoints(const SkDLine& pts) { |
| 43 a = pts[0].fY - pts[1].fY; | 51 a = pts[0].fY - pts[1].fY; |
| 44 b = pts[1].fX - pts[0].fX; | 52 b = pts[1].fX - pts[0].fX; |
| 45 c = pts[0].fX * pts[1].fY - pts[1].fX * pts[0].fY; | 53 c = pts[0].fX * pts[1].fY - pts[1].fX * pts[0].fY; |
| 46 } | 54 } |
| 47 | 55 |
| 48 void quadEndPoints(const SkDQuad& pts) { | 56 void quadEndPoints(const SkDQuad& pts) { |
| 49 quadEndPoints(pts, 0, 1); | 57 quadEndPoints(pts, 0, 1); |
| 50 if (dx() == 0 && dy() == 0) { | 58 if (dx() == 0 && dy() == 0) { |
| 51 quadEndPoints(pts, 0, 2); | 59 quadEndPoints(pts, 0, 2); |
| 52 } | 60 } |
| 53 } | 61 } |
| 54 | 62 |
| 55 void quadEndPoints(const SkDQuad& pts, int s, int e) { | 63 void quadEndPoints(const SkDQuad& pts, int s, int e) { |
| 56 a = pts[s].fY - pts[e].fY; | 64 a = pts[s].fY - pts[e].fY; |
| 57 b = pts[e].fX - pts[s].fX; | 65 b = pts[e].fX - pts[s].fX; |
| 58 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY; | 66 c = pts[s].fX * pts[e].fY - pts[e].fX * pts[s].fY; |
| 59 } | 67 } |
| 60 | 68 |
| 69 double quadPart(const SkDQuad& part) { |
| 70 quadEndPoints(part); |
| 71 return pointDistance(part[2]); |
| 72 } |
| 73 |
| 61 double normalSquared() const { | 74 double normalSquared() const { |
| 62 return a * a + b * b; | 75 return a * a + b * b; |
| 63 } | 76 } |
| 64 | 77 |
| 65 bool normalize() { | 78 bool normalize() { |
| 66 double normal = sqrt(normalSquared()); | 79 double normal = sqrt(normalSquared()); |
| 67 if (approximately_zero(normal)) { | 80 if (approximately_zero(normal)) { |
| 68 a = b = c = 0; | 81 a = b = c = 0; |
| 69 return false; | 82 return false; |
| 70 } | 83 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 123 |
| 111 double dy() const { | 124 double dy() const { |
| 112 return -a; | 125 return -a; |
| 113 } | 126 } |
| 114 | 127 |
| 115 private: | 128 private: |
| 116 double a; | 129 double a; |
| 117 double b; | 130 double b; |
| 118 double c; | 131 double c; |
| 119 }; | 132 }; |
| OLD | NEW |