2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #ifndef SkPathOpsCurve_DEFINE
8 #define SkPathOpsCurve_DEFINE
10 #include "SkIntersections.h"
11 #include "SkPathOpsCubic.h"
12 #include "SkPathOpsLine.h"
13 #include "SkPathOpsQuad.h"
15 static SkDPoint dline_xy_at_t(const SkPoint a[2], double t) {
21 static SkDPoint dquad_xy_at_t(const SkPoint a[3], double t) {
27 static SkDPoint dcubic_xy_at_t(const SkPoint a[4], double t) {
30 return cubic.ptAtT(t);
33 static SkDPoint (* const CurveDPointAtT[])(const SkPoint[], double ) = {
40 static SkPoint fline_xy_at_t(const SkPoint a[2], double t) {
41 return dline_xy_at_t(a, t).asSkPoint();
44 static SkPoint fquad_xy_at_t(const SkPoint a[3], double t) {
45 return dquad_xy_at_t(a, t).asSkPoint();
48 static SkPoint fcubic_xy_at_t(const SkPoint a[4], double t) {
49 return dcubic_xy_at_t(a, t).asSkPoint();
52 static SkPoint (* const CurvePointAtT[])(const SkPoint[], double ) = {
59 static SkDVector dline_dxdy_at_t(const SkPoint a[2], double ) {
62 return line[1] - line[0];
65 static SkDVector dquad_dxdy_at_t(const SkPoint a[3], double t) {
68 return quad.dxdyAtT(t);
71 static SkDVector dcubic_dxdy_at_t(const SkPoint a[4], double t) {
74 return cubic.dxdyAtT(t);
77 static SkDVector (* const CurveDSlopeAtT[])(const SkPoint[], double ) = {
84 static SkVector fline_dxdy_at_t(const SkPoint a[2], double ) {
88 static SkVector fquad_dxdy_at_t(const SkPoint a[3], double t) {
89 return dquad_dxdy_at_t(a, t).asSkVector();
92 static SkVector fcubic_dxdy_at_t(const SkPoint a[4], double t) {
93 return dcubic_dxdy_at_t(a, t).asSkVector();
96 static SkVector (* const CurveSlopeAtT[])(const SkPoint[], double ) = {
103 static SkPoint quad_top(const SkPoint a[3], double startT, double endT) {
106 SkDPoint topPt = quad.top(startT, endT);
107 return topPt.asSkPoint();
110 static SkPoint cubic_top(const SkPoint a[4], double startT, double endT) {
113 SkDPoint topPt = cubic.top(startT, endT);
114 return topPt.asSkPoint();
117 static SkPoint (* const CurveTop[])(const SkPoint[], double , double ) = {
124 static bool line_is_vertical(const SkPoint a[2], double startT, double endT) {
127 SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) };
128 return AlmostEqualUlps(dst[0].fX, dst[1].fX);
131 static bool quad_is_vertical(const SkPoint a[3], double startT, double endT) {
134 SkDQuad dst = quad.subDivide(startT, endT);
135 return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX);
138 static bool cubic_is_vertical(const SkPoint a[4], double startT, double endT) {
141 SkDCubic dst = cubic.subDivide(startT, endT);
142 return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX)
143 && AlmostEqualUlps(dst[2].fX, dst[3].fX);
146 static bool (* const CurveIsVertical[])(const SkPoint[], double , double) = {
153 static void line_intersect_ray(const SkPoint a[2], const SkDLine& ray, SkIntersections* i) {
156 i->intersectRay(line, ray);
159 static void quad_intersect_ray(const SkPoint a[3], const SkDLine& ray, SkIntersections* i) {
162 i->intersectRay(quad, ray);
165 static void cubic_intersect_ray(const SkPoint a[4], const SkDLine& ray, SkIntersections* i) {
168 i->intersectRay(cubic, ray);
171 static void (* const CurveIntersectRay[])(const SkPoint[] , const SkDLine& , SkIntersections* ) = {