Magic_Game/core/math/scalar.hpp

90 lines
3.0 KiB
C++
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <cmath>
2018-03-01 00:19:09 +08:00
#if _MSC_VER >= 1900
# define E2D_CONSTEXPR constexpr
#else
# define E2D_CONSTEXPR const
#endif
2018-11-08 00:21:59 +08:00
namespace easy2d
2018-03-01 00:19:09 +08:00
{
namespace math
2018-11-08 00:21:59 +08:00
{
namespace constants
{
E2D_CONSTEXPR auto PIf = 3.14159265358979f;
E2D_CONSTEXPR auto PId = 3.14159265358979323846;
}
inline int Abs(int val) { return ::abs(val); }
2018-03-01 00:19:09 +08:00
inline float Abs(float val) { return ::fabsf(val); }
2018-03-01 00:19:09 +08:00
inline double Abs(double val) { return ::fabs(val); }
2018-05-22 23:36:46 +08:00
inline float Sqrt(float val) { return ::sqrtf(val); }
2018-03-01 00:19:09 +08:00
inline double Sqrt(double val) { return ::sqrt(val); }
2018-03-01 00:19:09 +08:00
inline int Sign(int val) { return val < 0 ? -1 : 1; }
2018-03-01 00:19:09 +08:00
inline float Sign(float val) { return val < 0 ? -1.f : 1.f; }
2018-03-01 00:19:09 +08:00
inline double Sign(double val) { return val < 0 ? -1.0 : 1.0; }
inline float Sin(float val) { return ::sinf(val * constants::PIf / 180.f); }
inline double Sin(double val) { return ::sin(val * constants::PId / 180.0); }
2018-05-22 22:55:06 +08:00
inline float Cos(float val) { return ::cosf(val * constants::PIf / 180.f); }
inline double Cos(double val) { return ::cos(val * constants::PId / 180.0); }
inline float Tan(float val) { return ::tanf(val * constants::PIf / 180.f); }
inline double Tan(double val) { return ::tan(val * constants::PId / 180.0); }
2018-11-20 13:48:49 +08:00
inline float Asin(float val) { return ::asinf(val) * 180.f / constants::PIf; }
inline double Asin(double val) { return ::asin(val) * 180.f / constants::PIf; }
inline float Acos(float val) { return ::acosf(val) * 180.f / constants::PIf; }
inline double Acos(double val) { return ::acos(val) * 180.f / constants::PIf; }
inline float Atan(float val) { return ::atanf(val) * 180.f / constants::PIf; }
inline double Atan(double val) { return ::atan(val) * 180.f / constants::PIf; }
2018-11-11 16:47:15 +08:00
inline float Ceil(float val) { return ::ceil(val); }
2018-11-11 16:47:15 +08:00
inline double Ceil(double val) { return ::ceil(val); }
2018-11-11 16:47:15 +08:00
inline float Floor(float val) { return ::floor(val); }
2018-11-11 16:47:15 +08:00
inline double Floor(double val) { return ::floor(val); }
2018-11-08 00:21:59 +08:00
}
}