PathOpsSimplifyTrianglesThreadedTest.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "include/core/SkString.h"
  8. #include "tests/PathOpsExtendedTest.h"
  9. #include "tests/PathOpsThreadedCommon.h"
  10. static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
  11. SkASSERT(data);
  12. PathOpsThreadState& state = *data;
  13. state.fKey = "?";
  14. int ax = state.fA & 0x03;
  15. int ay = state.fA >> 2;
  16. int bx = state.fB & 0x03;
  17. int by = state.fB >> 2;
  18. int cx = state.fC & 0x03;
  19. int cy = state.fC >> 2;
  20. for (int d = 0; d < 15; ++d) {
  21. int dx = d & 0x03;
  22. int dy = d >> 2;
  23. for (int e = d + 1; e < 16; ++e) {
  24. int ex = e & 0x03;
  25. int ey = e >> 2;
  26. for (int f = d + 1; f < 16; ++f) {
  27. if (e == f) {
  28. continue;
  29. }
  30. int fx = f & 0x03;
  31. int fy = f >> 2;
  32. if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
  33. continue;
  34. }
  35. SkString pathStr;
  36. SkPath path, out;
  37. path.setFillType(SkPath::kWinding_FillType);
  38. path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
  39. path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
  40. path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
  41. path.close();
  42. path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
  43. path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
  44. path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
  45. path.close();
  46. if (state.fReporter->verbose()) {
  47. pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
  48. pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
  49. pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
  50. pathStr.appendf(" path.close();\n");
  51. pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
  52. pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
  53. pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
  54. pathStr.appendf(" path.close();\n");
  55. state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
  56. }
  57. ShowTestName(&state, d, e, f, 0);
  58. testSimplify(path, false, out, state, pathStr.c_str());
  59. path.setFillType(SkPath::kEvenOdd_FillType);
  60. if (state.fReporter->verbose()) {
  61. state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
  62. }
  63. ShowTestName(&state, d, e, f, 1);
  64. testSimplify(path, true, out, state, pathStr.c_str());
  65. }
  66. }
  67. }
  68. }
  69. DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
  70. initializeTests(reporter, "testTriangles");
  71. PathOpsThreadedTestRunner testRunner(reporter);
  72. for (int a = 0; a < 15; ++a) {
  73. int ax = a & 0x03;
  74. int ay = a >> 2;
  75. for (int b = a + 1; b < 16; ++b) {
  76. int bx = b & 0x03;
  77. int by = b >> 2;
  78. for (int c = a + 1; c < 16; ++c) {
  79. if (b == c) {
  80. continue;
  81. }
  82. int cx = c & 0x03;
  83. int cy = c >> 2;
  84. if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
  85. continue;
  86. }
  87. *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
  88. &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
  89. }
  90. if (!reporter->allowExtendedTest()) goto finish;
  91. }
  92. }
  93. finish:
  94. testRunner.render();
  95. }