| OLD | NEW |
| 1 function tostr(t) | 1 function tostr(t) |
| 2 local str = "" | 2 local str = "" |
| 3 for k, v in next, t do | 3 for k, v in next, t do |
| 4 if #str > 0 then | 4 if #str > 0 then |
| 5 str = str .. ", " | 5 str = str .. ", " |
| 6 end | 6 end |
| 7 if type(k) == "number" then | 7 if type(k) == "number" then |
| 8 str = str .. "[" .. k .. "] = " | 8 str = str .. "[" .. k .. "] = " |
| 9 else | 9 else |
| 10 str = str .. tostring(k) .. " = " | 10 str = str .. tostring(k) .. " = " |
| 11 end | 11 end |
| 12 if type(v) == "table" then | 12 if type(v) == "table" then |
| 13 str = str .. "{ " .. tostr(v) .. " }" | 13 str = str .. "{ " .. tostr(v) .. " }" |
| 14 else | 14 else |
| 15 str = str .. tostring(v) | 15 str = str .. tostring(v) |
| 16 end | 16 end |
| 17 end | 17 end |
| 18 return str | 18 return str |
| 19 end | 19 end |
| 20 | 20 |
| 21 local total = {} -- accumulate() stores its data in here | 21 local total_found = {} -- accumulate() stores its data in here |
| 22 local total_total = {} |
| 22 local canvas -- holds the current canvas (from startcanvas()) | 23 local canvas -- holds the current canvas (from startcanvas()) |
| 23 | 24 |
| 24 --[[ | 25 --[[ |
| 25 startcanvas() is called at the start of each picture file, passing the | 26 startcanvas() is called at the start of each picture file, passing the |
| 26 canvas that we will be drawing into, and the name of the file. | 27 canvas that we will be drawing into, and the name of the file. |
| 27 | 28 |
| 28 Following this call, there will be some number of calls to accumulate(t) | 29 Following this call, there will be some number of calls to accumulate(t) |
| 29 where t is a table of parameters that were passed to that draw-op. | 30 where t is a table of parameters that were passed to that draw-op. |
| 30 | 31 |
| 31 t.verb is a string holding the name of the draw-op (e.g. "drawRect") | 32 t.verb is a string holding the name of the draw-op (e.g. "drawRect") |
| 32 | 33 |
| 33 when a given picture is done, we call endcanvas(canvas, fileName) | 34 when a given picture is done, we call endcanvas(canvas, fileName) |
| 34 ]] | 35 ]] |
| 35 function sk_scrape_startcanvas(c, fileName) | 36 function sk_scrape_startcanvas(c, fileName) |
| 36 canvas = c | 37 canvas = c |
| 37 end | 38 end |
| 38 | 39 |
| 39 --[[ | 40 --[[ |
| 40 Called when the current canvas is done drawing. | 41 Called when the current canvas is done drawing. |
| 41 ]] | 42 ]] |
| 42 function sk_scrape_endcanvas(c, fileName) | 43 function sk_scrape_endcanvas(c, fileName) |
| 43 canvas = nil | 44 canvas = nil |
| 44 end | 45 end |
| 45 | 46 |
| 46 --[[ | 47 function increment(table, key) |
| 47 Called with the parameters to each canvas.draw call, where canvas is the | 48 table[key] = (table[key] or 0) + 1 |
| 48 current canvas as set by startcanvas() | 49 end |
| 49 ]] | 50 |
| 51 |
| 52 local drawPointsTable = {} |
| 53 local drawPointsTable_direction = {} |
| 54 |
| 50 function sk_scrape_accumulate(t) | 55 function sk_scrape_accumulate(t) |
| 51 local n = total[t.verb] or 0 | 56 increment(total_total, t.verb) |
| 52 total[t.verb] = n + 1 | |
| 53 | 57 |
| 54 if false and t.verb == "drawRect" and t.paint:isAntiAlias() then | 58 local p = t.paint |
| 55 local r = t.rect; | 59 if p then |
| 56 local p = t.paint; | 60 local pe = p:getPathEffect(); |
| 57 local c = p:getColor(); | 61 if pe then |
| 58 print("drawRect ", tostr(r), tostr(c), "\n") | 62 increment(total_found, t.verb) |
| 63 end |
| 59 end | 64 end |
| 60 | 65 |
| 61 if false and t.verb == "drawPath" then | 66 if "drawPoints" == t.verb then |
| 62 local pred, r1, r2, d1, d2 = t.path:isNestedRects() | 67 local points = t.points |
| 63 | 68 increment(drawPointsTable, #points) |
| 64 if pred then | 69 if 2 == #points then |
| 65 print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2) | 70 if points[1].y == points[2].y then |
| 66 else | 71 increment(drawPointsTable_direction, "hori") |
| 67 print("drawPath", "isEmpty", tostring(t.path:isEmpty()), | 72 elseif points[1].x == points[2].x then |
| 68 "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds(
))) | 73 increment(drawPointsTable_direction, "vert") |
| 74 else |
| 75 increment(drawPointsTable_direction, "other") |
| 76 end |
| 69 end | 77 end |
| 70 end | 78 end |
| 71 end | 79 end |
| 72 | 80 |
| 73 --[[ | 81 --[[ |
| 74 lua_pictures will call this function after all of the pictures have been | 82 lua_pictures will call this function after all of the pictures have been |
| 75 "accumulated". | 83 "accumulated". |
| 76 ]] | 84 ]] |
| 77 function sk_scrape_summarize() | 85 function sk_scrape_summarize() |
| 78 io.write("\n{ ", tostr(total), " }\n") | 86 for k, v in next, total_found do |
| 87 io.write(k, " = ", v, "/", total_total[k], "\n") |
| 88 end |
| 89 print("histogram of point-counts for all drawPoints calls") |
| 90 print(tostr(drawPointsTable)) |
| 91 print(tostr(drawPointsTable_direction)) |
| 79 end | 92 end |
| 80 | 93 |
| OLD | NEW |