caryclark@google.com | 9e49fb6 | 2012-08-27 14:11:33 +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 | */ |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 7 | #ifndef CurveIntersection_DEFINE |
| 8 | #define CurveIntersection_DEFINE |
| 9 | |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 10 | #include "DataTypes.h" |
| 11 | |
| 12 | class Intersections; |
| 13 | |
| 14 | // unit-testable utilities |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 15 | double axialIntersect(const Quadratic& q1, const _Point& p, bool vert); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 16 | bool bezier_clip(const Cubic& cubic1, const Cubic& cubic2, double& minT, double& maxT); |
| 17 | bool bezier_clip(const Quadratic& q1, const Quadratic& q2, double& minT, double& maxT); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 18 | int convex_hull(const Cubic& cubic, char order[4]); |
| 19 | bool convex_x_hull(const Cubic& cubic, char connectTo0[2], char connectTo3[2]); |
| 20 | bool implicit_matches(const Cubic& cubic1, const Cubic& cubic2); |
| 21 | bool implicit_matches(const _Line& line1, const _Line& line2); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 22 | bool implicit_matches_ulps(const _Line& one, const _Line& two, int ulps); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 23 | bool implicit_matches(const Quadratic& quad1, const Quadratic& quad2); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 24 | void tangent(const Cubic& cubic, double t, _Point& result); |
| 25 | void tangent(const _Line& line, _Point& result); |
| 26 | void tangent(const Quadratic& quad, double t, _Point& result); |
| 27 | |
| 28 | // main functions |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 29 | enum ReduceOrder_Quadratics { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 30 | kReduceOrder_NoQuadraticsAllowed, |
| 31 | kReduceOrder_QuadraticsAllowed |
| 32 | }; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 33 | enum ReduceOrder_Styles { |
| 34 | kReduceOrder_TreatAsStroke, |
| 35 | kReduceOrder_TreatAsFill |
| 36 | }; |
| 37 | int reduceOrder(const Cubic& cubic, Cubic& reduction, ReduceOrder_Quadratics , |
| 38 | ReduceOrder_Styles ); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 39 | int reduceOrder(const _Line& line, _Line& reduction); |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 40 | int reduceOrder(const Quadratic& quad, Quadratic& reduction, ReduceOrder_Styles ); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 41 | int horizontalIntersect(const Cubic& cubic, double y, double tRange[3]); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 42 | int horizontalIntersect(const Cubic& cubic, double left, double right, double y, |
| 43 | double tRange[3]); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 44 | int horizontalIntersect(const Cubic& cubic, double left, double right, double y, |
| 45 | bool flipped, Intersections&); |
| 46 | int horizontalIntersect(const _Line& line, double left, double right, |
| 47 | double y, bool flipped, Intersections& ); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 48 | int horizontalIntersect(const Quadratic& quad, double left, double right, |
| 49 | double y, double tRange[2]); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 50 | int horizontalIntersect(const Quadratic& quad, double left, double right, |
| 51 | double y, bool flipped, Intersections& ); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 52 | bool intersect(const Cubic& cubic1, const Cubic& cubic2, Intersections& ); |
caryclark@google.com | 73ca624 | 2013-01-17 21:02:47 +0000 | [diff] [blame] | 53 | // the following flavor uses quadratic approximation instead of convex hulls |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 54 | //bool intersect2(const Cubic& cubic1, const Cubic& cubic2, Intersections& ); |
caryclark@google.com | 45a8fc6 | 2013-02-14 15:29:11 +0000 | [diff] [blame] | 55 | // like '2', but iterates on centers instead of possible edges |
| 56 | bool intersect3(const Cubic& cubic1, const Cubic& cubic2, Intersections& ); |
caryclark@google.com | c83c70e | 2013-02-22 21:50:07 +0000 | [diff] [blame] | 57 | int intersect(const Cubic& cubic, Intersections& i); // return true if cubic self-intersects |
caryclark@google.com | 73ca624 | 2013-01-17 21:02:47 +0000 | [diff] [blame] | 58 | int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& ); |
| 59 | int intersect(const Cubic& cubic, const _Line& line, Intersections& ); |
caryclark@google.com | f9502d7 | 2013-02-04 14:06:49 +0000 | [diff] [blame] | 60 | int intersectRay(const Cubic& quad, const _Line& line, Intersections& i); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 61 | bool intersect(const Quadratic& q1, const Quadratic& q2, Intersections& ); |
caryclark@google.com | 3350c3c | 2012-08-24 15:24:36 +0000 | [diff] [blame] | 62 | int intersect(const Quadratic& quad, const _Line& line, Intersections& ); |
caryclark@google.com | 235f56a | 2012-09-14 14:19:30 +0000 | [diff] [blame] | 63 | // the following flavor uses the implicit form instead of convex hulls |
| 64 | bool intersect2(const Quadratic& q1, const Quadratic& q2, Intersections& i); |
| 65 | int intersectRay(const Quadratic& quad, const _Line& line, Intersections& i); |
| 66 | |
| 67 | |
caryclark@google.com | 15fa138 | 2012-05-07 20:49:36 +0000 | [diff] [blame] | 68 | bool isLinear(const Quadratic& quad, int startIndex, int endIndex); |
| 69 | bool isLinear(const Cubic& cubic, int startIndex, int endIndex); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 70 | double leftMostT(const Cubic& , double startT, double endT); |
| 71 | double leftMostT(const _Line& , double startT, double endT); |
| 72 | double leftMostT(const Quadratic& , double startT, double endT); |
| 73 | int verticalIntersect(const Cubic& cubic, double top, double bottom, double x, |
| 74 | bool flipped, Intersections& ); |
| 75 | int verticalIntersect(const _Line& line, double top, double bottom, double x, |
| 76 | bool flipped, Intersections& ); |
| 77 | int verticalIntersect(const Quadratic& quad, double top, double bottom, |
| 78 | double x, bool flipped, Intersections& ); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 79 | |
| 80 | #endif |