2018-08-25 21:10:52 +08:00
|
|
|
// (C) Copyright 2017, Google Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2018-08-24 21:07:48 +08:00
|
|
|
|
2018-08-25 21:10:52 +08:00
|
|
|
#include "blobs.h"
|
|
|
|
#include "normalis.h"
|
|
|
|
|
|
|
|
#include "include_gunit.h"
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DENORMTest : public testing::Test {
|
2019-05-17 00:12:06 +08:00
|
|
|
protected:
|
|
|
|
void SetUp() {
|
|
|
|
std::locale::global(std::locale(""));
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
2019-05-17 00:12:06 +08:00
|
|
|
public:
|
2018-09-29 15:19:13 +08:00
|
|
|
void TearDown() {}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
void ExpectCorrectTransform(const DENORM& denorm, const TPOINT& src,
|
|
|
|
const TPOINT& result, bool local) {
|
|
|
|
TPOINT normed;
|
|
|
|
if (local)
|
|
|
|
denorm.LocalNormTransform(src, &normed);
|
|
|
|
else
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm.NormTransform(nullptr, src, &normed);
|
2018-08-24 21:07:48 +08:00
|
|
|
EXPECT_EQ(result.x, normed.x);
|
|
|
|
EXPECT_EQ(result.y, normed.y);
|
|
|
|
// Now undo
|
|
|
|
TPOINT denormed;
|
|
|
|
if (local)
|
|
|
|
denorm.LocalDenormTransform(normed, &denormed);
|
|
|
|
else
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm.DenormTransform(nullptr, normed, &denormed);
|
2018-08-24 21:07:48 +08:00
|
|
|
EXPECT_EQ(src.x, denormed.x);
|
|
|
|
EXPECT_EQ(src.y, denormed.y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Tests a simple baseline-style normalization.
|
|
|
|
TEST_F(DENORMTest, NoRotations) {
|
|
|
|
DENORM denorm;
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
|
2018-08-24 21:07:48 +08:00
|
|
|
0.0f, static_cast<float>(kBlnBaselineOffset));
|
|
|
|
TPOINT pt1(1100, 2000);
|
|
|
|
TPOINT result1(200, kBlnBaselineOffset);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, true);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, false);
|
|
|
|
TPOINT pt2(900, 2100);
|
|
|
|
TPOINT result2(-200, 300 + kBlnBaselineOffset);
|
|
|
|
ExpectCorrectTransform(denorm, pt2, result2, true);
|
|
|
|
ExpectCorrectTransform(denorm, pt2, result2, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a simple baseline-style normalization with a rotation.
|
|
|
|
TEST_F(DENORMTest, WithRotations) {
|
|
|
|
DENORM denorm;
|
|
|
|
FCOORD rotation90(0.0f, 1.0f);
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm.SetupNormalization(nullptr, &rotation90, nullptr, 1000.0f, 2000.0f, 2.0f,
|
2018-09-29 15:19:13 +08:00
|
|
|
3.0f, 0.0f, static_cast<float>(kBlnBaselineOffset));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
TPOINT pt1(1100, 2000);
|
|
|
|
TPOINT result1(0, 200 + kBlnBaselineOffset);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, true);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, false);
|
|
|
|
TPOINT pt2(900, 2100);
|
|
|
|
TPOINT result2(-300, kBlnBaselineOffset - 200);
|
|
|
|
ExpectCorrectTransform(denorm, pt2, result2, true);
|
|
|
|
ExpectCorrectTransform(denorm, pt2, result2, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a simple baseline-style normalization with a second rotation & scale.
|
|
|
|
TEST_F(DENORMTest, Multiple) {
|
|
|
|
DENORM denorm;
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
|
2018-08-24 21:07:48 +08:00
|
|
|
0.0f, static_cast<float>(kBlnBaselineOffset));
|
|
|
|
|
|
|
|
DENORM denorm2;
|
|
|
|
FCOORD rotation90(0.0f, 1.0f);
|
2018-09-29 15:27:12 +08:00
|
|
|
denorm2.SetupNormalization(nullptr, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
|
2018-09-29 15:19:13 +08:00
|
|
|
0.25f, 0.0f, 0.0f);
|
2018-08-24 21:07:48 +08:00
|
|
|
TPOINT pt1(1050, 2000);
|
|
|
|
TPOINT result1(100, kBlnBaselineOffset);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, true);
|
|
|
|
ExpectCorrectTransform(denorm, pt1, result1, false);
|
|
|
|
TPOINT result2(kBlnBaselineOffset / 4, -14);
|
|
|
|
ExpectCorrectTransform(denorm2, result1, result2, true);
|
|
|
|
ExpectCorrectTransform(denorm2, pt1, result2, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace.
|