Skip to content

Commit

Permalink
Tests for new function make_aligned_mask
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasparoken committed Aug 23, 2024
1 parent 164b938 commit e7e1dd4
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/doc/grid_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2019 Igara Studio S.A.
// Copyright (c) 2019-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -11,6 +11,8 @@
#include <gtest/gtest.h>

#include "doc/grid.h"
#include "doc/mask.h"
#include "doc/util.h"
#include "gfx/rect_io.h"
#include "gfx/region.h"

Expand Down Expand Up @@ -79,6 +81,78 @@ TEST(Grid, RectWithOffset)
EXPECT_EQ(Rect(1, 1, 1, 1), grid.canvasToTile(Rect(30, 30, 1, 1)));
}

TEST(Grid, MakeAlignedMask)
{
auto grid = Grid::MakeRect(Size(4, 4));
grid.origin(gfx::Point(1,1));
auto mask = Mask();
mask.replace(gfx::Rect(3, 3, 4, 4));
auto gridAlignedMask = make_aligned_mask(&grid, &mask);
EXPECT_EQ(gfx::Rect(1,1,8,8), gridAlignedMask.bounds());

mask.replace(gfx::Rect(1, 1, 4, 4));
auto gridAlignedMask2 = make_aligned_mask(&grid, &mask);
EXPECT_EQ(gfx::Rect(1,1,4,4), gridAlignedMask2.bounds());

mask.add(gfx::Rect(8, 4, 1, 1));
mask.add(gfx::Rect(7, 7, 1, 1));
auto gridAlignedMask3 = make_aligned_mask(&grid, &mask);
bool expected[8*8] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,

0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1,
};
int c=0;
for (int j=0; j<8; ++j)
for (int i=0; i<8; ++i)
EXPECT_EQ(expected[c++], gridAlignedMask3.bitmap()->getPixel(i, j));

mask.replace(gfx::Rect(4, 4, 1, 1));
mask.add(gfx::Rect(5, 5, 1, 1));
mask.add(gfx::Rect(8, 4, 1, 1));
mask.add(gfx::Rect(9, 1, 1, 1));
auto gridAlignedMask4 = make_aligned_mask(&grid, &mask);
bool expected2[12*8] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,

0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
};
c=0;
for (int j=0; j<8; ++j)
for (int i=0; i<12; ++i)
EXPECT_EQ(expected2[c++], gridAlignedMask4.bitmap()->getPixel(i, j));

grid.origin(gfx::Point(2,1));
auto gridAlignedMask5 = make_aligned_mask(&grid, &mask);
bool expected3[8*8] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,

1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0,
};
c=0;
for (int j=0; j<8; ++j)
for (int i=0; i<8; ++i)
EXPECT_EQ(expected3[c++], gridAlignedMask5.bitmap()->getPixel(i, j));
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit e7e1dd4

Please sign in to comment.