mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.1 KiB
99 lines
3.1 KiB
|
14 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
14 years ago
|
|
||
|
13 years ago
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
|
#include <sstream>
|
||
|
14 years ago
|
#include <TestSuite/Tester.h>
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#include "Math/Range.h"
|
||
|
14 years ago
|
#include "TextureTools/Atlas.h"
|
||
|
|
|
||
|
|
namespace Magnum { namespace TextureTools { namespace Test {
|
||
|
|
|
||
|
13 years ago
|
class AtlasTest: public TestSuite::Tester {
|
||
|
14 years ago
|
public:
|
||
|
|
explicit AtlasTest();
|
||
|
|
|
||
|
|
void create();
|
||
|
13 years ago
|
void createPadding();
|
||
|
14 years ago
|
void createEmpty();
|
||
|
|
void createTooSmall();
|
||
|
|
};
|
||
|
|
|
||
|
14 years ago
|
AtlasTest::AtlasTest() {
|
||
|
13 years ago
|
addTests({&AtlasTest::create,
|
||
|
|
&AtlasTest::createPadding,
|
||
|
|
&AtlasTest::createEmpty,
|
||
|
|
&AtlasTest::createTooSmall});
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
void AtlasTest::create() {
|
||
|
13 years ago
|
std::vector<Range2Di> atlas = TextureTools::atlas({64, 64}, {
|
||
|
14 years ago
|
{12, 18},
|
||
|
|
{32, 15},
|
||
|
|
{23, 25}
|
||
|
|
});
|
||
|
|
|
||
|
|
CORRADE_COMPARE(atlas.size(), 3);
|
||
|
13 years ago
|
CORRADE_COMPARE(atlas, (std::vector<Range2Di>{
|
||
|
|
Range2Di::fromSize({0, 0}, {12, 18}),
|
||
|
|
Range2Di::fromSize({32, 0}, {32, 15}),
|
||
|
|
Range2Di::fromSize({0, 25}, {23, 25})}));
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void AtlasTest::createPadding() {
|
||
|
13 years ago
|
std::vector<Range2Di> atlas = TextureTools::atlas({64, 64}, {
|
||
|
13 years ago
|
{8, 16},
|
||
|
|
{28, 13},
|
||
|
|
{19, 23}
|
||
|
|
}, {2, 1});
|
||
|
|
|
||
|
|
CORRADE_COMPARE(atlas.size(), 3);
|
||
|
13 years ago
|
CORRADE_COMPARE(atlas, (std::vector<Range2Di>{
|
||
|
|
Range2Di::fromSize({2, 1}, {8, 16}),
|
||
|
|
Range2Di::fromSize({34, 1}, {28, 13}),
|
||
|
|
Range2Di::fromSize({2, 26}, {19, 23})}));
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void AtlasTest::createEmpty() {
|
||
|
13 years ago
|
std::vector<Range2Di> atlas = TextureTools::atlas({}, std::vector<Vector2i>{});
|
||
|
14 years ago
|
CORRADE_VERIFY(atlas.empty());
|
||
|
|
}
|
||
|
|
|
||
|
|
void AtlasTest::createTooSmall() {
|
||
|
|
std::ostringstream o;
|
||
|
|
Error::setOutput(&o);
|
||
|
|
|
||
|
13 years ago
|
std::vector<Range2Di> atlas = TextureTools::atlas({64, 32}, {
|
||
|
13 years ago
|
{8, 16},
|
||
|
|
{21, 13},
|
||
|
|
{19, 29}
|
||
|
|
}, {2, 1});
|
||
|
14 years ago
|
CORRADE_VERIFY(atlas.empty());
|
||
|
13 years ago
|
CORRADE_COMPARE(o.str(), "TextureTools::atlas(): requested atlas size Vector(64, 32) is too small to fit 3 Vector(25, 31) textures. Generated atlas will be empty.\n");
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
}}}
|
||
|
14 years ago
|
|
||
|
|
CORRADE_TEST_MAIN(Magnum::TextureTools::Test::AtlasTest)
|