blob: 4b34b31adbc6cbfc0ed1374923d45e5858d0fdba [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +00001/*
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.comd88e0892012-03-27 13:23:51 +00007#ifndef CurveIntersection_DEFINE
8#define CurveIntersection_DEFINE
9
caryclark@google.comc6825902012-02-03 22:07:47 +000010#include "DataTypes.h"
11
12class Intersections;
13
14// unit-testable utilities
caryclark@google.comfa0588f2012-04-26 21:01:06 +000015double axialIntersect(const Quadratic& q1, const _Point& p, bool vert);
caryclark@google.comc6825902012-02-03 22:07:47 +000016bool bezier_clip(const Cubic& cubic1, const Cubic& cubic2, double& minT, double& maxT);
17bool bezier_clip(const Quadratic& q1, const Quadratic& q2, double& minT, double& maxT);
18void chop_at(const Cubic& src, CubicPair& dst, double t);
19void chop_at(const Quadratic& src, QuadraticPair& dst, double t);
20int convex_hull(const Cubic& cubic, char order[4]);
21bool convex_x_hull(const Cubic& cubic, char connectTo0[2], char connectTo3[2]);
22bool implicit_matches(const Cubic& cubic1, const Cubic& cubic2);
23bool implicit_matches(const _Line& line1, const _Line& line2);
caryclark@google.com78e17132012-04-17 11:40:34 +000024bool implicit_matches_ulps(const _Line& one, const _Line& two, int ulps);
caryclark@google.comc6825902012-02-03 22:07:47 +000025bool implicit_matches(const Quadratic& quad1, const Quadratic& quad2);
26void sub_divide(const Cubic& src, double t1, double t2, Cubic& dst);
caryclark@google.com6680fb12012-02-07 22:10:51 +000027void sub_divide(const _Line& src, double t1, double t2, _Line& dst);
caryclark@google.comc6825902012-02-03 22:07:47 +000028void sub_divide(const Quadratic& src, double t1, double t2, Quadratic& dst);
29void tangent(const Cubic& cubic, double t, _Point& result);
30void tangent(const _Line& line, _Point& result);
31void tangent(const Quadratic& quad, double t, _Point& result);
32
33// main functions
34enum ReduceOrder_Flags {
35 kReduceOrder_NoQuadraticsAllowed,
36 kReduceOrder_QuadraticsAllowed
37};
38int reduceOrder(const Cubic& cubic, Cubic& reduction, ReduceOrder_Flags );
39int reduceOrder(const _Line& line, _Line& reduction);
40int reduceOrder(const Quadratic& quad, Quadratic& reduction);
41int horizontalIntersect(const Cubic& cubic, double y, double tRange[3]);
caryclark@google.com198e0542012-03-30 18:47:02 +000042int horizontalIntersect(const Cubic& cubic, double left, double right, double y,
43 double tRange[3]);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000044int horizontalIntersect(const Cubic& cubic, double left, double right, double y,
45 bool flipped, Intersections&);
46int horizontalIntersect(const _Line& line, double left, double right,
47 double y, bool flipped, Intersections& );
caryclark@google.com198e0542012-03-30 18:47:02 +000048int horizontalIntersect(const Quadratic& quad, double left, double right,
49 double y, double tRange[2]);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000050int horizontalIntersect(const Quadratic& quad, double left, double right,
51 double y, bool flipped, Intersections& );
caryclark@google.comc6825902012-02-03 22:07:47 +000052bool intersect(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
caryclark@google.com73ca6242013-01-17 21:02:47 +000053// the following flavor uses quadratic approximation instead of convex hulls
54bool intersect2(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
55bool intersect(const Cubic& cubic, Intersections& i); // return true if cubic self-intersects
56int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& );
57int intersect(const Cubic& cubic, const _Line& line, Intersections& );
caryclark@google.comc6825902012-02-03 22:07:47 +000058bool intersect(const Quadratic& q1, const Quadratic& q2, Intersections& );
caryclark@google.com3350c3c2012-08-24 15:24:36 +000059int intersect(const Quadratic& quad, const _Line& line, Intersections& );
caryclark@google.com235f56a2012-09-14 14:19:30 +000060// the following flavor uses the implicit form instead of convex hulls
61bool intersect2(const Quadratic& q1, const Quadratic& q2, Intersections& i);
62int intersectRay(const Quadratic& quad, const _Line& line, Intersections& i);
63
64
caryclark@google.com15fa1382012-05-07 20:49:36 +000065bool isLinear(const Quadratic& quad, int startIndex, int endIndex);
66bool isLinear(const Cubic& cubic, int startIndex, int endIndex);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000067double leftMostT(const Cubic& , double startT, double endT);
68double leftMostT(const _Line& , double startT, double endT);
69double leftMostT(const Quadratic& , double startT, double endT);
70int verticalIntersect(const Cubic& cubic, double top, double bottom, double x,
71 bool flipped, Intersections& );
72int verticalIntersect(const _Line& line, double top, double bottom, double x,
73 bool flipped, Intersections& );
74int verticalIntersect(const Quadratic& quad, double top, double bottom,
75 double x, bool flipped, Intersections& );
caryclark@google.comd88e0892012-03-27 13:23:51 +000076
77#endif