/* * Copyright (C) 2020 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_HPP #define ANTKEEPER_MATH_HPP #include #include #include using namespace vmq::operators; inline float frand(float start, float end) { float f = (float)std::rand() / RAND_MAX; return start + f * (end - start); } namespace math { /** * Reinterprets data as an `N`-dimensional vector of type `T`. * * @tparam N Number of vector dimensions. * @tparam T Scalar type. * @param data Data to reinterpret. */ template inline vmq::vector& as_vector(T& data) { static_assert(std::is_pod>::value); return reinterpret_cast&>(data); } /** * Reinterprets data as an `NxM` matrix of type `T`. * * @tparam N Number of columns. * @tparam M Number of rows. * @tparam T Element type. * @param data Data to reinterpret. */ template inline vmq::matrix& as_matrix(T& data) { static_assert(std::is_pod>::value); return reinterpret_cast&>(data); } template vmq::vector project_on_plane(const vmq::vector& v, const vmq::vector& p, const vmq::vector& n) { return v - n * vmq::dot(v - p, n); } } // namespace math #endif // ANTKEEPER_MATH_HPP