blob: cd2153aa39a18be3b197b3f00851fe52c5340264 [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& );
53int intersect(const Cubic& cubic, const _Line& line, double cRange[3], double lRange[3]);
54bool intersect(const Quadratic& q1, const Quadratic& q2, Intersections& );
caryclark@google.com3350c3c2012-08-24 15:24:36 +000055int intersect(const Quadratic& quad, const _Line& line, Intersections& );
caryclark@google.com15fa1382012-05-07 20:49:36 +000056bool isLinear(const Quadratic& quad, int startIndex, int endIndex);
57bool isLinear(const Cubic& cubic, int startIndex, int endIndex);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000058double leftMostT(const Cubic& , double startT, double endT);
59double leftMostT(const _Line& , double startT, double endT);
60double leftMostT(const Quadratic& , double startT, double endT);
61int verticalIntersect(const Cubic& cubic, double top, double bottom, double x,
62 bool flipped, Intersections& );
63int verticalIntersect(const _Line& line, double top, double bottom, double x,
64 bool flipped, Intersections& );
65int verticalIntersect(const Quadratic& quad, double top, double bottom,
66 double x, bool flipped, Intersections& );
caryclark@google.comd88e0892012-03-27 13:23:51 +000067
68#endif