blob: 34cd6fb6c271d9563da9ab12544774aa08b5e1de [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);
caryclark@google.comc6825902012-02-03 22:07:47 +000018int convex_hull(const Cubic& cubic, char order[4]);
19bool convex_x_hull(const Cubic& cubic, char connectTo0[2], char connectTo3[2]);
20bool implicit_matches(const Cubic& cubic1, const Cubic& cubic2);
21bool implicit_matches(const _Line& line1, const _Line& line2);
caryclark@google.com78e17132012-04-17 11:40:34 +000022bool implicit_matches_ulps(const _Line& one, const _Line& two, int ulps);
caryclark@google.comc6825902012-02-03 22:07:47 +000023bool implicit_matches(const Quadratic& quad1, const Quadratic& quad2);
caryclark@google.comc6825902012-02-03 22:07:47 +000024void tangent(const Cubic& cubic, double t, _Point& result);
25void tangent(const _Line& line, _Point& result);
26void tangent(const Quadratic& quad, double t, _Point& result);
27
28// main functions
29enum ReduceOrder_Flags {
30 kReduceOrder_NoQuadraticsAllowed,
31 kReduceOrder_QuadraticsAllowed
32};
33int reduceOrder(const Cubic& cubic, Cubic& reduction, ReduceOrder_Flags );
34int reduceOrder(const _Line& line, _Line& reduction);
35int reduceOrder(const Quadratic& quad, Quadratic& reduction);
36int horizontalIntersect(const Cubic& cubic, double y, double tRange[3]);
caryclark@google.com198e0542012-03-30 18:47:02 +000037int horizontalIntersect(const Cubic& cubic, double left, double right, double y,
38 double tRange[3]);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000039int horizontalIntersect(const Cubic& cubic, double left, double right, double y,
40 bool flipped, Intersections&);
41int horizontalIntersect(const _Line& line, double left, double right,
42 double y, bool flipped, Intersections& );
caryclark@google.com198e0542012-03-30 18:47:02 +000043int horizontalIntersect(const Quadratic& quad, double left, double right,
44 double y, double tRange[2]);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000045int horizontalIntersect(const Quadratic& quad, double left, double right,
46 double y, bool flipped, Intersections& );
caryclark@google.comc6825902012-02-03 22:07:47 +000047bool intersect(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
caryclark@google.com73ca6242013-01-17 21:02:47 +000048// the following flavor uses quadratic approximation instead of convex hulls
49bool intersect2(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
50bool intersect(const Cubic& cubic, Intersections& i); // return true if cubic self-intersects
51int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& );
52int intersect(const Cubic& cubic, const _Line& line, Intersections& );
caryclark@google.comf9502d72013-02-04 14:06:49 +000053int intersectRay(const Cubic& quad, const _Line& line, Intersections& i);
caryclark@google.comc6825902012-02-03 22:07:47 +000054bool 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.com235f56a2012-09-14 14:19:30 +000056// the following flavor uses the implicit form instead of convex hulls
57bool intersect2(const Quadratic& q1, const Quadratic& q2, Intersections& i);
58int intersectRay(const Quadratic& quad, const _Line& line, Intersections& i);
59
60
caryclark@google.com15fa1382012-05-07 20:49:36 +000061bool isLinear(const Quadratic& quad, int startIndex, int endIndex);
62bool isLinear(const Cubic& cubic, int startIndex, int endIndex);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000063double leftMostT(const Cubic& , double startT, double endT);
64double leftMostT(const _Line& , double startT, double endT);
65double leftMostT(const Quadratic& , double startT, double endT);
66int verticalIntersect(const Cubic& cubic, double top, double bottom, double x,
67 bool flipped, Intersections& );
68int verticalIntersect(const _Line& line, double top, double bottom, double x,
69 bool flipped, Intersections& );
70int verticalIntersect(const Quadratic& quad, double top, double bottom,
71 double x, bool flipped, Intersections& );
caryclark@google.comd88e0892012-03-27 13:23:51 +000072
73#endif