blob: 6c8ca954f164ebeb3fd644466e583023a2444c33 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
2 * Copyright 2013 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#include "SkPathOpsDebug.h"
caryclark@google.coma5e55922013-05-07 18:51:31 +00009#include "SkPath.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000010
11#if defined SK_DEBUG || !FORCE_RELEASE
12
13int gDebugMaxWindSum = SK_MaxS32;
14int gDebugMaxWindValue = SK_MaxS32;
15
16void mathematica_ize(char* str, size_t bufferLen) {
17 size_t len = strlen(str);
18 bool num = false;
19 for (size_t idx = 0; idx < len; ++idx) {
20 if (num && str[idx] == 'e') {
21 if (len + 2 >= bufferLen) {
22 return;
23 }
24 memmove(&str[idx + 2], &str[idx + 1], len - idx);
25 str[idx] = '*';
26 str[idx + 1] = '^';
27 ++len;
28 }
29 num = str[idx] >= '0' && str[idx] <= '9';
30 }
31}
caryclark@google.com03610322013-04-18 15:58:21 +000032#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +000033
caryclark@google.com03610322013-04-18 15:58:21 +000034#if DEBUG_SORT || DEBUG_SWAP_TOP
caryclark@google.com07393ca2013-04-08 11:47:37 +000035bool valid_wind(int wind) {
36 return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF;
37}
38
39void winding_printf(int wind) {
40 if (wind == SK_MinS32) {
41 SkDebugf("?");
42 } else {
43 SkDebugf("%d", wind);
44 }
45}
46#endif
47
48#if DEBUG_DUMP
49const char* kLVerbStr[] = {"", "line", "quad", "cubic"};
50// static const char* kUVerbStr[] = {"", "Line", "Quad", "Cubic"};
51int gContourID;
52int gSegmentID;
53#endif
54
55#if DEBUG_SORT || DEBUG_SWAP_TOP
56int gDebugSortCountDefault = SK_MaxS32;
57int gDebugSortCount;
58#endif
59
60#if DEBUG_ACTIVE_OP
61const char* kPathOpStr[] = {"diff", "sect", "union", "xor"};
62#endif
caryclark@google.coma5e55922013-05-07 18:51:31 +000063
64#if DEBUG_SHOW_PATH
65static void showPathContours(SkPath::Iter& iter, const char* pathName) {
66 uint8_t verb;
67 SkPoint pts[4];
68 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
69 switch (verb) {
70 case SkPath::kMove_Verb:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000071 SkDebugf(" %s.moveTo(%#1.9gf, %#1.9gf);\n", pathName, pts[0].fX, pts[0].fY);
caryclark@google.coma5e55922013-05-07 18:51:31 +000072 continue;
73 case SkPath::kLine_Verb:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000074 SkDebugf(" %s.lineTo(%#1.9gf, %#1.9gf);\n", pathName, pts[1].fX, pts[1].fY);
caryclark@google.coma5e55922013-05-07 18:51:31 +000075 break;
76 case SkPath::kQuad_Verb:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000077 SkDebugf(" %s.quadTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n", pathName,
caryclark@google.coma5e55922013-05-07 18:51:31 +000078 pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
79 break;
80 case SkPath::kCubic_Verb:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000081 SkDebugf(" %s.cubicTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n",
caryclark@google.coma5e55922013-05-07 18:51:31 +000082 pathName, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, pts[3].fX, pts[3].fY);
83 break;
84 case SkPath::kClose_Verb:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000085 SkDebugf(" %s.close();\n", pathName);
caryclark@google.coma5e55922013-05-07 18:51:31 +000086 break;
87 default:
88 SkDEBUGFAIL("bad verb");
89 return;
90 }
91 }
92}
93
94static const char* gFillTypeStr[] = {
95 "kWinding_FillType",
96 "kEvenOdd_FillType",
97 "kInverseWinding_FillType",
98 "kInverseEvenOdd_FillType"
99};
100
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000101
102void ShowFunctionHeader() {
103 SkDebugf("\nstatic void test#(skiatest::Reporter* reporter) {\n");
104}
105
caryclark@google.coma5e55922013-05-07 18:51:31 +0000106void ShowPath(const SkPath& path, const char* pathName) {
107 SkPath::Iter iter(path, true);
108 SkPath::FillType fillType = path.getFillType();
109 SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInverseEvenOdd_FillType);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000110 SkDebugf(" SkPath %s;\n", pathName);
111 SkDebugf(" %s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillType]);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000112 iter.setPath(path, true);
113 showPathContours(iter, pathName);
114}
115
116static const char* gOpStrs[] = {
117 "kDifference_PathOp",
118 "kIntersect_PathOp",
119 "kUnion_PathOp",
120 "kXor_PathOp",
121 "kReverseDifference_PathOp",
122};
123
124void ShowOp(SkPathOp op, const char* pathOne, const char* pathTwo) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000125 SkDebugf(" testPathOp(reporter, %s, %s, %s);\n", pathOne, pathTwo, gOpStrs[op]);
126 SkDebugf("}\n");
caryclark@google.coma5e55922013-05-07 18:51:31 +0000127}
128#endif