/*! \file maths.c * \brief Math helper functions. */ /* * Copyright (c) Sebastian Krzyszkowiak * * This program 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. * * This program 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 this program. If not, see . */ #include "maths.h" #include "config.h" #include "internal.h" #include #include #include #include #include SYMBOL_EXPORT double VectorLength(double x, double y, double z) { return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2)); } SYMBOL_EXPORT double Wrap(double left, double right, double val) { return left + fmod(val - left, right - left); } SYMBOL_EXPORT double Clamp(double left, double right, double val) { if (val > right) { return right; } if (val < left) { return left; } return val; } SYMBOL_EXPORT double Lerp(double left, double right, double pos) { return left + (right - left) * pos; } SYMBOL_EXPORT double Sign(double val) { return val / fabs(val); } SYMBOL_EXPORT double Fract(double val) { return val - floor(val); }