Path_Iter_next.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 Google LLC.
  2. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  3. #include "tools/fiddle/examples.h"
  4. // HASH=00ae8984856486bdb626d0ed6587855a
  5. REG_FIDDLE(Path_Iter_next, 256, 256, true, 0) {
  6. void draw(SkCanvas* canvas) {
  7. auto debugster = [](const char* prefix, const SkPath& path, bool degen, bool exact) -> void {
  8. SkPath::Iter iter(path, false);
  9. SkDebugf("%s:\n", prefix);
  10. const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" };
  11. const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 };
  12. SkPath::Verb verb;
  13. do {
  14. SkPoint points[4];
  15. verb = iter.next(points, degen, exact);
  16. SkDebugf("k%s_Verb ", verbStr[(int) verb]);
  17. for (int i = 0; i < pointCount[(int) verb]; ++i) {
  18. SkDebugf("{%1.8g, %1.8g}, ", points[i].fX, points[i].fY);
  19. }
  20. SkDebugf("\n");
  21. } while (SkPath::kDone_Verb != verb);
  22. SkDebugf("\n");
  23. };
  24. SkPath path;
  25. path.moveTo(10, 10);
  26. path.moveTo(20, 20);
  27. path.quadTo(10, 20, 30, 40);
  28. path.moveTo(1, 1);
  29. path.close();
  30. path.moveTo(30, 30);
  31. path.lineTo(30, 30);
  32. path.moveTo(30, 30);
  33. path.lineTo(30.00001f, 30);
  34. debugster("skip degenerate", path, true, false);
  35. debugster("skip degenerate if exact", path, true, true);
  36. debugster("skip none", path, false, false);
  37. }
  38. } // END FIDDLE