Skip to content

Commit 5a5ea5a

Browse files
committed
More tweaks
1 parent 5c3dc30 commit 5a5ea5a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

modules/yup_core/maths/yup_MathsFunctions.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,22 @@ struct MathConstants
176176
static_assert (std::is_floating_point_v<FloatType>, "FloatType can only be a floating point type.");
177177

178178
/** A predefined value for Pi */
179-
static constexpr FloatType pi = static_cast<FloatType> (3.141592653589793238L);
179+
static inline constexpr FloatType pi = static_cast<FloatType> (3.141592653589793238L);
180180

181181
/** A predefined value for 2 * Pi */
182-
static constexpr FloatType twoPi = static_cast<FloatType> (2.0L * 3.141592653589793238L);
182+
static inline constexpr FloatType twoPi = static_cast<FloatType> (2.0L * 3.141592653589793238L);
183183

184184
/** A predefined value for Pi / 2 */
185-
static constexpr FloatType halfPi = static_cast<FloatType> (3.141592653589793238L / 2.0L);
185+
static inline constexpr FloatType halfPi = static_cast<FloatType> (3.141592653589793238L / 2.0L);
186186

187187
/** A predefined value for Euler's number */
188-
static constexpr FloatType euler = static_cast<FloatType> (2.71828182845904523536L);
188+
static inline constexpr FloatType euler = static_cast<FloatType> (2.71828182845904523536L);
189189

190190
/** A predefined value for sqrt (2) */
191-
static constexpr FloatType sqrt2 = static_cast<FloatType> (1.4142135623730950488L);
191+
static inline constexpr FloatType sqrt2 = static_cast<FloatType> (1.4142135623730950488L);
192+
193+
/** A predefined value for 0.5 */
194+
static inline constexpr FloatType half = static_cast<FloatType> (0.5L);
192195
};
193196

194197
/** Converts an angle in degrees to radians. */
@@ -630,11 +633,14 @@ constexpr bool isWithin (Type a, Type b, Type tolerance) noexcept
630633
even numbers will be rounded up or down differently.
631634
*/
632635
template <typename FloatType>
633-
constexpr int roundToInt (const FloatType value) noexcept
636+
constexpr auto roundToInt (const FloatType value) noexcept
637+
-> std::enable_if_t<std::is_floating_point_v<FloatType>, int>
634638
{
635639
if (isConstantEvaluated())
636640
{
637-
return static_cast<int> (value > FloatType (0) ? value + FloatType (0.5) : value - FloatType (0.5));
641+
return static_cast<int> (value > 0
642+
? value + MathConstants<FloatType>::half
643+
: value - MathConstants<FloatType>::half);
638644
}
639645
else
640646
{

modules/yup_python/bindings/yup_YupCore_bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ void registerYupCoreBindings (py::module_& m)
732732
//m.def ("isPositiveAndBelow", &isPositiveAndBelow<?>);
733733
//m.def ("isPositiveAndNotGreaterThan", &isPositiveAndNotGreaterThan<?>);
734734
//m.def ("isWithin", &isWithin<?>);
735-
m.def ("roundToInt", &roundToInt<int>);
735+
m.def ("roundToInt", static_cast<int (*)(int) noexcept> (&roundToInt));
736736
m.def ("roundToInt", &roundToInt<float>);
737737
m.def ("roundToInt", &roundToInt<double>);
738738
m.def ("roundToIntAccurate", &roundToIntAccurate);

0 commit comments

Comments
 (0)