caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | #ifndef SkPathOpsCurve_DEFINE |
| 8 | #define SkPathOpsCurve_DEFINE |
| 9 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 10 | #include "SkIntersections.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 11 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 12 | #ifndef SK_RELEASE |
| 13 | #include "SkPath.h" |
| 14 | #endif |
| 15 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 16 | struct SkPathOpsBounds; |
| 17 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 18 | struct SkOpCurve { |
| 19 | SkPoint fPts[4]; |
| 20 | SkScalar fWeight; |
| 21 | SkDEBUGCODE(SkPath::Verb fVerb); |
| 22 | |
| 23 | const SkPoint& operator[](int n) const { |
| 24 | SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
| 25 | return fPts[n]; |
| 26 | } |
| 27 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 28 | void dump() const; |
| 29 | |
| 30 | void set(const SkDQuad& quad) { |
| 31 | for (int index = 0; index < SkDQuad::kPointCount; ++index) { |
| 32 | fPts[index] = quad[index].asSkPoint(); |
| 33 | } |
| 34 | SkDEBUGCODE(fWeight = 1); |
| 35 | SkDEBUGCODE(fVerb = SkPath::kQuad_Verb); |
| 36 | } |
| 37 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 38 | void set(const SkDCubic& cubic) { |
| 39 | for (int index = 0; index < SkDCubic::kPointCount; ++index) { |
| 40 | fPts[index] = cubic[index].asSkPoint(); |
| 41 | } |
| 42 | SkDEBUGCODE(fWeight = 1); |
| 43 | SkDEBUGCODE(fVerb = SkPath::kCubic_Verb); |
| 44 | } |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 45 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct SkDCurve { |
| 49 | union { |
| 50 | SkDLine fLine; |
| 51 | SkDQuad fQuad; |
| 52 | SkDConic fConic; |
| 53 | SkDCubic fCubic; |
| 54 | }; |
| 55 | SkDEBUGCODE(SkPath::Verb fVerb); |
| 56 | |
| 57 | const SkDPoint& operator[](int n) const { |
| 58 | SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
| 59 | return fCubic[n]; |
| 60 | } |
| 61 | |
| 62 | SkDPoint& operator[](int n) { |
| 63 | SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
| 64 | return fCubic[n]; |
| 65 | } |
| 66 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 67 | SkDPoint conicTop(const SkPoint curve[3], SkScalar curveWeight, |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 68 | double s, double e, double* topT); |
| 69 | SkDPoint cubicTop(const SkPoint curve[4], SkScalar , double s, double e, double* topT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 70 | void dump() const; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 71 | void dumpID(int ) const; |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 72 | SkDPoint lineTop(const SkPoint[2], SkScalar , double , double , double* topT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 73 | double nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint& opp) const; |
| 74 | void offset(SkPath::Verb verb, const SkDVector& ); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 75 | SkDPoint quadTop(const SkPoint curve[3], SkScalar , double s, double e, double* topT); |
| 76 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 77 | void setConicBounds(const SkPoint curve[3], SkScalar curveWeight, |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 78 | double s, double e, SkPathOpsBounds* ); |
| 79 | void setCubicBounds(const SkPoint curve[4], SkScalar , |
| 80 | double s, double e, SkPathOpsBounds* ); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 81 | void setQuadBounds(const SkPoint curve[3], SkScalar , |
| 82 | double s, double e, SkPathOpsBounds*); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 85 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 86 | extern SkDPoint (SkDCurve::* const Top[])(const SkPoint curve[], SkScalar cWeight, |
| 87 | double tStart, double tEnd, double* topT); |
| 88 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 89 | static SkDPoint dline_xy_at_t(const SkPoint a[2], SkScalar , double t) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 90 | SkDLine line; |
| 91 | line.set(a); |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 92 | return line.ptAtT(t); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 93 | } |
| 94 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 95 | static SkDPoint dquad_xy_at_t(const SkPoint a[3], SkScalar , double t) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 96 | SkDQuad quad; |
| 97 | quad.set(a); |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 98 | return quad.ptAtT(t); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 99 | } |
| 100 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 101 | static SkDPoint dconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 102 | SkDConic conic; |
| 103 | conic.set(a, weight); |
| 104 | return conic.ptAtT(t); |
| 105 | } |
| 106 | |
| 107 | static SkDPoint dcubic_xy_at_t(const SkPoint a[4], SkScalar , double t) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 108 | SkDCubic cubic; |
| 109 | cubic.set(a); |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 110 | return cubic.ptAtT(t); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 111 | } |
| 112 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 113 | static SkDPoint (* const CurveDPointAtT[])(const SkPoint[], SkScalar , double ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 114 | nullptr, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 115 | dline_xy_at_t, |
| 116 | dquad_xy_at_t, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 117 | dconic_xy_at_t, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 118 | dcubic_xy_at_t |
| 119 | }; |
| 120 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 121 | static SkDPoint ddline_xy_at_t(const SkDCurve& c, double t) { |
| 122 | return c.fLine.ptAtT(t); |
| 123 | } |
| 124 | |
| 125 | static SkDPoint ddquad_xy_at_t(const SkDCurve& c, double t) { |
| 126 | return c.fQuad.ptAtT(t); |
| 127 | } |
| 128 | |
| 129 | static SkDPoint ddconic_xy_at_t(const SkDCurve& c, double t) { |
| 130 | return c.fConic.ptAtT(t); |
| 131 | } |
| 132 | |
| 133 | static SkDPoint ddcubic_xy_at_t(const SkDCurve& c, double t) { |
| 134 | return c.fCubic.ptAtT(t); |
| 135 | } |
| 136 | |
| 137 | static SkDPoint (* const CurveDDPointAtT[])(const SkDCurve& , double ) = { |
| 138 | nullptr, |
| 139 | ddline_xy_at_t, |
| 140 | ddquad_xy_at_t, |
| 141 | ddconic_xy_at_t, |
| 142 | ddcubic_xy_at_t |
| 143 | }; |
| 144 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 145 | static SkPoint fline_xy_at_t(const SkPoint a[2], SkScalar weight, double t) { |
| 146 | return dline_xy_at_t(a, weight, t).asSkPoint(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 147 | } |
| 148 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 149 | static SkPoint fquad_xy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 150 | return dquad_xy_at_t(a, weight, t).asSkPoint(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 151 | } |
| 152 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 153 | static SkPoint fconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 154 | return dconic_xy_at_t(a, weight, t).asSkPoint(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 155 | } |
| 156 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 157 | static SkPoint fcubic_xy_at_t(const SkPoint a[4], SkScalar weight, double t) { |
| 158 | return dcubic_xy_at_t(a, weight, t).asSkPoint(); |
| 159 | } |
| 160 | |
| 161 | static SkPoint (* const CurvePointAtT[])(const SkPoint[], SkScalar , double ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 162 | nullptr, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 163 | fline_xy_at_t, |
| 164 | fquad_xy_at_t, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 165 | fconic_xy_at_t, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 166 | fcubic_xy_at_t |
| 167 | }; |
| 168 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 169 | static SkDVector dline_dxdy_at_t(const SkPoint a[2], SkScalar , double ) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 170 | SkDLine line; |
| 171 | line.set(a); |
| 172 | return line[1] - line[0]; |
| 173 | } |
| 174 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 175 | static SkDVector dquad_dxdy_at_t(const SkPoint a[3], SkScalar , double t) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 176 | SkDQuad quad; |
| 177 | quad.set(a); |
| 178 | return quad.dxdyAtT(t); |
| 179 | } |
| 180 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 181 | static SkDVector dconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 182 | SkDConic conic; |
| 183 | conic.set(a, weight); |
| 184 | return conic.dxdyAtT(t); |
| 185 | } |
| 186 | |
| 187 | static SkDVector dcubic_dxdy_at_t(const SkPoint a[4], SkScalar , double t) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 188 | SkDCubic cubic; |
| 189 | cubic.set(a); |
| 190 | return cubic.dxdyAtT(t); |
| 191 | } |
| 192 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 193 | static SkDVector (* const CurveDSlopeAtT[])(const SkPoint[], SkScalar , double ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 194 | nullptr, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 195 | dline_dxdy_at_t, |
| 196 | dquad_dxdy_at_t, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 197 | dconic_dxdy_at_t, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 198 | dcubic_dxdy_at_t |
| 199 | }; |
| 200 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 201 | static SkDVector ddline_dxdy_at_t(const SkDCurve& c, double ) { |
| 202 | return c.fLine.fPts[1] - c.fLine.fPts[0]; |
| 203 | } |
| 204 | |
| 205 | static SkDVector ddquad_dxdy_at_t(const SkDCurve& c, double t) { |
| 206 | return c.fQuad.dxdyAtT(t); |
| 207 | } |
| 208 | |
| 209 | static SkDVector ddconic_dxdy_at_t(const SkDCurve& c, double t) { |
| 210 | return c.fConic.dxdyAtT(t); |
| 211 | } |
| 212 | |
| 213 | static SkDVector ddcubic_dxdy_at_t(const SkDCurve& c, double t) { |
| 214 | return c.fCubic.dxdyAtT(t); |
| 215 | } |
| 216 | |
| 217 | static SkDVector (* const CurveDDSlopeAtT[])(const SkDCurve& , double ) = { |
| 218 | nullptr, |
| 219 | ddline_dxdy_at_t, |
| 220 | ddquad_dxdy_at_t, |
| 221 | ddconic_dxdy_at_t, |
| 222 | ddcubic_dxdy_at_t |
| 223 | }; |
| 224 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 225 | static SkVector fline_dxdy_at_t(const SkPoint a[2], SkScalar , double ) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 226 | return a[1] - a[0]; |
| 227 | } |
| 228 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 229 | static SkVector fquad_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 230 | return dquad_dxdy_at_t(a, weight, t).asSkVector(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 231 | } |
| 232 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 233 | static SkVector fconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) { |
| 234 | return dconic_dxdy_at_t(a, weight, t).asSkVector(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 235 | } |
| 236 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 237 | static SkVector fcubic_dxdy_at_t(const SkPoint a[4], SkScalar weight, double t) { |
| 238 | return dcubic_dxdy_at_t(a, weight, t).asSkVector(); |
| 239 | } |
| 240 | |
| 241 | static SkVector (* const CurveSlopeAtT[])(const SkPoint[], SkScalar , double ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 242 | nullptr, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 243 | fline_dxdy_at_t, |
| 244 | fquad_dxdy_at_t, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 245 | fconic_dxdy_at_t, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 246 | fcubic_dxdy_at_t |
| 247 | }; |
| 248 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 249 | static bool line_is_vertical(const SkPoint a[2], SkScalar , double startT, double endT) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 250 | SkDLine line; |
| 251 | line.set(a); |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 252 | SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) }; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 253 | return AlmostEqualUlps(dst[0].fX, dst[1].fX); |
| 254 | } |
| 255 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 256 | static bool quad_is_vertical(const SkPoint a[3], SkScalar , double startT, double endT) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 257 | SkDQuad quad; |
| 258 | quad.set(a); |
| 259 | SkDQuad dst = quad.subDivide(startT, endT); |
| 260 | return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX); |
| 261 | } |
| 262 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 263 | static bool conic_is_vertical(const SkPoint a[3], SkScalar weight, double startT, double endT) { |
| 264 | SkDConic conic; |
| 265 | conic.set(a, weight); |
| 266 | SkDConic dst = conic.subDivide(startT, endT); |
| 267 | return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX); |
| 268 | } |
| 269 | |
| 270 | static bool cubic_is_vertical(const SkPoint a[4], SkScalar , double startT, double endT) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 271 | SkDCubic cubic; |
| 272 | cubic.set(a); |
| 273 | SkDCubic dst = cubic.subDivide(startT, endT); |
| 274 | return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX) |
| 275 | && AlmostEqualUlps(dst[2].fX, dst[3].fX); |
| 276 | } |
| 277 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 278 | static bool (* const CurveIsVertical[])(const SkPoint[], SkScalar , double , double) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 279 | nullptr, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 280 | line_is_vertical, |
| 281 | quad_is_vertical, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 282 | conic_is_vertical, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 283 | cubic_is_vertical |
| 284 | }; |
| 285 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 286 | static void line_intersect_ray(const SkPoint a[2], SkScalar , const SkDLine& ray, |
| 287 | SkIntersections* i) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 288 | SkDLine line; |
| 289 | line.set(a); |
| 290 | i->intersectRay(line, ray); |
| 291 | } |
| 292 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 293 | static void quad_intersect_ray(const SkPoint a[3], SkScalar , const SkDLine& ray, |
| 294 | SkIntersections* i) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 295 | SkDQuad quad; |
| 296 | quad.set(a); |
| 297 | i->intersectRay(quad, ray); |
| 298 | } |
| 299 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 300 | static void conic_intersect_ray(const SkPoint a[3], SkScalar weight, const SkDLine& ray, |
| 301 | SkIntersections* i) { |
| 302 | SkDConic conic; |
| 303 | conic.set(a, weight); |
| 304 | i->intersectRay(conic, ray); |
| 305 | } |
| 306 | |
| 307 | static void cubic_intersect_ray(const SkPoint a[4], SkScalar , const SkDLine& ray, |
| 308 | SkIntersections* i) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 309 | SkDCubic cubic; |
| 310 | cubic.set(a); |
| 311 | i->intersectRay(cubic, ray); |
| 312 | } |
| 313 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 314 | static void (* const CurveIntersectRay[])(const SkPoint[] , SkScalar , const SkDLine& , |
| 315 | SkIntersections* ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 316 | nullptr, |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 317 | line_intersect_ray, |
| 318 | quad_intersect_ray, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 319 | conic_intersect_ray, |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 320 | cubic_intersect_ray |
| 321 | }; |
| 322 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 323 | static void dline_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) { |
| 324 | i->intersectRay(c.fLine, ray); |
| 325 | } |
| 326 | |
| 327 | static void dquad_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) { |
| 328 | i->intersectRay(c.fQuad, ray); |
| 329 | } |
| 330 | |
| 331 | static void dconic_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) { |
| 332 | i->intersectRay(c.fConic, ray); |
| 333 | } |
| 334 | |
| 335 | static void dcubic_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) { |
| 336 | i->intersectRay(c.fCubic, ray); |
| 337 | } |
| 338 | |
| 339 | static void (* const CurveDIntersectRay[])(const SkDCurve& , const SkDLine& , SkIntersections* ) = { |
| 340 | nullptr, |
| 341 | dline_intersect_ray, |
| 342 | dquad_intersect_ray, |
| 343 | dconic_intersect_ray, |
| 344 | dcubic_intersect_ray |
| 345 | }; |
| 346 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 347 | static int line_intercept_h(const SkPoint a[2], SkScalar , SkScalar y, double* roots) { |
| 348 | SkDLine line; |
| 349 | roots[0] = SkIntersections::HorizontalIntercept(line.set(a), y); |
| 350 | return between(0, roots[0], 1); |
| 351 | } |
| 352 | |
| 353 | static int line_intercept_v(const SkPoint a[2], SkScalar , SkScalar x, double* roots) { |
| 354 | SkDLine line; |
| 355 | roots[0] = SkIntersections::VerticalIntercept(line.set(a), x); |
| 356 | return between(0, roots[0], 1); |
| 357 | } |
| 358 | |
| 359 | static int quad_intercept_h(const SkPoint a[2], SkScalar , SkScalar y, double* roots) { |
| 360 | SkDQuad quad; |
| 361 | return SkIntersections::HorizontalIntercept(quad.set(a), y, roots); |
| 362 | } |
| 363 | |
| 364 | static int quad_intercept_v(const SkPoint a[2], SkScalar , SkScalar x, double* roots) { |
| 365 | SkDQuad quad; |
| 366 | return SkIntersections::VerticalIntercept(quad.set(a), x, roots); |
| 367 | } |
| 368 | |
| 369 | static int conic_intercept_h(const SkPoint a[2], SkScalar w, SkScalar y, double* roots) { |
| 370 | SkDConic conic; |
| 371 | return SkIntersections::HorizontalIntercept(conic.set(a, w), y, roots); |
| 372 | } |
| 373 | |
| 374 | static int conic_intercept_v(const SkPoint a[2], SkScalar w, SkScalar x, double* roots) { |
| 375 | SkDConic conic; |
| 376 | return SkIntersections::VerticalIntercept(conic.set(a, w), x, roots); |
| 377 | } |
| 378 | |
| 379 | static int cubic_intercept_h(const SkPoint a[3], SkScalar , SkScalar y, double* roots) { |
| 380 | SkDCubic cubic; |
| 381 | return cubic.set(a).horizontalIntersect(y, roots); |
| 382 | } |
| 383 | |
| 384 | static int cubic_intercept_v(const SkPoint a[3], SkScalar , SkScalar x, double* roots) { |
| 385 | SkDCubic cubic; |
| 386 | return cubic.set(a).verticalIntersect(x, roots); |
| 387 | } |
| 388 | |
| 389 | static int (* const CurveIntercept[])(const SkPoint[] , SkScalar , SkScalar , double* ) = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 390 | nullptr, |
| 391 | nullptr, |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 392 | line_intercept_h, |
| 393 | line_intercept_v, |
| 394 | quad_intercept_h, |
| 395 | quad_intercept_v, |
| 396 | conic_intercept_h, |
| 397 | conic_intercept_v, |
| 398 | cubic_intercept_h, |
| 399 | cubic_intercept_v, |
| 400 | }; |
| 401 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 402 | #endif |