| 1 |
/* |
| 2 |
* Copyright 2015 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 |
|
| 8 |
#ifndef SkPathOpsConic_DEFINED |
| 9 |
#define SkPathOpsConic_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkPoint.h" |
| 12 |
#include "include/core/SkScalar.h" |
| 13 |
#include "include/private/base/SkDebug.h" |
| 14 |
#include "src/base/SkArenaAlloc.h" |
| 15 |
#include "src/pathops/SkPathOpsDebug.h" |
| 16 |
#include "src/pathops/SkPathOpsPoint.h" |
| 17 |
#include "src/pathops/SkPathOpsQuad.h" |
| 18 |
#include "src/pathops/SkPathOpsTCurve.h" |
| 19 |
|
| 20 |
class SkIntersections; |
| 21 |
class SkOpGlobalState; |
| 22 |
struct SkDCubic; |
| 23 |
struct SkDLine; |
| 24 |
struct SkDRect; |
| 25 |
|
| 26 |
struct SkDConic { |
| 27 |
static const int kPointCount = 3; |
| 28 |
static const int kPointLast = kPointCount - 1; |
| 29 |
static const int kMaxIntersections = 4; |
| 30 |
|
| 31 |
SkDQuad fPts; |
| 32 |
SkScalar fWeight; |
| 33 |
|
| 34 |
bool collapsed() const { |
| 35 |
return fPts.collapsed(); |
| 36 |
} |
| 37 |
|
| 38 |
bool controlsInside() const { |
| 39 |
return fPts.controlsInside(); |
| 40 |
} |
| 41 |
|
| 42 |
void debugInit() { |
| 43 |
fPts.debugInit(); |
| 44 |
fWeight = 0; |
| 45 |
} |
| 46 |
|
| 47 |
void debugSet(const SkDPoint* pts, SkScalar weight); |
| 48 |
|
| 49 |
SkDConic flip() const { |
| 50 |
SkDConic result = {{{fPts[2], fPts[1], fPts[0]} |
| 51 |
SkDEBUGPARAMS(fPts.fDebugGlobalState) }, fWeight}; |
| 52 |
return result; |
| 53 |
} |
| 54 |
|
| 55 |
#ifdef SK_DEBUG |
| 56 |
SkOpGlobalState* globalState() const { return fPts.globalState(); } |
| 57 |
#endif |
| 58 |
|
| 59 |
static bool IsConic() { return true; } |
| 60 |
|
| 61 |
const SkDConic& set(const SkPoint pts[kPointCount], SkScalar weight |
| 62 |
SkDEBUGPARAMS(SkOpGlobalState* state = nullptr)) { |
| 63 |
fPts.set(pts SkDEBUGPARAMS(state)); |
| 64 |
fWeight = weight; |
| 65 |
return *this; |
| 66 |
} |
| 67 |
|
| 68 |
const SkDPoint& operator[](int n) const { return fPts[n]; } |
| 69 |
SkDPoint& operator[](int n) { return fPts[n]; } |
| 70 |
|
| 71 |
static int AddValidTs(double s[], int realRoots, double* t) { |
| 72 |
return SkDQuad::AddValidTs(s, realRoots, t); |
| 73 |
} |
| 74 |
|
| 75 |
void align(int endIndex, SkDPoint* dstPt) const { |
| 76 |
fPts.align(endIndex, dstPt); |
| 77 |
} |
| 78 |
|
| 79 |
SkDVector dxdyAtT(double t) const; |
| 80 |
static int FindExtrema(const double src[], SkScalar weight, double tValue[1]); |
| 81 |
|
| 82 |
bool hullIntersects(const SkDQuad& quad, bool* isLinear) const { |
| 83 |
return fPts.hullIntersects(quad, isLinear); |
| 84 |
} |
| 85 |
|
| 86 |
bool hullIntersects(const SkDConic& conic, bool* isLinear) const { |
| 87 |
return fPts.hullIntersects(conic.fPts, isLinear); |
| 88 |
} |
| 89 |
|
| 90 |
bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const; |
| 91 |
|
| 92 |
bool isLinear(int startIndex, int endIndex) const { |
| 93 |
return fPts.isLinear(startIndex, endIndex); |
| 94 |
} |
| 95 |
|
| 96 |
static int maxIntersections() { return kMaxIntersections; } |
| 97 |
|
| 98 |
bool monotonicInX() const { |
| 99 |
return fPts.monotonicInX(); |
| 100 |
} |
| 101 |
|
| 102 |
bool monotonicInY() const { |
| 103 |
return fPts.monotonicInY(); |
| 104 |
} |
| 105 |
|
| 106 |
void otherPts(int oddMan, const SkDPoint* endPt[2]) const { |
| 107 |
fPts.otherPts(oddMan, endPt); |
| 108 |
} |
| 109 |
|
| 110 |
static int pointCount() { return kPointCount; } |
| 111 |
static int pointLast() { return kPointLast; } |
| 112 |
SkDPoint ptAtT(double t) const; |
| 113 |
|
| 114 |
static int RootsReal(double A, double B, double C, double t[2]) { |
| 115 |
return SkDQuad::RootsReal(A, B, C, t); |
| 116 |
} |
| 117 |
|
| 118 |
static int RootsValidT(const double A, const double B, const double C, double s[2]) { |
| 119 |
return SkDQuad::RootsValidT(A, B, C, s); |
| 120 |
} |
| 121 |
|
| 122 |
SkDConic subDivide(double t1, double t2) const; |
| 123 |
void subDivide(double t1, double t2, SkDConic* c) const { *c = this->subDivide(t1, t2); } |
| 124 |
|
| 125 |
static SkDConic SubDivide(const SkPoint a[kPointCount], SkScalar weight, double t1, double t2) { |
| 126 |
SkDConic conic; |
| 127 |
conic.set(a, weight); |
| 128 |
return conic.subDivide(t1, t2); |
| 129 |
} |
| 130 |
|
| 131 |
SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2, |
| 132 |
SkScalar* weight) const; |
| 133 |
|
| 134 |
static SkDPoint SubDivide(const SkPoint pts[kPointCount], SkScalar weight, |
| 135 |
const SkDPoint& a, const SkDPoint& c, |
| 136 |
double t1, double t2, SkScalar* newWeight) { |
| 137 |
SkDConic conic; |
| 138 |
conic.set(pts, weight); |
| 139 |
return conic.subDivide(a, c, t1, t2, newWeight); |
| 140 |
} |
| 141 |
|
| 142 |
// utilities callable by the user from the debugger when the implementation code is linked in |
| 143 |
void dump() const; |
| 144 |
void dumpID(int id) const; |
| 145 |
void dumpInner() const; |
| 146 |
|
| 147 |
}; |
| 148 |
|
| 149 |
class SkTConic : public SkTCurve { |
| 150 |
public: |
| 151 |
SkDConic fConic; |
| 152 |
|
| 153 |
SkTConic() {} |
| 154 |
|
| 155 |
SkTConic(const SkDConic& c) |
| 156 |
: fConic(c) { |
| 157 |
} |
| 158 |
|
| 159 |
~SkTConic() override {} |
| 160 |
|
| 161 |
const SkDPoint& operator[](int n) const override { return fConic[n]; } |
| 162 |
SkDPoint& operator[](int n) override { return fConic[n]; } |
| 163 |
|
| 164 |
bool collapsed() const override { return fConic.collapsed(); } |
| 165 |
bool controlsInside() const override { return fConic.controlsInside(); } |
| 166 |
void debugInit() override { return fConic.debugInit(); } |
| 167 |
#if DEBUG_T_SECT |
| 168 |
void dumpID(int id) const override { return fConic.dumpID(id); } |
| 169 |
#endif |
| 170 |
SkDVector dxdyAtT(double t) const override { return fConic.dxdyAtT(t); } |
| 171 |
#ifdef SK_DEBUG |
| 172 |
SkOpGlobalState* globalState() const override { return fConic.globalState(); } |
| 173 |
#endif |
| 174 |
bool hullIntersects(const SkDQuad& quad, bool* isLinear) const override; |
| 175 |
|
| 176 |
bool hullIntersects(const SkDConic& conic, bool* isLinear) const override { |
| 177 |
return conic.hullIntersects(fConic, isLinear); |
| 178 |
} |
| 179 |
|
| 180 |
bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const override; |
| 181 |
|
| 182 |
bool hullIntersects(const SkTCurve& curve, bool* isLinear) const override { |
| 183 |
return curve.hullIntersects(fConic, isLinear); |
| 184 |
} |
| 185 |
|
| 186 |
int intersectRay(SkIntersections* i, const SkDLine& line) const override; |
| 187 |
bool IsConic() const override { return true; } |
| 188 |
SkTCurve* make(SkArenaAlloc& heap) const override { return heap.make<SkTConic>(); } |
| 189 |
|
| 190 |
int maxIntersections() const override { return SkDConic::kMaxIntersections; } |
| 191 |
|
| 192 |
void otherPts(int oddMan, const SkDPoint* endPt[2]) const override { |
| 193 |
fConic.otherPts(oddMan, endPt); |
| 194 |
} |
| 195 |
|
| 196 |
int pointCount() const override { return SkDConic::kPointCount; } |
| 197 |
int pointLast() const override { return SkDConic::kPointLast; } |
| 198 |
SkDPoint ptAtT(double t) const override { return fConic.ptAtT(t); } |
| 199 |
void setBounds(SkDRect* ) const override; |
| 200 |
|
| 201 |
void subDivide(double t1, double t2, SkTCurve* curve) const override { |
| 202 |
((SkTConic*) curve)->fConic = fConic.subDivide(t1, t2); |
| 203 |
} |
| 204 |
}; |
| 205 |
|
| 206 |
#endif |