blob: 2800ff0568118400ac0e0fe303924ac72a42b7bb [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 SkOpAngle_DEFINED
8#define SkOpAngle_DEFINED
9
10#include "SkLineParameters.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000011#include "SkPath.h"
12#include "SkPathOpsCubic.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000013
14class SkOpSegment;
caryclark@google.com07393ca2013-04-08 11:47:37 +000015
16// sorting angles
17// given angles of {dx dy ddx ddy dddx dddy} sort them
18class SkOpAngle {
19public:
20 bool operator<(const SkOpAngle& rh) const;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000021
caryclark@google.comcffbcc32013-06-04 17:59:42 +000022 bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
23
caryclark@google.com07393ca2013-04-08 11:47:37 +000024 double dx() const {
25 return fTangent1.dx();
26 }
27
28 double dy() const {
29 return fTangent1.dy();
30 }
31
32 int end() const {
33 return fEnd;
34 }
35
caryclark@google.comcffbcc32013-06-04 17:59:42 +000036 bool isHorizontal() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000037
caryclark@google.comcffbcc32013-06-04 17:59:42 +000038 void set(const SkOpSegment* segment, int start, int end);
caryclark@google.comad65a3e2013-04-15 19:13:59 +000039
caryclark@google.com07393ca2013-04-08 11:47:37 +000040 SkOpSegment* segment() const {
41 return const_cast<SkOpSegment*>(fSegment);
42 }
43
44 int sign() const {
45 return SkSign32(fStart - fEnd);
46 }
47
caryclark@google.com07393ca2013-04-08 11:47:37 +000048 int start() const {
49 return fStart;
50 }
51
caryclark@google.comcffbcc32013-06-04 17:59:42 +000052 bool unorderable() const {
53 return fUnorderable;
54 }
55
caryclark@google.com07393ca2013-04-08 11:47:37 +000056 bool unsortable() const {
57 return fUnsortable;
58 }
59
60#if DEBUG_ANGLE
caryclark@google.com07393ca2013-04-08 11:47:37 +000061 void debugShow(const SkPoint& a) const {
62 SkDebugf(" d=(%1.9g,%1.9g) side=%1.9g\n", dx(), dy(), fSide);
63 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +000064
65 void setID(int id) {
66 fID = id;
67 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000068#endif
69
70private:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000071 bool lengthen(const SkOpAngle& );
72 void setSpans();
73
caryclark@google.com07393ca2013-04-08 11:47:37 +000074 SkDCubic fCurvePart;
caryclark@google.com07393ca2013-04-08 11:47:37 +000075 double fSide;
76 SkLineParameters fTangent1;
caryclark@google.com07393ca2013-04-08 11:47:37 +000077 const SkOpSegment* fSegment;
78 int fStart;
79 int fEnd;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000080 bool fComputed; // tangent is computed, may contain some error
81 // if subdividing a quad or cubic causes the tangent to go from the maximum angle to the
82 // minimum, mark it unorderable. It still can be sorted, which is good enough for find-top
83 // but can't be ordered, and therefore can't be used to compute winding
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +000084 bool fUnorderable;
caryclark@google.com07393ca2013-04-08 11:47:37 +000085 mutable bool fUnsortable; // this alone is editable by the less than operator
caryclark@google.comcffbcc32013-06-04 17:59:42 +000086#if DEBUG_ANGLE
87 int fID;
88#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +000089};
90
91#endif