Skip to content

Commit

Permalink
Add diagonal and 8-quadrant symmetry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasparoken committed Sep 19, 2024
1 parent 95d88cb commit d7b5408
Showing 1 changed file with 151 additions and 4 deletions.
155 changes: 151 additions & 4 deletions tests/scripts/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(0, 0, 8, 3))
expect_img(cel.image,
{ 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 })
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 })

local b = Brush { size=1 }
app.fgColor = c
Expand Down Expand Up @@ -457,7 +457,7 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(0, 0, 8, 3))
expect_img(cel.image,
{ 0, c, 0, 0, 0, 0, c, 0,
c, c, c, 0, 0, c, c, c,
c, c, c, 0, 0, c, c, c,
0, c, 0, 0, 0, 0, c, 0 })
app.undo()

Expand All @@ -467,7 +467,7 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(1, 0, 6, 3))
expect_img(cel.image,
{ 0, c, 0, 0, c, 0,
c, c, c, c, c, c,
c, c, c, c, c, c,
0, c, 0, 0, c, 0 })
app.undo()

Expand Down Expand Up @@ -524,6 +524,153 @@ do
ColorMode.RGB, rgba(255, 0, 0))
end

----------------------------------------------------------------------
-- diagonal and 8-quadrant symmetry tests
----------------------------------------------------------------------
do
local s = Sprite(8, 8, ColorMode.INDEXED)
local c = 1
cel = s.cels[1]
expect_eq(cel.bounds, Rectangle(0, 0, 8, 8))
expect_img(cel.image,
{ 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 })

-- Enable symmetry
local pref = app.preferences
local docPref = pref.document(s)
pref.symmetry_mode.enabled = true
docPref.symmetry.mode = 4 -- RIGHT_DIAG = 4,
docPref.symmetry.x_axis = 4
local b = Brush{ type=BrushType.LINE, size=3, angle=45}
app.fgColor = c
app.useTool{ tool=pencil, brush=b, points={ Point(2, 1) } }
expect_eq(cel.bounds, Rectangle(1, 0, 7, 7))
expect_img(cel.image,
{ 0, 0, c, 0, 0, 0, 0,
0, c, 0, 0, 0, 0, 0,
c, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, c,
0, 0, 0, 0, 0, c, 0,
0, 0, 0, 0, c, 0, 0 })
app.undo()
docPref.symmetry.mode = 8 -- LEFT_DIAG = 8,
app.useTool{ tool=pencil, brush=b, points={ Point(6, 2) } }
expect_eq(cel.bounds, Rectangle(1, 1, 7, 7))
expect_img(cel.image,
{ 0, 0, 0, 0, 0, 0, c,
0, 0, 0, 0, 0, c, 0,
0, 0, 0, 0, c, 0, 0,
0, 0, 0, 0, 0, 0, 0,

0, 0, c, 0, 0, 0, 0,
0, c, 0, 0, 0, 0, 0,
c, 0, 0, 0, 0, 0, 0 })
app.undo()

docPref.symmetry.mode = 12 -- BOTH_DIAG = 12,
app.useTool{ tool=pencil, brush=b, points={ Point(5, 1) } }
expect_eq(cel.bounds, Rectangle(0, 0, 8, 8))
expect_img(cel.image,
{ 0, 0, 0, 0, 0, 0, c, 0,
0, 0, 0, 0, 0, c, 0, c,
0, 0, 0, 0, c, 0, c, 0,
0, 0, 0, 0, 0, c, 0, 0,

0, 0, c, 0, 0, 0, 0, 0,
0, c, 0, c, 0, 0, 0, 0,
c, 0, c, 0, 0, 0, 0, 0,
0, c, 0, 0, 0, 0, 0, 0 })

-- symmetry with image brush tests
local brushImg = Image(3, 2, ColorMode.INDEXED)
array_to_pixels({ 1, 2, 3,
0, 1, 2 }, brushImg)
local bru = Brush { image=brushImg }
s = Sprite(12, 12, ColorMode.INDEXED)
cel = s.cels[1]
local p = s.palettes[1]
p:setColor(1, Color { r=255, g=0, b=0, a=255 })
p:setColor(2, Color { r=0, g=255, b=0, a=255 })
p:setColor(3, Color { r=0, g=0, b=255, a=255 })
-- Enable symmetry
pref = app.preferences
docPref = pref.document(s)
docPref.symmetry.mode = 15 -- ALL = 15,
app.useTool{ tool=pencil, brush=bru, points={ Point(4, 2) } }
expect_eq(cel.bounds, Rectangle(1, 1, 10, 10))
expect_img(cel.image,
{ 0, 0, 1, 2, 3, 3, 2, 1, 0, 0,
0, 0, 0, 1, 2, 2, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
2, 1, 0, 0, 0, 0, 0, 0, 1, 2,
3, 2, 0, 0, 0, 0, 0, 0, 2, 3,

3, 2, 0, 0, 0, 0, 0, 0, 2, 3,
2, 1, 0, 0, 0, 0, 0, 0, 1, 2,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 2, 2, 1, 0, 0, 0,
0, 0, 1, 2, 3, 3, 2, 1, 0, 0 })
app.undo()

docPref.symmetry.x_axis = 5.5
app.useTool{ tool=pencil, brush=bru, points={ Point(4, 2) } }
expect_eq(cel.bounds, Rectangle(1, 1, 9, 10))
expect_img(cel.image,
{ 0, 0, 1, 2, 3, 2, 1, 0, 0,
0, 0, 0, 1, 2, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 1,
2, 1, 0, 0, 0, 0, 0, 1, 2,
3, 2, 0, 0, 0, 0, 0, 2, 3,

3, 2, 0, 0, 0, 0, 0, 2, 3,
2, 1, 0, 0, 0, 0, 0, 1, 2,
1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 2, 1, 0, 0, 0,
0, 0, 1, 2, 3, 2, 1, 0, 0 })
app.undo()

docPref.symmetry.x_axis = 5.5
docPref.symmetry.y_axis = 5.5
app.useTool{ tool=pencil, brush=bru, points={ Point(4, 2) } }
expect_eq(cel.bounds, Rectangle(1, 1, 9, 9))
expect_img(cel.image,
{ 0, 0, 1, 2, 3, 2, 1, 0, 0,
0, 0, 0, 1, 2, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 1,
2, 1, 0, 0, 0, 0, 0, 1, 2,
3, 2, 0, 0, 0, 0, 0, 2, 3,
2, 1, 0, 0, 0, 0, 0, 1, 2,
1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 2, 1, 0, 0, 0,
0, 0, 1, 2, 3, 2, 1, 0, 0 })
app.undo()

docPref.symmetry.x_axis = 6
docPref.symmetry.y_axis = 5.5
app.useTool{ tool=pencil, brush=bru, points={ Point(4, 2) } }
expect_eq(cel.bounds, Rectangle(1, 1, 10, 9))
expect_img(cel.image,
{ 0, 0, 1, 2, 3, 3, 2, 1, 0, 0,
0, 0, 0, 1, 2, 2, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
2, 1, 0, 0, 0, 0, 0, 0, 1, 2,
3, 2, 0, 0, 0, 0, 0, 0, 2, 3,
2, 1, 0, 0, 0, 0, 0, 0, 1, 2,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 2, 2, 1, 0, 0, 0,
0, 0, 1, 2, 3, 3, 2, 1, 0, 0 })
end

----------------------------------------------------------------------
-- useTool in a transaction
----------------------------------------------------------------------
Expand Down

0 comments on commit d7b5408

Please sign in to comment.