SkPathOpsConic.h 5.9 KB

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