From 0f9358f01399aff7920ae220e6762f34aa1e1093 Mon Sep 17 00:00:00 2001 From: treeform Date: Fri, 8 Jul 2022 23:09:59 -0700 Subject: [PATCH] more diffVs --- tests/test_images.nim | 36 ++++++++++++++++---------------- tests/test_images_draw.nim | 40 ++++++++++++++++++------------------ tests/test_masks.nim | 42 +++++++++++++++++++------------------- tests/test_svg.nim | 31 +++++++++++++++------------- 4 files changed, 76 insertions(+), 73 deletions(-) diff --git a/tests/test_images.nim b/tests/test_images.nim index 4ae2938..b74e32d 100644 --- a/tests/test_images.nim +++ b/tests/test_images.nim @@ -1,4 +1,4 @@ -import chroma, pixie, pixie/internal, vmath +import chroma, pixie, pixie/internal, vmath, utils block: let image = newImage(10, 10) @@ -45,77 +45,77 @@ block: a.draw(b) - a.writeFile("tests/images/flipped1.png") + a.diffVs("tests/images/flipped1.png") a.flipVertical() - a.writeFile("tests/images/flipped2.png") + a.diffVs("tests/images/flipped2.png") a.flipHorizontal() - a.writeFile("tests/images/flipped3.png") + a.diffVs("tests/images/flipped3.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(-10, 0, 20, 20) - b.writeFile("tests/images/superimage1.png") + b.diffVs("tests/images/superimage1.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(-10, -10, 20, 20) - b.writeFile("tests/images/superimage2.png") + b.diffVs("tests/images/superimage2.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(90, 0, 120, 120) - b.writeFile("tests/images/superimage3.png") + b.diffVs("tests/images/superimage3.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(90, 90, 120, 120) - b.writeFile("tests/images/superimage4.png") + b.diffVs("tests/images/superimage4.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(-10, -10, 120, 120) - b.writeFile("tests/images/superimage5.png") + b.diffVs("tests/images/superimage5.png") block: let a = readImage("tests/images/flipped1.png") b = a.superImage(45, 45, 20, 20) - b.writeFile("tests/images/superimage6.png") + b.diffVs("tests/images/superimage6.png") block: let a = readImage("tests/images/flipped1.png") b = a.minifyBy2() - b.writeFile("tests/images/minifiedBy2.png") + b.diffVs("tests/images/minifiedBy2.png") block: let a = readImage("tests/images/minifiedBy2.png") b = a.magnifyBy2() - b.writeFile("tests/images/magnifiedBy2.png") + b.diffVs("tests/images/magnifiedBy2.png") block: let a = readImage("tests/images/flipped1.png") b = a.minifyBy2(2) - b.writeFile("tests/images/minifiedBy4.png") + b.diffVs("tests/images/minifiedBy4.png") block: let a = readImage("tests/images/minifiedBy4.png") b = a.magnifyBy2(2) - b.writeFile("tests/images/magnifiedBy4.png") + b.diffVs("tests/images/magnifiedBy4.png") block: let a = readImage("tests/fileformats/png/mandrill.png") b = a.minifyBy2() - b.writeFile("tests/images/minifiedMandrill.png") + b.diffVs("tests/images/minifiedMandrill.png") block: let a = newImage(100, 100) @@ -129,7 +129,7 @@ block: ctx.image.fill(rgba(0, 0, 0, 255)) ctx.fillRect(rect(25, 25, 50, 50), ) ctx.image.blur(20) - ctx.image.writeFile("tests/images/imageblur20.png") + ctx.image.diffVs("tests/images/imageblur20.png") block: let ctx = newContext(100, 100) @@ -137,7 +137,7 @@ block: ctx.image.fill(rgba(0, 0, 0, 255)) ctx.fillRect(rect(25, 25, 50, 50)) ctx.image.blur(20, rgba(0, 0, 0, 255)) - ctx.image.writeFile("tests/images/imageblur20oob.png") + ctx.image.diffVs("tests/images/imageblur20oob.png") block: # Test conversion between image and mask let @@ -163,7 +163,7 @@ block: let image = newImage(100, 100) image.fillPath(p, rgba(255, 0, 0, 255)) - newImage(newMask(image)).writeFile("tests/images/mask2image.png") + newImage(newMask(image)).diffVs("tests/images/mask2image.png") block: let image = newImage(100, 100) diff --git a/tests/test_images_draw.nim b/tests/test_images_draw.nim index 4c926f6..a3ffdb2 100644 --- a/tests/test_images_draw.nim +++ b/tests/test_images_draw.nim @@ -1,12 +1,12 @@ -import pixie, strformat +import pixie, strformat, utils proc doDiff(rendered: Image, name: string) = - rendered.writeFile(&"tests/images/rendered/{name}.png") + rendered.diffVs(&"tests/images/rendered/{name}.png") let master = readImage(&"tests/images/masters/{name}.png") (diffScore, diffImage) = diff(master, rendered) echo &"{name} score: {diffScore}" - diffImage.writeFile(&"tests/images/diffs/{name}.png") + diffImage.diffVs(&"tests/images/diffs/{name}.png") block: let @@ -16,7 +16,7 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250))) - a.writeFile("tests/images/rotate0.png") + a.diffVs("tests/images/rotate0.png") block: let @@ -26,7 +26,7 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250)) * rotate(90 * PI.float32 / 180)) - a.writeFile("tests/images/rotate90.png") + a.diffVs("tests/images/rotate90.png") block: let @@ -36,7 +36,7 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250)) * rotate(180 * PI.float32 / 180)) - a.writeFile("tests/images/rotate180.png") + a.diffVs("tests/images/rotate180.png") block: let @@ -46,7 +46,7 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250)) * rotate(270 * PI.float32 / 180)) - a.writeFile("tests/images/rotate270.png") + a.diffVs("tests/images/rotate270.png") block: let @@ -56,14 +56,14 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250)) * rotate(360 * PI.float32 / 180)) - a.writeFile("tests/images/rotate360.png") + a.diffVs("tests/images/rotate360.png") block: let ctx = newContext(100, 100) ctx.fillStyle = rgba(255, 255, 0, 255) ctx.image.fill(rgba(0, 255, 255, 255)) ctx.fillRect(rect(vec2(10, 10), vec2(30, 30))) - ctx.image.writeFile("tests/images/drawRect.png") + ctx.image.diffVs("tests/images/drawRect.png") block: let ctx = newContext(100, 100) @@ -71,14 +71,14 @@ block: ctx.lineWidth = 10 ctx.image.fill(rgba(0, 255, 255, 255)) ctx.strokeRect(rect(vec2(10, 10), vec2(30, 30))) - ctx.image.writeFile("tests/images/strokeRect.png") + ctx.image.diffVs("tests/images/strokeRect.png") block: let ctx = newContext(100, 100) ctx.fillStyle = rgba(255, 255, 0, 255) ctx.image.fill(rgba(0, 255, 255, 255)) ctx.fillRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10) - ctx.image.writeFile("tests/images/drawRoundedRect.png") + ctx.image.diffVs("tests/images/drawRoundedRect.png") block: let ctx = newContext(100, 100) @@ -86,7 +86,7 @@ block: ctx.lineWidth = 10 ctx.image.fill(rgba(0, 255, 255, 255)) ctx.strokeRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10) - ctx.image.writeFile("tests/images/strokeRoundedRect.png") + ctx.image.diffVs("tests/images/strokeRoundedRect.png") block: let ctx = newContext(100, 100) @@ -94,14 +94,14 @@ block: ctx.lineWidth = 10 ctx.image.fill(rgba(0, 255, 255, 255)) ctx.strokeSegment(segment(vec2(10, 10), vec2(90, 90))) - ctx.image.writeFile("tests/images/drawSegment.png") + ctx.image.diffVs("tests/images/drawSegment.png") block: let ctx = newContext(100, 100) ctx.fillStyle = rgba(255, 255, 0, 255) ctx.image.fill(rgba(0, 255, 255, 255)) ctx.fillEllipse(vec2(50, 50), 25, 25) - ctx.image.writeFile("tests/images/drawEllipse.png") + ctx.image.diffVs("tests/images/drawEllipse.png") block: let ctx = newContext(100, 100) @@ -109,14 +109,14 @@ block: ctx.lineWidth = 10 ctx.image.fill(rgba(0, 255, 255, 255)) ctx.strokeEllipse(vec2(50, 50), 25, 25) - ctx.image.writeFile("tests/images/strokeEllipse.png") + ctx.image.diffVs("tests/images/strokeEllipse.png") block: let ctx = newContext(100, 100) ctx.fillStyle = rgba(255, 255, 0, 255) ctx.image.fill(rgba(0, 255, 255, 255)) ctx.fillPolygon(vec2(50, 50), 30, 6) - ctx.image.writeFile("tests/images/drawPolygon.png") + ctx.image.diffVs("tests/images/drawPolygon.png") block: let ctx = newContext(100, 100) @@ -124,7 +124,7 @@ block: ctx.lineWidth = 10 ctx.image.fill(rgba(0, 255, 255, 255)) ctx.strokePolygon(vec2(50, 50), 30, 6) - ctx.image.writeFile("tests/images/strokePolygon.png") + ctx.image.diffVs("tests/images/strokePolygon.png") block: let @@ -134,7 +134,7 @@ block: b.fill(rgba(0, 255, 0, 255)) a.draw(b, translate(vec2(250, 250)) * scale(vec2(0.5, 0.5))) - a.writeFile("tests/images/scaleHalf.png") + a.diffVs("tests/images/scaleHalf.png") block: let @@ -286,7 +286,7 @@ block: strokeImage.strokePath(pathStr, color(1, 1, 1, 1), strokeWidth = 4) image.draw(strokeImage) - image.writeFile("tests/images/fillOptimization.png") + image.diffVs("tests/images/fillOptimization.png") doAssert image[10, 10] == rgbx(255, 127, 63, 255) block: @@ -314,4 +314,4 @@ block: a.draw(b, translate(translation)) - a.writeFile("tests/images/fillOptimization2.png") + a.diffVs("tests/images/fillOptimization2.png") diff --git a/tests/test_masks.nim b/tests/test_masks.nim index 0be2fc1..4dc7fef 100644 --- a/tests/test_masks.nim +++ b/tests/test_masks.nim @@ -1,4 +1,4 @@ -import pixie +import pixie, utils block: let mask = newMask(100, 100) @@ -34,13 +34,13 @@ block: doAssert minified.width == 50 and minified.height == 50 - minified.writeFile("tests/masks/maskMinified.png") + minified.diffVs("tests/masks/maskMinified.png") block: let a = readImage("tests/masks/maskMinified.png") b = a.magnifyBy2() - b.writeFile("tests/masks/maskMagnified.png") + b.diffVs("tests/masks/maskMagnified.png") block: let image = newImage(100, 100) @@ -53,7 +53,7 @@ block: mask.fillPath(path) image.draw(mask) - image.writeFile("tests/masks/circleMask.png") + image.diffVs("tests/masks/circleMask.png") block: let a = newMask(100, 100) @@ -66,7 +66,7 @@ block: b.fillPath(path) a.draw(b) - a.writeFile("tests/masks/maskedMask.png") + a.diffVs("tests/masks/maskedMask.png") block: let a = newMask(100, 100) @@ -79,7 +79,7 @@ block: b.fillPath(path, rgba(0, 0, 0, 255)) a.draw(b) - a.writeFile("tests/masks/imageMaskedMask.png") + a.diffVs("tests/masks/imageMaskedMask.png") block: let path = newPath() @@ -90,7 +90,7 @@ block: a.spread(10) - a.writeFile("tests/masks/spread.png") + a.diffVs("tests/masks/spread.png") block: let path = newPath() @@ -101,7 +101,7 @@ block: a.spread(-5) - a.writeFile("tests/masks/negativeSpread.png") + a.diffVs("tests/masks/negativeSpread.png") block: let mask = newMask(100, 100) @@ -112,7 +112,7 @@ block: mask.fillPath(path) mask.ceil() - mask.writeFile("tests/masks/circleMaskSharpened.png") + mask.diffVs("tests/masks/circleMaskSharpened.png") block: let path = newPath() @@ -120,7 +120,7 @@ block: let mask = newMask(100, 100) mask.fillPath(path) - mask.writeFile("tests/masks/drawRect.png") + mask.diffVs("tests/masks/drawRect.png") block: let path = newPath() @@ -128,7 +128,7 @@ block: let mask = newMask(100, 100) mask.strokePath(path, strokeWidth = 10) - mask.writeFile("tests/masks/strokeRect.png") + mask.diffVs("tests/masks/strokeRect.png") block: let path = newPath() @@ -136,14 +136,14 @@ block: let mask = newMask(100, 100) mask.fillPath(path) - mask.writeFile("tests/masks/drawRoundedRect.png") + mask.diffVs("tests/masks/drawRoundedRect.png") block: let path = newPath() path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10) let mask = newMask(100, 100) mask.strokePath(path, strokeWidth = 10) - mask.writeFile("tests/masks/strokeRoundedRect.png") + mask.diffVs("tests/masks/strokeRoundedRect.png") block: let path = newPath() @@ -152,7 +152,7 @@ block: let mask = newMask(100, 100) mask.strokePath(path, strokeWidth = 10) - mask.writeFile("tests/masks/drawSegment.png") + mask.diffVs("tests/masks/drawSegment.png") block: let path = newPath() @@ -160,7 +160,7 @@ block: let mask = newMask(100, 100) mask.fillPath(path) - mask.writeFile("tests/masks/drawEllipse.png") + mask.diffVs("tests/masks/drawEllipse.png") block: let path = newPath() @@ -168,7 +168,7 @@ block: let mask = newMask(100, 100) mask.strokePath(path, strokeWidth = 10) - mask.writeFile("tests/masks/strokeEllipse.png") + mask.diffVs("tests/masks/strokeEllipse.png") block: let path = newPath() @@ -176,7 +176,7 @@ block: let mask = newMask(100, 100) mask.fillPath(path) - mask.writeFile("tests/masks/drawPolygon.png") + mask.diffVs("tests/masks/drawPolygon.png") block: let path = newPath() @@ -184,7 +184,7 @@ block: let mask = newMask(100, 100) mask.strokepath(path, strokeWidth = 10) - mask.writeFile("tests/masks/strokePolygon.png") + mask.diffVs("tests/masks/strokePolygon.png") block: let path = newPath() @@ -193,7 +193,7 @@ block: let mask = newMask(100, 100) mask.fillpath(path) mask.blur(20) - mask.writeFile("tests/images/maskblur20.png") + mask.diffVs("tests/images/maskblur20.png") block: let path = newPath() @@ -204,7 +204,7 @@ block: mask.blur(25) let minified = mask.minifyBy2() - minified.writeFile("tests/masks/minifiedBlur.png") + minified.diffVs("tests/masks/minifiedBlur.png") block: let path = newPath() @@ -214,4 +214,4 @@ block: mask.fillPath(path) let magnified = mask.magnifyBy2() - magnified.writeFile("tests/masks/drawPolygonMagnified.png") + magnified.diffVs("tests/masks/drawPolygonMagnified.png") diff --git a/tests/test_svg.nim b/tests/test_svg.nim index 9bc7683..4569182 100644 --- a/tests/test_svg.nim +++ b/tests/test_svg.nim @@ -1,4 +1,4 @@ -import pixie, pixie/fileformats/svg, strformat +import pixie, pixie/fileformats/svg, strformat, utils const files = [ "line01", @@ -17,20 +17,23 @@ const files = [ "dragon2" ] -proc doDiff(rendered: Image, name: string) = - rendered.writeFile(&"tests/fileformats/svg/rendered/{name}.png") - let - master = readImage(&"tests/fileformats/svg/masters/{name}.png") - (diffScore, diffImage) = diff(master, rendered) - echo &"{name} score: {diffScore}" - diffImage.writeFile(&"tests/fileformats/svg/diffs/{name}.png") +# proc doDiff(rendered: Image, name: string) = +# rendered.writeFile(&"tests/fileformats/svg/rendered/{name}.png") +# let +# master = readImage(&"tests/fileformats/svg/masters/{name}.png") +# (diffScore, diffImage) = diff(master, rendered) +# echo &"{name} score: {diffScore}" +# diffImage.writeFile(&"tests/fileformats/svg/diffs/{name}.png") for file in files: - doDiff(readImage(&"tests/fileformats/svg/{file}.svg"), file) + let image = readImage(&"tests/fileformats/svg/{file}.svg") + image.diffVs(&"tests/fileformats/svg/masters/{file}.png") block: - let svg = parseSvg( - readFile("tests/fileformats/svg/accessibility-outline.svg"), - 512, 512 - ) - doDiff(newImage(svg), "accessibility-outline") + let + svg = parseSvg( + readFile("tests/fileformats/svg/accessibility-outline.svg"), + 512, 512 + ) + image = newImage(svg) + image.diffVs(&"tests/fileformats/svg/masters/accessibility-outline.png")