SkPathOpsRect.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  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. #include "src/pathops/SkPathOpsConic.h"
  8. #include "src/pathops/SkPathOpsCubic.h"
  9. #include "src/pathops/SkPathOpsLine.h"
  10. #include "src/pathops/SkPathOpsQuad.h"
  11. #include "src/pathops/SkPathOpsRect.h"
  12. void SkDRect::setBounds(const SkDQuad& curve, const SkDQuad& sub, double startT, double endT) {
  13. set(sub[0]);
  14. add(sub[2]);
  15. double tValues[2];
  16. int roots = 0;
  17. if (!sub.monotonicInX()) {
  18. roots = SkDQuad::FindExtrema(&sub[0].fX, tValues);
  19. }
  20. if (!sub.monotonicInY()) {
  21. roots += SkDQuad::FindExtrema(&sub[0].fY, &tValues[roots]);
  22. }
  23. for (int index = 0; index < roots; ++index) {
  24. double t = startT + (endT - startT) * tValues[index];
  25. add(curve.ptAtT(t));
  26. }
  27. }
  28. void SkDRect::setBounds(const SkDConic& curve, const SkDConic& sub, double startT, double endT) {
  29. set(sub[0]);
  30. add(sub[2]);
  31. double tValues[2];
  32. int roots = 0;
  33. if (!sub.monotonicInX()) {
  34. roots = SkDConic::FindExtrema(&sub[0].fX, sub.fWeight, tValues);
  35. }
  36. if (!sub.monotonicInY()) {
  37. roots += SkDConic::FindExtrema(&sub[0].fY, sub.fWeight, &tValues[roots]);
  38. }
  39. for (int index = 0; index < roots; ++index) {
  40. double t = startT + (endT - startT) * tValues[index];
  41. add(curve.ptAtT(t));
  42. }
  43. }
  44. void SkDRect::setBounds(const SkDCubic& curve, const SkDCubic& sub, double startT, double endT) {
  45. set(sub[0]);
  46. add(sub[3]);
  47. double tValues[4];
  48. int roots = 0;
  49. if (!sub.monotonicInX()) {
  50. roots = SkDCubic::FindExtrema(&sub[0].fX, tValues);
  51. }
  52. if (!sub.monotonicInY()) {
  53. roots += SkDCubic::FindExtrema(&sub[0].fY, &tValues[roots]);
  54. }
  55. for (int index = 0; index < roots; ++index) {
  56. double t = startT + (endT - startT) * tValues[index];
  57. add(curve.ptAtT(t));
  58. }
  59. }
  60. void SkDRect::setBounds(const SkTCurve& curve) {
  61. curve.setBounds(this);
  62. }