mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-12 00:26:22 +00:00
- srb2::math::Fixed
- Operator overloads for FixedMul and FixedDiv
- Implicit conversion between fixed_t, Fixed and
floating-point types
- srb2::math::Vec2
- Template to any type
- Operator overloads for arithmetic operations
- Convertible between different types
- srb2::math::LineSegment
- Template to any type
- Holds two Vec2 instances
- Sorting methods and vertical/horizontal test
- srb2::math::LineEquation
- Slope formula from LineSegment
- y method to find y from x
- Intersect algorithm
- Fixed-point specialization to avoid overflows
- srb2::math::LineEquationX
- Inherits LineEquation
- x method to find x from y
34 lines
890 B
C++
34 lines
890 B
C++
// DR. ROBOTNIK'S RING RACERS
|
|
//-----------------------------------------------------------------------------
|
|
// Copyright (C) 2023 by James Robert Roman
|
|
//
|
|
// This program is free software distributed under the
|
|
// terms of the GNU General Public License, version 2.
|
|
// See the 'LICENSE' file for more details.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef math_traits_hpp
|
|
#define math_traits_hpp
|
|
|
|
#include <cmath>
|
|
#include <type_traits>
|
|
|
|
namespace srb2::math
|
|
{
|
|
|
|
template <typename T, typename = void>
|
|
struct Traits;
|
|
|
|
template <typename T>
|
|
struct Traits<T, std::enable_if_t<std::is_floating_point_v<T>>>
|
|
{
|
|
static constexpr T kZero = 0.0;
|
|
static constexpr T kUnit = 1.0;
|
|
|
|
static T copysign(T x, T y) { return std::copysign(x, y); }
|
|
static T hypot(T x, T y) { return std::hypot(x, y); }
|
|
};
|
|
|
|
}; // namespace srb2::math
|
|
|
|
#endif/*math_traits_hpp*/
|