/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see .
*/
#ifndef ANTKEEPER_MATH_VECTOR_TYPE_HPP
#define ANTKEEPER_MATH_VECTOR_TYPE_HPP
#include
namespace math {
/**
* An `N`-dimensional Euclidean vector.
*
* @tparam T Scalar type.
* @tparam N Number of dimensions.
*/
template
struct vector
{
typedef T element_type;
element_type elements[N];
inline constexpr element_type& operator[](std::size_t i) noexcept { return elements[i]; }
inline constexpr const element_type& operator[](std::size_t i) const noexcept { return elements[i]; }
inline constexpr const element_type* data() const noexcept { return elements; };
inline constexpr element_type* data() noexcept { return elements; };
inline constexpr std::size_t size() const noexcept { return N; };
};
template
struct vector
{
typedef T element_type;
union
{
element_type elements[1];
struct
{
element_type x;
};
};
inline constexpr element_type& operator[](std::size_t i) noexcept { return elements[i]; }
inline constexpr const element_type& operator[](std::size_t i) const noexcept { return elements[i]; }
inline constexpr const element_type* data() const noexcept { return elements; };
inline constexpr element_type* data() noexcept { return elements; };
inline constexpr std::size_t size() const noexcept { return 1; };
};
template
struct vector
{
typedef T element_type;
union
{
element_type elements[2];
struct
{
element_type x;
element_type y;
};
};
inline constexpr element_type& operator[](std::size_t i) noexcept { return elements[i]; }
inline constexpr const element_type& operator[](std::size_t i) const noexcept { return elements[i]; }
inline constexpr const element_type* data() const noexcept { return elements; };
inline constexpr element_type* data() noexcept { return elements; };
inline constexpr std::size_t size() const noexcept { return 2; };
};
template
struct vector
{
typedef T element_type;
union
{
element_type elements[3];
struct
{
element_type x;
element_type y;
element_type z;
};
};
inline constexpr element_type& operator[](std::size_t i) noexcept { return elements[i]; }
inline constexpr const element_type& operator[](std::size_t i) const noexcept { return elements[i]; }
inline constexpr const element_type* data() const noexcept { return elements; };
inline constexpr element_type* data() noexcept { return elements; };
inline constexpr std::size_t size() const noexcept { return 3; };
};
template
struct vector
{
typedef T element_type;
union
{
element_type elements[4];
struct
{
element_type x;
element_type y;
element_type z;
element_type w;
};
};
inline constexpr element_type& operator[](std::size_t i) noexcept { return elements[i]; }
inline constexpr const element_type& operator[](std::size_t i) const noexcept { return elements[i]; }
inline constexpr const element_type* data() const noexcept { return elements; };
inline constexpr element_type* data() noexcept { return elements; };
inline constexpr std::size_t size() const noexcept { return 4; };
};
/// 2D vector.
template
using vector2 = vector;
/// 3D vector.
template
using vector3 = vector;
/// 4D vector.
template
using vector4 = vector;
} // namespace math
#endif // ANTKEEPER_MATH_VECTOR_TYPE_HPP