/*
 * 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.
 */

#include "vectorwrapper/vectorwrapper.hpp"
#include <gtest/gtest.h>
#include <cstddef>

struct Point {
	int x, y;
};
struct Line {
	int x, y, z;
};
struct Hyperline {
	int x, y, z, w;
};

namespace vwr {
	template <>
	struct VectorWrapperInfo<Point> {
        enum { dimensions = 2 };

        typedef int scalar_type;
        typedef Point vector_type;

        typedef Line higher_vector_type;

        enum {
			offset_x = offsetof(vector_type, x),
			offset_y = offsetof(vector_type, y)
        };
	};
	template <>
	struct VectorWrapperInfo<Line> {
        enum { dimensions = 3 };

        typedef int scalar_type;
        typedef Line vector_type;

        typedef Point lower_vector_type;
        typedef Hyperline higher_vector_type;

        enum {
			offset_x = offsetof(vector_type, x),
			offset_y = offsetof(vector_type, y),
			offset_z = offsetof(vector_type, z)
        };
	};
	template <>
	struct VectorWrapperInfo<Hyperline> {
        enum { dimensions = 4 };

        typedef int scalar_type;
        typedef Hyperline vector_type;

        typedef Line lower_vector_type;

        enum {
			offset_x = offsetof(vector_type, x),
			offset_y = offsetof(vector_type, y),
			offset_z = offsetof(vector_type, z),
			offset_w = offsetof(vector_type, w)
        };
	};
} //namespace vwr

using vec2 = vwr::Vec<Point>;
using vec3 = vwr::Vec<Line>;
using vec4 = vwr::Vec<Hyperline>;

TEST(vwr, offset_get_at) {
	{
		vec2 v(300000, 400000);
		EXPECT_EQ(v.data().x, 300000);
		EXPECT_EQ(v.data().y, 400000);
		EXPECT_EQ(v.x(), 300000);
		EXPECT_EQ(v.y(), 400000);
		v.x()++;
		v.y()++;
		EXPECT_EQ(v.data().x, 300001);
		EXPECT_EQ(v.data().y, 400001);
		EXPECT_EQ(v.x(), 300001);
		EXPECT_EQ(v.y(), 400001);
	}

	{
		vec3 v(330000, 440000, 550000);
		EXPECT_EQ(v.data().x, 330000);
		EXPECT_EQ(v.data().y, 440000);
		EXPECT_EQ(v.data().z, 550000);
		EXPECT_EQ(v.x(), 330000);
		EXPECT_EQ(v.y(), 440000);
		EXPECT_EQ(v.z(), 550000);
		v.x()++;
		v.y()++;
		v.z()++;
		EXPECT_EQ(v.data().x, 330001);
		EXPECT_EQ(v.data().y, 440001);
		EXPECT_EQ(v.data().z, 550001);
		EXPECT_EQ(v.x(), 330001);
		EXPECT_EQ(v.y(), 440001);
		EXPECT_EQ(v.z(), 550001);
	}

	{
		vec4 v(333000, 444000, 555000, 666000);
		EXPECT_EQ(v.data().x, 333000);
		EXPECT_EQ(v.data().y, 444000);
		EXPECT_EQ(v.data().z, 555000);
		EXPECT_EQ(v.data().w, 666000);
		EXPECT_EQ(v.x(), 333000);
		EXPECT_EQ(v.y(), 444000);
		EXPECT_EQ(v.z(), 555000);
		EXPECT_EQ(v.w(), 666000);
		v.x()++;
		v.y()++;
		v.z()++;
		v.w()++;
		EXPECT_EQ(v.data().x, 333001);
		EXPECT_EQ(v.data().y, 444001);
		EXPECT_EQ(v.data().z, 555001);
		EXPECT_EQ(v.data().w, 666001);
		EXPECT_EQ(v.x(), 333001);
		EXPECT_EQ(v.y(), 444001);
		EXPECT_EQ(v.z(), 555001);
		EXPECT_EQ(v.w(), 666001);
	}
}
