| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 7 |
| 8 #ifndef SkGeometry_DEFINED | 8 #ifndef SkGeometry_DEFINED |
| 9 #define SkGeometry_DEFINED | 9 #define SkGeometry_DEFINED |
| 10 | 10 |
| 11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
| 12 | 12 |
| 13 /** An XRay is a half-line that runs from the specific point/origin to | |
| 14 +infinity in the X direction. e.g. XRay(3,5) is the half-line | |
| 15 (3,5)....(infinity, 5) | |
| 16 */ | |
| 17 typedef SkPoint SkXRay; | |
| 18 | |
| 19 /** Given a line segment from pts[0] to pts[1], and an xray, return true if | |
| 20 they intersect. Optional outgoing "ambiguous" argument indicates | |
| 21 whether the answer is ambiguous because the query occurred exactly at | |
| 22 one of the endpoints' y coordinates, indicating that another query y | |
| 23 coordinate is preferred for robustness. | |
| 24 */ | |
| 25 bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2], | |
| 26 bool* ambiguous = NULL); | |
| 27 | |
| 28 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the | 13 /** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the |
| 29 equation. | 14 equation. |
| 30 */ | 15 */ |
| 31 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); | 16 int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]); |
| 32 | 17 |
| 33 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 34 | 19 |
| 35 /** Set pt to the point on the src quadratic specified by t. t must be | 20 /** Set pt to the point on the src quadratic specified by t. t must be |
| 36 0 <= t <= 1.0 | 21 0 <= t <= 1.0 |
| 37 */ | 22 */ |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 /** Return 1 for no chop, 2 for having chopped the cubic at a single | 137 /** Return 1 for no chop, 2 for having chopped the cubic at a single |
| 153 inflection point, 3 for having chopped at 2 inflection points. | 138 inflection point, 3 for having chopped at 2 inflection points. |
| 154 dst will hold the resulting 1, 2, or 3 cubics. | 139 dst will hold the resulting 1, 2, or 3 cubics. |
| 155 */ | 140 */ |
| 156 int SkChopCubicAtInflections(const SkPoint src[4], SkPoint dst[10]); | 141 int SkChopCubicAtInflections(const SkPoint src[4], SkPoint dst[10]); |
| 157 | 142 |
| 158 int SkFindCubicMaxCurvature(const SkPoint src[4], SkScalar tValues[3]); | 143 int SkFindCubicMaxCurvature(const SkPoint src[4], SkScalar tValues[3]); |
| 159 int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13], | 144 int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13], |
| 160 SkScalar tValues[3] = NULL); | 145 SkScalar tValues[3] = NULL); |
| 161 | 146 |
| 162 /** Given a monotonic cubic bezier, determine whether an xray intersects the | |
| 163 cubic. | |
| 164 By definition the cubic is open at the starting point; in other | |
| 165 words, if pt.fY is equivalent to cubic[0].fY, and pt.fX is to the | |
| 166 left of the curve, the line is not considered to cross the curve, | |
| 167 but if it is equal to cubic[3].fY then it is considered to | |
| 168 cross. | |
| 169 Optional outgoing "ambiguous" argument indicates whether the answer is | |
| 170 ambiguous because the query occurred exactly at one of the endpoints' y | |
| 171 coordinates, indicating that another query y coordinate is preferred | |
| 172 for robustness. | |
| 173 */ | |
| 174 bool SkXRayCrossesMonotonicCubic(const SkXRay& pt, const SkPoint cubic[4], | |
| 175 bool* ambiguous = NULL); | |
| 176 | |
| 177 /** Given an arbitrary cubic bezier, return the number of times an xray crosses | |
| 178 the cubic. Valid return values are [0..3] | |
| 179 By definition the cubic is open at the starting point; in other | |
| 180 words, if pt.fY is equivalent to cubic[0].fY, and pt.fX is to the | |
| 181 left of the curve, the line is not considered to cross the curve, | |
| 182 but if it is equal to cubic[3].fY then it is considered to | |
| 183 cross. | |
| 184 Optional outgoing "ambiguous" argument indicates whether the answer is | |
| 185 ambiguous because the query occurred exactly at one of the endpoints' y | |
| 186 coordinates or at a tangent point, indicating that another query y | |
| 187 coordinate is preferred for robustness. | |
| 188 */ | |
| 189 int SkNumXRayCrossingsForCubic(const SkXRay& pt, const SkPoint cubic[4], | |
| 190 bool* ambiguous = NULL); | |
| 191 | |
| 192 enum SkCubicType { | 147 enum SkCubicType { |
| 193 kSerpentine_SkCubicType, | 148 kSerpentine_SkCubicType, |
| 194 kCusp_SkCubicType, | 149 kCusp_SkCubicType, |
| 195 kLoop_SkCubicType, | 150 kLoop_SkCubicType, |
| 196 kQuadratic_SkCubicType, | 151 kQuadratic_SkCubicType, |
| 197 kLine_SkCubicType, | 152 kLine_SkCubicType, |
| 198 kPoint_SkCubicType | 153 kPoint_SkCubicType |
| 199 }; | 154 }; |
| 200 | 155 |
| 201 /** Returns the cubic classification. Pass scratch storage for computing inflect
ion data, | 156 /** Returns the cubic classification. Pass scratch storage for computing inflect
ion data, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 private: | 300 private: |
| 346 enum { | 301 enum { |
| 347 kQuadCount = 8, // should handle most conics | 302 kQuadCount = 8, // should handle most conics |
| 348 kPointCount = 1 + 2 * kQuadCount, | 303 kPointCount = 1 + 2 * kQuadCount, |
| 349 }; | 304 }; |
| 350 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; | 305 SkAutoSTMalloc<kPointCount, SkPoint> fStorage; |
| 351 int fQuadCount; // #quads for current usage | 306 int fQuadCount; // #quads for current usage |
| 352 }; | 307 }; |
| 353 | 308 |
| 354 #endif | 309 #endif |
| OLD | NEW |