blob: 2d0962b1e4d811afef28e8f3e897aa67580c5cc8 [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:
71 SkDebugf("%s.moveTo(%#1.9gf, %#1.9gf);\n", pathName, pts[0].fX, pts[0].fY);
72 continue;
73 case SkPath::kLine_Verb:
74 SkDebugf("%s.lineTo(%#1.9gf, %#1.9gf);\n", pathName, pts[1].fX, pts[1].fY);
75 break;
76 case SkPath::kQuad_Verb:
77 SkDebugf("%s.quadTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n", pathName,
78 pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
79 break;
80 case SkPath::kCubic_Verb:
81 SkDebugf("%s.cubicTo(%#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf, %#1.9gf);\n",
82 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:
85 SkDebugf("%s.close();\n", pathName);
86 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
101void ShowPath(const SkPath& path, const char* pathName) {
102 SkPath::Iter iter(path, true);
103 SkPath::FillType fillType = path.getFillType();
104 SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInverseEvenOdd_FillType);
105 SkDebugf("SkPath %s;\n", pathName);
106 SkDebugf("%s.setFillType(SkPath::%s);\n", pathName, gFillTypeStr[fillType]);
107 iter.setPath(path, true);
108 showPathContours(iter, pathName);
109}
110
111static const char* gOpStrs[] = {
112 "kDifference_PathOp",
113 "kIntersect_PathOp",
114 "kUnion_PathOp",
115 "kXor_PathOp",
116 "kReverseDifference_PathOp",
117};
118
119void ShowOp(SkPathOp op, const char* pathOne, const char* pathTwo) {
120 SkDebugf("SkPath result;\n");
121 SkDebugf("bool success = Op(%s, %s, %s, &result);\n", pathOne, pathTwo, gOpStrs[op]);
122 SkDebugf("SkASSERT(success);\n");
123}
124#endif