Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
typed-geometry
Commits
05492d65
Commit
05492d65
authored
Oct 25, 2019
by
Philip Trettner
Browse files
replaced TG_NODISCARD with [[nodiscard]]
parent
50aef922
Changes
93
Hide whitespace changes
Inline
Side-by-side
src/typed-geometry/common/scalar_math.hh
View file @
05492d65
...
...
@@ -19,33 +19,33 @@ namespace tg
// ==================================================================
// Classification
TG_NODISCARD
inline
bool
is_nan
(
f32
x
)
{
return
std
::
isnan
(
x
);
}
TG_NODISCARD
inline
bool
is_nan
(
f64
x
)
{
return
std
::
isnan
(
x
);
}
[[
nodiscard
]]
inline
bool
is_nan
(
f32
x
)
{
return
std
::
isnan
(
x
);
}
[[
nodiscard
]]
inline
bool
is_nan
(
f64
x
)
{
return
std
::
isnan
(
x
);
}
TG_NODISCARD
inline
bool
is_zero
(
i8
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
i16
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
i32
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
i64
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
i8
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
i16
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
i32
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
i64
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
u8
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
u16
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
u32
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
u64
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
u8
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
u16
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
u32
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
u64
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
f32
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_zero
(
f64
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
f32
x
)
{
return
x
==
0
;
}
[[
nodiscard
]]
inline
bool
is_zero
(
f64
x
)
{
return
x
==
0
;
}
TG_NODISCARD
inline
bool
is_inf
(
f32
x
)
{
return
std
::
isinf
(
x
);
}
TG_NODISCARD
inline
bool
is_inf
(
f64
x
)
{
return
std
::
isinf
(
x
);
}
[[
nodiscard
]]
inline
bool
is_inf
(
f32
x
)
{
return
std
::
isinf
(
x
);
}
[[
nodiscard
]]
inline
bool
is_inf
(
f64
x
)
{
return
std
::
isinf
(
x
);
}
TG_NODISCARD
inline
bool
is_finite
(
f32
x
)
{
return
std
::
isfinite
(
x
);
}
TG_NODISCARD
inline
bool
is_finite
(
f64
x
)
{
return
std
::
isfinite
(
x
);
}
[[
nodiscard
]]
inline
bool
is_finite
(
f32
x
)
{
return
std
::
isfinite
(
x
);
}
[[
nodiscard
]]
inline
bool
is_finite
(
f64
x
)
{
return
std
::
isfinite
(
x
);
}
TG_NODISCARD
inline
bool
is_normal
(
f32
x
)
{
return
std
::
isnormal
(
x
);
}
TG_NODISCARD
inline
bool
is_normal
(
f64
x
)
{
return
std
::
isnormal
(
x
);
}
[[
nodiscard
]]
inline
bool
is_normal
(
f32
x
)
{
return
std
::
isnormal
(
x
);
}
[[
nodiscard
]]
inline
bool
is_normal
(
f64
x
)
{
return
std
::
isnormal
(
x
);
}
TG_NODISCARD
inline
bool
is_subnormal
(
f32
x
)
{
return
is_finite
(
x
)
&&
!
is_normal
(
x
);
}
TG_NODISCARD
inline
bool
is_subnormal
(
f64
x
)
{
return
is_finite
(
x
)
&&
!
is_normal
(
x
);
}
[[
nodiscard
]]
inline
bool
is_subnormal
(
f32
x
)
{
return
is_finite
(
x
)
&&
!
is_normal
(
x
);
}
[[
nodiscard
]]
inline
bool
is_subnormal
(
f64
x
)
{
return
is_finite
(
x
)
&&
!
is_normal
(
x
);
}
enum
class
fp_class
{
...
...
@@ -56,7 +56,7 @@ enum class fp_class
zero
};
TG_NODISCARD
inline
fp_class
fp_classify
(
f32
x
)
[[
nodiscard
]]
inline
fp_class
fp_classify
(
f32
x
)
{
if
(
is_nan
(
x
))
return
fp_class
::
nan
;
...
...
@@ -69,7 +69,7 @@ TG_NODISCARD inline fp_class fp_classify(f32 x)
else
return
fp_class
::
subnormal
;
}
TG_NODISCARD
inline
fp_class
fp_classify
(
f64
x
)
[[
nodiscard
]]
inline
fp_class
fp_classify
(
f64
x
)
{
if
(
is_nan
(
x
))
return
fp_class
::
nan
;
...
...
@@ -87,70 +87,70 @@ TG_NODISCARD inline fp_class fp_classify(f64 x)
// Basics
// -i8 is i32 consistent with C++
TG_NODISCARD
inline
i32
abs
(
i8
v
)
{
return
v
<
0
?
-
v
:
v
;
}
TG_NODISCARD
inline
i32
abs
(
i16
v
)
{
return
v
<
0
?
-
v
:
v
;
}
TG_NODISCARD
inline
i32
abs
(
i32
v
)
{
return
v
<
0
?
-
v
:
v
;
}
TG_NODISCARD
inline
i64
abs
(
i64
v
)
{
return
v
<
0
?
-
v
:
v
;
}
[[
nodiscard
]]
inline
i32
abs
(
i8
v
)
{
return
v
<
0
?
-
v
:
v
;
}
[[
nodiscard
]]
inline
i32
abs
(
i16
v
)
{
return
v
<
0
?
-
v
:
v
;
}
[[
nodiscard
]]
inline
i32
abs
(
i32
v
)
{
return
v
<
0
?
-
v
:
v
;
}
[[
nodiscard
]]
inline
i64
abs
(
i64
v
)
{
return
v
<
0
?
-
v
:
v
;
}
TG_NODISCARD
inline
u8
abs
(
u8
v
)
{
return
v
;
}
TG_NODISCARD
inline
u16
abs
(
u16
v
)
{
return
v
;
}
TG_NODISCARD
inline
u32
abs
(
u32
v
)
{
return
v
;
}
TG_NODISCARD
inline
u64
abs
(
u64
v
)
{
return
v
;
}
[[
nodiscard
]]
inline
u8
abs
(
u8
v
)
{
return
v
;
}
[[
nodiscard
]]
inline
u16
abs
(
u16
v
)
{
return
v
;
}
[[
nodiscard
]]
inline
u32
abs
(
u32
v
)
{
return
v
;
}
[[
nodiscard
]]
inline
u64
abs
(
u64
v
)
{
return
v
;
}
TG_NODISCARD
inline
f8
abs
(
f8
v
)
{
return
v
;
}
TG_NODISCARD
inline
f16
abs
(
f16
v
)
{
return
std
::
abs
(
v
);
}
TG_NODISCARD
inline
f32
abs
(
f32
v
)
{
return
std
::
abs
(
v
);
}
TG_NODISCARD
inline
f64
abs
(
f64
v
)
{
return
std
::
abs
(
v
);
}
[[
nodiscard
]]
inline
f8
abs
(
f8
v
)
{
return
v
;
}
[[
nodiscard
]]
inline
f16
abs
(
f16
v
)
{
return
std
::
abs
(
v
);
}
[[
nodiscard
]]
inline
f32
abs
(
f32
v
)
{
return
std
::
abs
(
v
);
}
[[
nodiscard
]]
inline
f64
abs
(
f64
v
)
{
return
std
::
abs
(
v
);
}
template
<
class
T
>
TG_NODISCARD
angle_t
<
T
>
abs
(
angle_t
<
T
>
a
)
[[
nodiscard
]]
angle_t
<
T
>
abs
(
angle_t
<
T
>
a
)
{
return
radians
(
abs
(
a
.
radians
()));
}
TG_NODISCARD
inline
f32
floor
(
f32
v
)
{
return
std
::
floor
(
v
);
}
TG_NODISCARD
inline
f64
floor
(
f64
v
)
{
return
std
::
floor
(
v
);
}
TG_NODISCARD
inline
i32
ifloor
(
f32
v
)
{
return
v
>=
0
||
f32
(
i32
(
v
))
==
v
?
i32
(
v
)
:
i32
(
v
)
-
1
;
}
TG_NODISCARD
inline
i64
ifloor
(
f64
v
)
{
return
v
>=
0
||
f64
(
i64
(
v
))
==
v
?
i64
(
v
)
:
i64
(
v
)
-
1
;
}
[[
nodiscard
]]
inline
f32
floor
(
f32
v
)
{
return
std
::
floor
(
v
);
}
[[
nodiscard
]]
inline
f64
floor
(
f64
v
)
{
return
std
::
floor
(
v
);
}
[[
nodiscard
]]
inline
i32
ifloor
(
f32
v
)
{
return
v
>=
0
||
f32
(
i32
(
v
))
==
v
?
i32
(
v
)
:
i32
(
v
)
-
1
;
}
[[
nodiscard
]]
inline
i64
ifloor
(
f64
v
)
{
return
v
>=
0
||
f64
(
i64
(
v
))
==
v
?
i64
(
v
)
:
i64
(
v
)
-
1
;
}
TG_NODISCARD
inline
f32
ceil
(
f32
v
)
{
return
std
::
ceil
(
v
);
}
TG_NODISCARD
inline
f64
ceil
(
f64
v
)
{
return
std
::
ceil
(
v
);
}
TG_NODISCARD
inline
i32
iceil
(
f32
v
)
{
return
v
<=
0
||
f32
(
i32
(
v
))
==
v
?
i32
(
v
)
:
i32
(
v
)
+
1
;
}
TG_NODISCARD
inline
i64
iceil
(
f64
v
)
{
return
v
<=
0
||
f64
(
i64
(
v
))
==
v
?
i64
(
v
)
:
i64
(
v
)
+
1
;
}
[[
nodiscard
]]
inline
f32
ceil
(
f32
v
)
{
return
std
::
ceil
(
v
);
}
[[
nodiscard
]]
inline
f64
ceil
(
f64
v
)
{
return
std
::
ceil
(
v
);
}
[[
nodiscard
]]
inline
i32
iceil
(
f32
v
)
{
return
v
<=
0
||
f32
(
i32
(
v
))
==
v
?
i32
(
v
)
:
i32
(
v
)
+
1
;
}
[[
nodiscard
]]
inline
i64
iceil
(
f64
v
)
{
return
v
<=
0
||
f64
(
i64
(
v
))
==
v
?
i64
(
v
)
:
i64
(
v
)
+
1
;
}
TG_NODISCARD
inline
f32
round
(
f32
v
)
{
return
std
::
round
(
v
);
}
TG_NODISCARD
inline
f64
round
(
f64
v
)
{
return
std
::
round
(
v
);
}
TG_NODISCARD
inline
i32
iround
(
f32
v
)
{
return
v
>=
0
?
i32
(
v
+
0.5
f
)
:
i32
(
v
-
0.5
f
);
}
TG_NODISCARD
inline
i64
iround
(
f64
v
)
{
return
v
>=
0
?
i64
(
v
+
0.5
)
:
i64
(
v
-
0.5
);
}
[[
nodiscard
]]
inline
f32
round
(
f32
v
)
{
return
std
::
round
(
v
);
}
[[
nodiscard
]]
inline
f64
round
(
f64
v
)
{
return
std
::
round
(
v
);
}
[[
nodiscard
]]
inline
i32
iround
(
f32
v
)
{
return
v
>=
0
?
i32
(
v
+
0.5
f
)
:
i32
(
v
-
0.5
f
);
}
[[
nodiscard
]]
inline
i64
iround
(
f64
v
)
{
return
v
>=
0
?
i64
(
v
+
0.5
)
:
i64
(
v
-
0.5
);
}
TG_NODISCARD
inline
f32
fract
(
f32
v
)
{
return
v
-
floor
(
v
);
}
TG_NODISCARD
inline
f64
fract
(
f64
v
)
{
return
v
-
floor
(
v
);
}
[[
nodiscard
]]
inline
f32
fract
(
f32
v
)
{
return
v
-
floor
(
v
);
}
[[
nodiscard
]]
inline
f64
fract
(
f64
v
)
{
return
v
-
floor
(
v
);
}
template
<
class
A
,
class
B
>
TG_NODISCARD
constexpr
auto
min
(
A
&&
a
,
B
&&
b
)
->
decltype
(
a
<
b
?
a
:
b
)
[[
nodiscard
]]
constexpr
auto
min
(
A
&&
a
,
B
&&
b
)
->
decltype
(
a
<
b
?
a
:
b
)
{
return
a
<
b
?
a
:
b
;
}
template
<
class
A
,
class
B
>
TG_NODISCARD
constexpr
auto
max
(
A
&&
a
,
B
&&
b
)
->
decltype
(
a
<
b
?
b
:
a
)
[[
nodiscard
]]
constexpr
auto
max
(
A
&&
a
,
B
&&
b
)
->
decltype
(
a
<
b
?
b
:
a
)
{
return
a
<
b
?
b
:
a
;
}
template
<
class
A
,
class
B
,
class
C
>
TG_NODISCARD
constexpr
auto
clamp
(
A
const
&
a
,
B
const
&
min_value
,
C
const
&
max_value
)
->
decltype
(
min
(
max
(
a
,
min_value
),
max_value
))
[[
nodiscard
]]
constexpr
auto
clamp
(
A
const
&
a
,
B
const
&
min_value
,
C
const
&
max_value
)
->
decltype
(
min
(
max
(
a
,
min_value
),
max_value
))
{
return
min
(
max
(
a
,
min_value
),
max_value
);
}
template
<
class
T
>
TG_NODISCARD
constexpr
T
saturate
(
T
const
&
a
)
[[
nodiscard
]]
constexpr
T
saturate
(
T
const
&
a
)
{
return
clamp
(
a
,
T
(
0
),
T
(
1
));
}
template
<
class
T
,
class
=
enable_if
<
is_scalar
<
T
>
>>
TG_NODISCARD
constexpr
T
sign
(
T
const
&
v
)
[[
nodiscard
]]
constexpr
T
sign
(
T
const
&
v
)
{
// TODO: optimize?
// if constexpr (!is_unsigned_integer<T>)
...
...
@@ -164,109 +164,109 @@ TG_NODISCARD constexpr T sign(T const& v)
// ==================================================================
// Powers
TG_NODISCARD
inline
f32
pow
(
f32
b
,
f32
e
)
{
return
std
::
pow
(
b
,
e
);
}
TG_NODISCARD
inline
f32
pow
(
f32
b
,
i32
e
)
{
return
f32
(
std
::
pow
(
b
,
e
));
}
TG_NODISCARD
inline
f64
pow
(
f64
b
,
f64
e
)
{
return
std
::
pow
(
b
,
e
);
}
TG_NODISCARD
inline
f64
pow
(
f64
b
,
i32
e
)
{
return
std
::
pow
(
b
,
e
);
}
[[
nodiscard
]]
inline
f32
pow
(
f32
b
,
f32
e
)
{
return
std
::
pow
(
b
,
e
);
}
[[
nodiscard
]]
inline
f32
pow
(
f32
b
,
i32
e
)
{
return
f32
(
std
::
pow
(
b
,
e
));
}
[[
nodiscard
]]
inline
f64
pow
(
f64
b
,
f64
e
)
{
return
std
::
pow
(
b
,
e
);
}
[[
nodiscard
]]
inline
f64
pow
(
f64
b
,
i32
e
)
{
return
std
::
pow
(
b
,
e
);
}
template
<
class
T
>
TG_NODISCARD
constexpr
auto
pow2
(
T
const
&
v
)
->
decltype
(
v
*
v
)
[[
nodiscard
]]
constexpr
auto
pow2
(
T
const
&
v
)
->
decltype
(
v
*
v
)
{
return
v
*
v
;
}
template
<
class
T
>
TG_NODISCARD
constexpr
auto
pow3
(
T
const
&
v
)
->
decltype
(
v
*
v
*
v
)
[[
nodiscard
]]
constexpr
auto
pow3
(
T
const
&
v
)
->
decltype
(
v
*
v
*
v
)
{
return
v
*
v
*
v
;
}
template
<
class
T
>
TG_NODISCARD
constexpr
auto
pow4
(
T
const
&
v
)
->
decltype
((
v
*
v
)
*
(
v
*
v
))
[[
nodiscard
]]
constexpr
auto
pow4
(
T
const
&
v
)
->
decltype
((
v
*
v
)
*
(
v
*
v
))
{
auto
const
v2
=
v
*
v
;
return
v2
*
v2
;
}
template
<
class
T
>
TG_NODISCARD
constexpr
auto
pow5
(
T
const
&
v
)
->
decltype
((
v
*
v
)
*
(
v
*
v
)
*
v
)
[[
nodiscard
]]
constexpr
auto
pow5
(
T
const
&
v
)
->
decltype
((
v
*
v
)
*
(
v
*
v
)
*
v
)
{
auto
const
v2
=
v
*
v
;
return
v2
*
v2
*
v
;
}
TG_NODISCARD
inline
f32
sqrt
(
f32
v
)
{
return
std
::
sqrt
(
v
);
}
TG_NODISCARD
inline
f64
sqrt
(
f64
v
)
{
return
std
::
sqrt
(
v
);
}
[[
nodiscard
]]
inline
f32
sqrt
(
f32
v
)
{
return
std
::
sqrt
(
v
);
}
[[
nodiscard
]]
inline
f64
sqrt
(
f64
v
)
{
return
std
::
sqrt
(
v
);
}
// TODO: _mm_rsqrt_ss
TG_NODISCARD
inline
f32
rsqrt
(
f32
v
)
{
return
1
/
std
::
sqrt
(
v
);
}
TG_NODISCARD
inline
f64
rsqrt
(
f64
v
)
{
return
1
/
std
::
sqrt
(
v
);
}
[[
nodiscard
]]
inline
f32
rsqrt
(
f32
v
)
{
return
1
/
std
::
sqrt
(
v
);
}
[[
nodiscard
]]
inline
f64
rsqrt
(
f64
v
)
{
return
1
/
std
::
sqrt
(
v
);
}
TG_NODISCARD
inline
f32
cbrt
(
f32
v
)
{
return
std
::
cbrt
(
v
);
}
TG_NODISCARD
inline
f64
cbrt
(
f64
v
)
{
return
std
::
cbrt
(
v
);
}
[[
nodiscard
]]
inline
f32
cbrt
(
f32
v
)
{
return
std
::
cbrt
(
v
);
}
[[
nodiscard
]]
inline
f64
cbrt
(
f64
v
)
{
return
std
::
cbrt
(
v
);
}
// ==================================================================
// Exponentials
TG_NODISCARD
inline
f32
exp
(
f32
v
)
{
return
std
::
exp
(
v
);
}
TG_NODISCARD
inline
f64
exp
(
f64
v
)
{
return
std
::
exp
(
v
);
}
[[
nodiscard
]]
inline
f32
exp
(
f32
v
)
{
return
std
::
exp
(
v
);
}
[[
nodiscard
]]
inline
f64
exp
(
f64
v
)
{
return
std
::
exp
(
v
);
}
TG_NODISCARD
inline
f32
exp2
(
f32
v
)
{
return
std
::
exp2
(
v
);
}
TG_NODISCARD
inline
f64
exp2
(
f64
v
)
{
return
std
::
exp2
(
v
);
}
[[
nodiscard
]]
inline
f32
exp2
(
f32
v
)
{
return
std
::
exp2
(
v
);
}
[[
nodiscard
]]
inline
f64
exp2
(
f64
v
)
{
return
std
::
exp2
(
v
);
}
TG_NODISCARD
inline
f32
log
(
f32
v
)
{
return
std
::
log
(
v
);
}
TG_NODISCARD
inline
f64
log
(
f64
v
)
{
return
std
::
log
(
v
);
}
[[
nodiscard
]]
inline
f32
log
(
f32
v
)
{
return
std
::
log
(
v
);
}
[[
nodiscard
]]
inline
f64
log
(
f64
v
)
{
return
std
::
log
(
v
);
}
TG_NODISCARD
inline
f32
log2
(
f32
v
)
{
return
std
::
log2
(
v
);
}
TG_NODISCARD
inline
f64
log2
(
f64
v
)
{
return
std
::
log2
(
v
);
}
[[
nodiscard
]]
inline
f32
log2
(
f32
v
)
{
return
std
::
log2
(
v
);
}
[[
nodiscard
]]
inline
f64
log2
(
f64
v
)
{
return
std
::
log2
(
v
);
}
TG_NODISCARD
inline
f32
log10
(
f32
v
)
{
return
std
::
log10
(
v
);
}
TG_NODISCARD
inline
f64
log10
(
f64
v
)
{
return
std
::
log10
(
v
);
}
[[
nodiscard
]]
inline
f32
log10
(
f32
v
)
{
return
std
::
log10
(
v
);
}
[[
nodiscard
]]
inline
f64
log10
(
f64
v
)
{
return
std
::
log10
(
v
);
}
// ==================================================================
// Trigonometry
TG_NODISCARD
inline
f32
sin
(
angle_t
<
f32
>
v
)
{
return
std
::
sin
(
v
.
radians
());
}
TG_NODISCARD
inline
f64
sin
(
angle_t
<
f64
>
v
)
{
return
std
::
sin
(
v
.
radians
());
}
TG_NODISCARD
inline
f32
cos
(
angle_t
<
f32
>
v
)
{
return
std
::
cos
(
v
.
radians
());
}
TG_NODISCARD
inline
f64
cos
(
angle_t
<
f64
>
v
)
{
return
std
::
cos
(
v
.
radians
());
}
TG_NODISCARD
inline
f32
tan
(
angle_t
<
f32
>
v
)
{
return
std
::
tan
(
v
.
radians
());
}
TG_NODISCARD
inline
f64
tan
(
angle_t
<
f64
>
v
)
{
return
std
::
tan
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f32
sin
(
angle_t
<
f32
>
v
)
{
return
std
::
sin
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f64
sin
(
angle_t
<
f64
>
v
)
{
return
std
::
sin
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f32
cos
(
angle_t
<
f32
>
v
)
{
return
std
::
cos
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f64
cos
(
angle_t
<
f64
>
v
)
{
return
std
::
cos
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f32
tan
(
angle_t
<
f32
>
v
)
{
return
std
::
tan
(
v
.
radians
());
}
[[
nodiscard
]]
inline
f64
tan
(
angle_t
<
f64
>
v
)
{
return
std
::
tan
(
v
.
radians
());
}
// TODO: use SSE intrinsic to compute both directly
TG_NODISCARD
inline
pair
<
f32
,
f32
>
sin_cos
(
angle_t
<
f32
>
v
)
{
return
{
sin
(
v
),
cos
(
v
)};
}
TG_NODISCARD
inline
pair
<
f64
,
f64
>
sin_cos
(
angle_t
<
f64
>
v
)
{
return
{
sin
(
v
),
cos
(
v
)};
}
TG_NODISCARD
inline
angle_t
<
f32
>
asin
(
f32
v
)
{
return
radians
(
std
::
asin
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f64
>
asin
(
f64
v
)
{
return
radians
(
std
::
asin
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f32
>
acos
(
f32
v
)
{
return
radians
(
std
::
acos
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f64
>
acos
(
f64
v
)
{
return
radians
(
std
::
acos
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f32
>
atan
(
f32
v
)
{
return
radians
(
std
::
atan
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f64
>
atan
(
f64
v
)
{
return
radians
(
std
::
atan
(
v
));
}
TG_NODISCARD
inline
angle_t
<
f32
>
atan2
(
f32
y
,
f32
x
)
{
return
radians
(
std
::
atan2
(
y
,
x
));
}
TG_NODISCARD
inline
angle_t
<
f64
>
atan2
(
f64
y
,
f64
x
)
{
return
radians
(
std
::
atan2
(
y
,
x
));
}
TG_NODISCARD
inline
f32
sinh
(
f32
v
)
{
return
std
::
sinh
(
v
);
}
TG_NODISCARD
inline
f64
sinh
(
f64
v
)
{
return
std
::
sinh
(
v
);
}
TG_NODISCARD
inline
f32
cosh
(
f32
v
)
{
return
std
::
cosh
(
v
);
}
TG_NODISCARD
inline
f64
cosh
(
f64
v
)
{
return
std
::
cosh
(
v
);
}
TG_NODISCARD
inline
f32
tanh
(
f32
v
)
{
return
std
::
tanh
(
v
);
}
TG_NODISCARD
inline
f64
tanh
(
f64
v
)
{
return
std
::
tanh
(
v
);
}
TG_NODISCARD
inline
f32
asinh
(
f32
v
)
{
return
std
::
asinh
(
v
);
}
TG_NODISCARD
inline
f64
asinh
(
f64
v
)
{
return
std
::
asinh
(
v
);
}
TG_NODISCARD
inline
f32
acosh
(
f32
v
)
{
return
std
::
acosh
(
v
);
}
TG_NODISCARD
inline
f64
acosh
(
f64
v
)
{
return
std
::
acosh
(
v
);
}
TG_NODISCARD
inline
f32
atanh
(
f32
v
)
{
return
std
::
atanh
(
v
);
}
TG_NODISCARD
inline
f64
atanh
(
f64
v
)
{
return
std
::
atanh
(
v
);
}
[[
nodiscard
]]
inline
pair
<
f32
,
f32
>
sin_cos
(
angle_t
<
f32
>
v
)
{
return
{
sin
(
v
),
cos
(
v
)};
}
[[
nodiscard
]]
inline
pair
<
f64
,
f64
>
sin_cos
(
angle_t
<
f64
>
v
)
{
return
{
sin
(
v
),
cos
(
v
)};
}
[[
nodiscard
]]
inline
angle_t
<
f32
>
asin
(
f32
v
)
{
return
radians
(
std
::
asin
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f64
>
asin
(
f64
v
)
{
return
radians
(
std
::
asin
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f32
>
acos
(
f32
v
)
{
return
radians
(
std
::
acos
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f64
>
acos
(
f64
v
)
{
return
radians
(
std
::
acos
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f32
>
atan
(
f32
v
)
{
return
radians
(
std
::
atan
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f64
>
atan
(
f64
v
)
{
return
radians
(
std
::
atan
(
v
));
}
[[
nodiscard
]]
inline
angle_t
<
f32
>
atan2
(
f32
y
,
f32
x
)
{
return
radians
(
std
::
atan2
(
y
,
x
));
}
[[
nodiscard
]]
inline
angle_t
<
f64
>
atan2
(
f64
y
,
f64
x
)
{
return
radians
(
std
::
atan2
(
y
,
x
));
}
[[
nodiscard
]]
inline
f32
sinh
(
f32
v
)
{
return
std
::
sinh
(
v
);
}
[[
nodiscard
]]
inline
f64
sinh
(
f64
v
)
{
return
std
::
sinh
(
v
);
}
[[
nodiscard
]]
inline
f32
cosh
(
f32
v
)
{
return
std
::
cosh
(
v
);
}
[[
nodiscard
]]
inline
f64
cosh
(
f64
v
)
{
return
std
::
cosh
(
v
);
}
[[
nodiscard
]]
inline
f32
tanh
(
f32
v
)
{
return
std
::
tanh
(
v
);
}
[[
nodiscard
]]
inline
f64
tanh
(
f64
v
)
{
return
std
::
tanh
(
v
);
}
[[
nodiscard
]]
inline
f32
asinh
(
f32
v
)
{
return
std
::
asinh
(
v
);
}
[[
nodiscard
]]
inline
f64
asinh
(
f64
v
)
{
return
std
::
asinh
(
v
);
}
[[
nodiscard
]]
inline
f32
acosh
(
f32
v
)
{
return
std
::
acosh
(
v
);
}
[[
nodiscard
]]
inline
f64
acosh
(
f64
v
)
{
return
std
::
acosh
(
v
);
}
[[
nodiscard
]]
inline
f32
atanh
(
f32
v
)
{
return
std
::
atanh
(
v
);
}
[[
nodiscard
]]
inline
f64
atanh
(
f64
v
)
{
return
std
::
atanh
(
v
);
}
// ==================================================================
// other GLSL
TG_NODISCARD
constexpr
f32
smoothstep
(
f32
edge0
,
f32
edge1
,
f32
x
)
[[
nodiscard
]]
constexpr
f32
smoothstep
(
f32
edge0
,
f32
edge1
,
f32
x
)
{
auto
t
=
clamp
((
x
-
edge0
)
/
(
edge1
-
edge0
),
f32
(
0
),
f32
(
1
));
return
t
*
t
*
(
f32
(
3
)
-
f32
(
2
)
*
t
);
}
TG_NODISCARD
constexpr
f64
smoothstep
(
f64
edge0
,
f64
edge1
,
f64
x
)
[[
nodiscard
]]
constexpr
f64
smoothstep
(
f64
edge0
,
f64
edge1
,
f64
x
)
{
auto
t
=
clamp
((
x
-
edge0
)
/
(
edge1
-
edge0
),
f64
(
0
),
f64
(
1
));
return
t
*
t
*
(
f64
(
3
)
-
f64
(
2
)
*
t
);
...
...
src/typed-geometry/common/swizzling.hh
View file @
05492d65
...
...
@@ -16,9 +16,9 @@ struct base_swizzle_proxy
using
comp_t
=
CompTemplate
<
D
,
ScalarT
>
;
using
other_comp_t
=
CompTemplate
<
sizeof
...(
Indices
),
ScalarT
>
;
TG_NODISCARD
constexpr
operator
other_comp_t
()
const
{
return
other_comp_t
(
ref
[
Indices
]...);
}
[[
nodiscard
]]
constexpr
operator
other_comp_t
()
const
{
return
other_comp_t
(
ref
[
Indices
]...);
}
template
<
class
OtherT
>
TG_NODISCARD
explicit
constexpr
operator
OtherT
()
const
[[
nodiscard
]]
explicit
constexpr
operator
OtherT
()
const
{
return
OtherT
(
ref
[
Indices
]...);
}
...
...
@@ -67,7 +67,7 @@ struct swizzler
{
// directly apply swizzling
template
<
template
<
int
,
class
>
class
CompT
,
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
CompT
<
sizeof
...(
Indices
),
ScalarT
>
const
operator
()(
CompT
<
D
,
ScalarT
>
const
&
v
)
const
[[
nodiscard
]]
constexpr
CompT
<
sizeof
...(
Indices
),
ScalarT
>
const
operator
()(
CompT
<
D
,
ScalarT
>
const
&
v
)
const
{
#if !defined(_MSC_VER) || _MSC_VER >= 1920
static_assert
((...
&&
(
0
<=
Indices
&&
Indices
<
D
)),
"swizzle index out of range"
);
...
...
@@ -77,22 +77,22 @@ struct swizzler
// return proxy object to allow assignment
template
<
template
<
int
,
class
>
class
CompT
,
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
detail
::
mutable_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>&
v
)
const
[[
nodiscard
]]
constexpr
detail
::
mutable_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>&
v
)
const
{
return
detail
::
mutable_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
(
v
);
}
template
<
template
<
int
,
class
>
class
CompT
,
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
detail
::
const_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>
const
&
v
)
const
[[
nodiscard
]]
constexpr
detail
::
const_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>
const
&
v
)
const
{
return
detail
::
const_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
(
v
);
}
template
<
template
<
int
,
class
>
class
CompT
,
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>&&
v
)
const
[[
nodiscard
]]
constexpr
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>&&
v
)
const
{
return
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
(
static_cast
<
CompT
<
D
,
ScalarT
>&&>
(
v
));
}
template
<
template
<
int
,
class
>
class
CompT
,
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>
const
&&
v
)
const
[[
nodiscard
]]
constexpr
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
operator
[](
CompT
<
D
,
ScalarT
>
const
&&
v
)
const
{
return
detail
::
owning_swizzle_proxy
<
CompT
,
D
,
ScalarT
,
Indices
...
>
(
v
);
}
...
...
src/typed-geometry/detail/macros.hh
View file @
05492d65
...
...
@@ -55,8 +55,6 @@
#define TG_FORCE_SEMICOLON static_assert(true)
// currently a macro because clang-format interacts badly with it
#define TG_NODISCARD [[nodiscard]]
// =========
// operations and classes
...
...
@@ -125,17 +123,17 @@
#define TG_DECLARE_SELF_SWIZZLE(TYPE) \
template <int... Indices> \
TG_NODISCARD
constexpr auto operator[](swizzler<Indices...> const& swizzle) \
[[nodiscard]]
constexpr auto operator[](swizzler<Indices...> const& swizzle) \
{ \
return swizzle[*this]; \
} \
template <int... Indices> \
TG_NODISCARD
constexpr auto operator[](swizzler<Indices...> const& swizzle) const \
[[nodiscard]]
constexpr auto operator[](swizzler<Indices...> const& swizzle) const \
{ \
return swizzle[*this]; \
} \
template <int... Indices> \
TG_NODISCARD
constexpr TYPE<sizeof...(Indices), ScalarT> const operator()(swizzler<Indices...> const& swizzle) const \
[[nodiscard]]
constexpr TYPE<sizeof...(Indices), ScalarT> const operator()(swizzler<Indices...> const& swizzle) const \
{ \
return swizzle(*this); \
} \
...
...
@@ -241,7 +239,7 @@
#define TG_IMPL_DEFINE_UNARY_OP(TYPE, OP) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr TYPE<D, ScalarT> operator OP(TYPE<D, ScalarT> const& a) \
[[nodiscard]]
constexpr TYPE<D, ScalarT> operator OP(TYPE<D, ScalarT> const& a) \
{ \
if constexpr (D == 1) \
return {OP a.TG_IMPL_MEMBER(TYPE, 0)}; \
...
...
@@ -258,7 +256,7 @@
#define TG_IMPL_DEFINE_BINARY_OP(TYPE_A, TYPE_B, TYPE_R, OP) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr TYPE_R<D, ScalarT> operator OP(TYPE_A<D, ScalarT> const& a, TYPE_B<D, ScalarT> const& b) \
[[nodiscard]]
constexpr TYPE_R<D, ScalarT> operator OP(TYPE_A<D, ScalarT> const& a, TYPE_B<D, ScalarT> const& b) \
{ \
if constexpr (D == 1) \
return {a.TG_IMPL_MEMBER(TYPE_A, 0) OP b.TG_IMPL_MEMBER(TYPE_B, 0)}; \
...
...
@@ -281,7 +279,7 @@
#define TG_IMPL_DEFINE_BINARY_OP_SCALAR_RIGHT(TYPE, OP) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr TYPE<D, ScalarT> operator OP(TYPE<D, ScalarT> const& a, dont_deduce<ScalarT> const& b) \
[[nodiscard]]
constexpr TYPE<D, ScalarT> operator OP(TYPE<D, ScalarT> const& a, dont_deduce<ScalarT> const& b) \
{ \
if constexpr (D == 1) \
return {a.TG_IMPL_MEMBER(TYPE, 0) OP b}; \
...
...
@@ -298,7 +296,7 @@
#define TG_IMPL_DEFINE_BINARY_OP_SCALAR_LEFT(TYPE, OP) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr TYPE<D, ScalarT> operator OP(dont_deduce<ScalarT> const& a, TYPE<D, ScalarT> const& b) \
[[nodiscard]]
constexpr TYPE<D, ScalarT> operator OP(dont_deduce<ScalarT> const& a, TYPE<D, ScalarT> const& b) \
{ \
if constexpr (D == 1) \
return {a OP b.TG_IMPL_MEMBER(TYPE, 0)}; \
...
...
@@ -317,7 +315,7 @@
/* scalar / type */
\
TG_IMPL_DEFINE_BINARY_OP_SCALAR_LEFT(TYPE, /); \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr TYPE<D, ScalarT> operator/(TYPE<D, ScalarT> const& a, dont_deduce<ScalarT> const& b) \
[[nodiscard]]
constexpr TYPE<D, ScalarT> operator/(TYPE<D, ScalarT> const& a, dont_deduce<ScalarT> const& b) \
{ \
if constexpr (is_floating_point<ScalarT>) \
return a * ScalarT(1 / b); \
...
...
@@ -340,7 +338,7 @@
#define TG_IMPL_DEFINE_COMPWISE_UNARY_TO_COMP(TYPE, FUN) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr auto FUN(TYPE<D, ScalarT> const& a) \
[[nodiscard]]
constexpr auto FUN(TYPE<D, ScalarT> const& a) \
{ \
using R = remove_const_ref<decltype(FUN(a.TG_IMPL_MEMBER(TYPE, 0)))>; \
\
...
...
@@ -363,7 +361,7 @@
#define TG_IMPL_DEFINE_COMPWISE_FUNC_UNARY(TYPE, FUN) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr auto FUN(TYPE<D, ScalarT> const& a) \
[[nodiscard]]
constexpr auto FUN(TYPE<D, ScalarT> const& a) \
{ \
using R = remove_const_ref<decltype(FUN(a.TG_IMPL_MEMBER(TYPE, 0)))>; \
\
...
...
@@ -386,7 +384,7 @@
#define TG_IMPL_DEFINE_COMPWISE_FUNC_BINARY(TYPE, FUN) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr auto FUN(TYPE<D, ScalarT> const& a, TYPE<D, ScalarT> const& b) \
[[nodiscard]]
constexpr auto FUN(TYPE<D, ScalarT> const& a, TYPE<D, ScalarT> const& b) \
{ \
using R = remove_const_ref<decltype(FUN(a.TG_IMPL_MEMBER(TYPE, 0), b.TG_IMPL_MEMBER(TYPE, 0)))>; \
\
...
...
@@ -411,7 +409,7 @@
#define TG_IMPL_DEFINE_COMPWISE_FUNC_TERNARY(TYPE, FUN) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr auto FUN(TYPE<D, ScalarT> const& a, TYPE<D, ScalarT> const& b, TYPE<D, ScalarT> const& c) \
[[nodiscard]]
constexpr auto FUN(TYPE<D, ScalarT> const& a, TYPE<D, ScalarT> const& b, TYPE<D, ScalarT> const& c) \
{ \
using R = remove_const_ref<decltype(FUN(a.TG_IMPL_MEMBER(TYPE, 0), b.TG_IMPL_MEMBER(TYPE, 0), c.TG_IMPL_MEMBER(TYPE, 0)))>; \
\
...
...
@@ -440,7 +438,7 @@
#define TG_IMPL_DEFINE_REDUCTION_OP_BINARY(TYPE_A, TYPE_B, RESULT_T, NAME, REDUCE, OP) \
template <int D, class ScalarT> \
TG_NODISCARD
constexpr RESULT_T NAME(TYPE_A<D, ScalarT> const& a, TYPE_B<D, ScalarT> const& b) \
[[nodiscard]]
constexpr RESULT_T NAME(TYPE_A<D, ScalarT> const& a, TYPE_B<D, ScalarT> const& b) \
{ \
if constexpr (D == 1) \
return a.TG_IMPL_MEMBER(TYPE_A, 0) OP b.TG_IMPL_MEMBER(TYPE_B, 0); \
...
...
src/typed-geometry/detail/operators/ops_angle.hh
View file @
05492d65
...
...
@@ -7,46 +7,46 @@
namespace
tg
{
template
<
class
T
>
TG_NODISCARD
constexpr
angle_t
<
T
>
operator
-
(
angle_t
<
T
>
const
&
a
)
[[
nodiscard
]]
constexpr
angle_t
<
T
>
operator
-
(
angle_t
<
T
>
const
&
a
)
{
return
radians
(
-
a
.
radians
());
}
template
<
class
T
>
TG_NODISCARD
constexpr
angle_t
<
T
>
operator
+
(
angle_t
<
T
>
const
&
a
)
[[
nodiscard
]]
constexpr
angle_t
<
T
>
operator
+
(
angle_t
<
T
>
const
&
a
)
{
return
a
;
}
template
<
class
T
>
TG_NODISCARD
constexpr
angle_t
<
T
>
operator
+
(
angle_t
<
T
>
a
,
angle_t
<
T
>
b
)
[[
nodiscard
]]
constexpr
angle_t
<
T
>
operator
+
(
angle_t
<
T
>
a
,
angle_t
<
T
>
b
)
{
return
radians
(
a
.
radians
()
+
b
.
radians
());
}
template
<
class
T
>
TG_NODISCARD
constexpr
angle_t
<
T
>
operator
-
(
angle_t
<
T
>
a
,
angle_t
<
T
>
b
)
[[
nodiscard
]]
constexpr
angle_t
<
T
>
operator
-
(
angle_t
<
T
>
a
,
angle_t
<
T
>
b
)
{
return
radians
(
a
.
radians
()
-
b
.
radians
());
}
template
<
class
T
>
TG_NODISCARD
constexpr
angle_t
<
T
>
operator
*
(
angle_t
<
T
>
a
,
dont_deduce
<
T
>
b
)
[[
nodiscard
]]
constexpr
angle_t
<
T
>
operator
*
(
angle_t
<
T
>
a
,
dont_deduce
<
T
>
b
)