2017-03-15 22:13:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015-2017 Michele "King_DuckZ" Santullo
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-07-23 21:10:03 +00:00
|
|
|
#include "sample_vectors.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2015-07-25 18:55:52 +00:00
|
|
|
namespace {
|
|
|
|
void test_svec3 (const vwr::svec3& parVec, float parX, float parY, float parZ) {
|
|
|
|
EXPECT_EQ(parVec.x(), parX);
|
|
|
|
EXPECT_EQ(parVec.y(), parY);
|
|
|
|
EXPECT_EQ(parVec.z(), parZ);
|
|
|
|
}
|
2015-07-24 23:52:27 +00:00
|
|
|
|
2015-07-25 18:55:52 +00:00
|
|
|
void test_tvec3 (const vwr::tvec3& parVec, float parX, float parY, float parZ) {
|
|
|
|
EXPECT_EQ(parVec.x(), parX);
|
|
|
|
EXPECT_EQ(parVec.y(), parY);
|
|
|
|
EXPECT_EQ(parVec.z(), parZ);
|
|
|
|
}
|
|
|
|
} //unnamed namespace
|
2015-07-25 17:12:21 +00:00
|
|
|
|
2015-07-23 21:10:03 +00:00
|
|
|
TEST(vwr, conversion) {
|
|
|
|
using namespace vwr;
|
|
|
|
|
|
|
|
{
|
|
|
|
svec1 s(10.0f);
|
|
|
|
EXPECT_EQ(s.x(), 10.0f);
|
2015-07-24 22:55:57 +00:00
|
|
|
|
|
|
|
auto s2 = s.x1();
|
|
|
|
static_assert(std::is_same<decltype(s2), svec2>::value, "Expecting svec2");
|
|
|
|
EXPECT_EQ(s2.x(), s.x());
|
|
|
|
EXPECT_EQ(s2.y(), 1.0f);
|
2015-07-24 23:52:27 +00:00
|
|
|
|
|
|
|
auto s3 = s2.xyn(2.0f);
|
|
|
|
EXPECT_EQ(s3.x(), s2.x());
|
|
|
|
EXPECT_EQ(s3.y(), s2.y());
|
|
|
|
EXPECT_EQ(s3.z(), 2.0f);
|
|
|
|
|
|
|
|
const auto s3_copy(s3);
|
|
|
|
EXPECT_EQ(s3_copy, s3);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
svec3 s3(1.0f);
|
|
|
|
mvec3 m3(s3);
|
|
|
|
EXPECT_EQ(m3.x(), 1.0f);
|
|
|
|
EXPECT_EQ(m3.y(), 1.0f);
|
|
|
|
EXPECT_EQ(m3.z(), 1.0f);
|
|
|
|
EXPECT_EQ(m3.data().x, 1.0f);
|
|
|
|
EXPECT_EQ(m3.data().y, 1.0f);
|
|
|
|
EXPECT_EQ(m3.data().z, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
pvec3 p3(1.0f, 2.0f, 3.0f);
|
|
|
|
test_svec3(p3.cast<svec3>(), p3.x(), p3.y(), p3.z());
|
2015-07-25 17:12:21 +00:00
|
|
|
test_tvec3(p3.cast<tvec3>(), p3.x(), p3.y(), p3.z());
|
2015-07-23 21:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-11 08:45:11 +00:00
|
|
|
|
|
|
|
TEST(vwr, cast) {
|
|
|
|
using namespace vwr;
|
|
|
|
|
|
|
|
svec2 s(10.0f);
|
|
|
|
ivec2 i = static_cast<ivec2>(s);
|
|
|
|
EXPECT_EQ(i.x(), 10);
|
|
|
|
EXPECT_EQ(i.y(), 10);
|
|
|
|
}
|