Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TFraction.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/math_fwd.h"
4
5#include <Common/assertion.h>
6#include <Common/primitive_type.h>
7
8#include <utility>
9#include <type_traits>
10
11namespace ph::math
12{
13
14template<typename T>
15class TFraction final
16{
17public:
18 constexpr inline TFraction() = default;
19 constexpr TFraction(T nume, T deno);
20
21 // TODO: arithemtics
22
23 template<typename U = real>
24 constexpr U toReal() const;
25
26 template<typename U>
27 constexpr explicit operator U () const;
28
29private:
30 T m_nume;
31 T m_deno;
32};
33
34// In-header Implementations:
35
36template<typename T>
37inline constexpr TFraction<T>::TFraction(T nume, T deno) :
38 m_nume(std::move(nume)),
39 m_deno(std::move(deno))
40{}
41
42template<typename T>
43template<typename U>
44inline constexpr U TFraction<T>::toReal() const
45{
46 static_assert(std::is_floating_point_v<U>);
47
48 return m_nume / m_deno;
49}
50
51template<typename T>
52template<typename U>
53inline constexpr TFraction<T>::operator U () const
54{
55 return toReal<U>();
56}
57
58}// end namespace ph::math
Definition TFraction.h:16
constexpr TFraction()=default
constexpr U toReal() const
Definition TFraction.h:44
Math functions and utilities.
Definition TransformInfo.h:10
Definition TAABB2D.h:96