blob: 74eb6153488814e7a3ad41cdec71f9b4a0ab1030 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +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 */
7#ifndef SkPathOpsLine_DEFINED
8#define SkPathOpsLine_DEFINED
9
10#include "SkPathOpsPoint.h"
11
12struct SkDLine {
13 SkDPoint fPts[2];
14
caryclark@google.comfa2aeee2013-07-15 13:29:13 +000015 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 2); return fPts[n]; }
16 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 2); return fPts[n]; }
17
caryclark@google.com07393ca2013-04-08 11:47:37 +000018 void set(const SkPoint pts[2]) {
19 fPts[0] = pts[0];
20 fPts[1] = pts[1];
21 }
22
caryclark@google.com07393ca2013-04-08 11:47:37 +000023 static SkDLine SubDivide(const SkPoint a[2], double t1, double t2) {
24 SkDLine line;
25 line.set(a);
26 return line.subDivide(t1, t2);
27 }
caryclark@google.comfa2aeee2013-07-15 13:29:13 +000028
29 double exactPoint(const SkDPoint& xy) const;
30 static double ExactPointH(const SkDPoint& xy, double left, double right, double y);
31 static double ExactPointV(const SkDPoint& xy, double top, double bottom, double x);
32 double isLeft(const SkDPoint& pt) const;
caryclarkdac1d172014-06-17 05:15:38 -070033 double nearPoint(const SkDPoint& xy, bool* unequal) const;
caryclark@google.com570863f2013-09-16 15:55:01 +000034 bool nearRay(const SkDPoint& xy) const;
caryclark@google.comfa2aeee2013-07-15 13:29:13 +000035 static double NearPointH(const SkDPoint& xy, double left, double right, double y);
36 static double NearPointV(const SkDPoint& xy, double top, double bottom, double x);
caryclark@google.com570863f2013-09-16 15:55:01 +000037 static bool NearRay(double dx1, double dy1, double dx2, double dy2);
caryclark@google.com4fdbb222013-07-23 15:27:41 +000038 SkDPoint ptAtT(double t) const;
caryclark@google.comfa2aeee2013-07-15 13:29:13 +000039 SkDLine subDivide(double t1, double t2) const;
caryclark@google.com570863f2013-09-16 15:55:01 +000040
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000041 void dump() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000042private:
43 SkDVector tangent() const { return fPts[0] - fPts[1]; }
44};
45
46#endif