blob: cbcda7645265da5a75db44397276f76b24b38907 [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
caryclark@google.com47d73da2013-02-17 01:41:25 +000029enum ReduceOrder_Quadratics {
caryclark@google.comc6825902012-02-03 22:07:47 +000030 kReduceOrder_NoQuadraticsAllowed,
31 kReduceOrder_QuadraticsAllowed
32};
caryclark@google.com47d73da2013-02-17 01:41:25 +000033enum ReduceOrder_Styles {
34 kReduceOrder_TreatAsStroke,
35 kReduceOrder_TreatAsFill
36};
37int reduceOrder(const Cubic& cubic, Cubic& reduction, ReduceOrder_Quadratics ,
38 ReduceOrder_Styles );
caryclark@google.comc6825902012-02-03 22:07:47 +000039int reduceOrder(const _Line& line, _Line& reduction);
caryclark@google.com47d73da2013-02-17 01:41:25 +000040int reduceOrder(const Quadratic& quad, Quadratic& reduction, ReduceOrder_Styles );
caryclark@google.comc6825902012-02-03 22:07:47 +000041int 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
caryclark@google.com4aaaaea2013-02-28 16:12:39 +000054//bool intersect2(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
caryclark@google.com45a8fc62013-02-14 15:29:11 +000055// like '2', but iterates on centers instead of possible edges
56bool intersect3(const Cubic& cubic1, const Cubic& cubic2, Intersections& );
caryclark@google.comc83c70e2013-02-22 21:50:07 +000057int intersect(const Cubic& cubic, Intersections& i); // return true if cubic self-intersects
caryclark@google.com73ca6242013-01-17 21:02:47 +000058int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& );
59int intersect(const Cubic& cubic, const _Line& line, Intersections& );
caryclark@google.comf9502d72013-02-04 14:06:49 +000060int intersectRay(const Cubic& quad, const _Line& line, Intersections& i);
caryclark@google.comc6825902012-02-03 22:07:47 +000061bool intersect(const Quadratic& q1, const Quadratic& q2, Intersections& );
caryclark@google.com3350c3c2012-08-24 15:24:36 +000062int intersect(const Quadratic& quad, const _Line& line, Intersections& );
caryclark@google.com235f56a2012-09-14 14:19:30 +000063// the following flavor uses the implicit form instead of convex hulls
64bool intersect2(const Quadratic& q1, const Quadratic& q2, Intersections& i);
65int intersectRay(const Quadratic& quad, const _Line& line, Intersections& i);
66
67
caryclark@google.com15fa1382012-05-07 20:49:36 +000068bool isLinear(const Quadratic& quad, int startIndex, int endIndex);
69bool isLinear(const Cubic& cubic, int startIndex, int endIndex);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000070double leftMostT(const Cubic& , double startT, double endT);
71double leftMostT(const _Line& , double startT, double endT);
72double leftMostT(const Quadratic& , double startT, double endT);
73int verticalIntersect(const Cubic& cubic, double top, double bottom, double x,
74 bool flipped, Intersections& );
75int verticalIntersect(const _Line& line, double top, double bottom, double x,
76 bool flipped, Intersections& );
77int verticalIntersect(const Quadratic& quad, double top, double bottom,
78 double x, bool flipped, Intersections& );
caryclark@google.comd88e0892012-03-27 13:23:51 +000079
80#endif