Browse Source

Minor cleanup, doc++, updated changelog & credits.

pull/435/merge
Vladimír Vondruš 6 years ago
parent
commit
f1c713f4c8
  1. 3
      doc/changelog.dox
  2. 1
      doc/credits.dox
  3. 21
      src/Magnum/Math/Functions.cpp
  4. 15
      src/Magnum/Math/Functions.h
  5. 1
      src/Magnum/Math/Test/FunctionsTest.cpp

3
doc/changelog.dox

@ -64,6 +64,7 @@ See also:
@subsubsection changelog-latest-new-math Math library @subsubsection changelog-latest-new-math Math library
- Added @ref Math::fmod() (see [mosra/magnum#454](https://github.com/mosra/magnum/pull/454)) - Added @ref Math::fmod() (see [mosra/magnum#454](https://github.com/mosra/magnum/pull/454))
- Added @ref Math::binomialCoefficient() (see [mosra/magnum#461](https://github.com/mosra/magnum/pull/461))
@subsection changelog-latest-changes Changes and improvements @subsection changelog-latest-changes Changes and improvements
@ -139,7 +140,7 @@ See also:
@ref Corrade::Containers::ArrayView are now removed. This should have a @ref Corrade::Containers::ArrayView are now removed. This should have a
significant positive effect on compile times of code using the @ref GL, significant positive effect on compile times of code using the @ref GL,
@ref Audio, @ref Trade and @ref Text librariess @ref Audio, @ref Trade and @ref Text librariess
- @ref SceneGraph::Object:addChild() no longer requires the type constructor - @ref SceneGraph::Object::addChild() no longer requires the type constructor
to have the last parameter a parent object object pointer, as that was to have the last parameter a parent object object pointer, as that was
quite limiting. Instead it's calling @ref SceneGraph::Object::setParent() quite limiting. Instead it's calling @ref SceneGraph::Object::setParent()
afterwards. This can cause compilation breakages in case the type afterwards. This can cause compilation breakages in case the type

1
doc/credits.dox

@ -143,6 +143,7 @@ Are the below lists missing your name or something's wrong?
bootstrap project bootstrap project
- **Jan Dupal** ([\@JanDupal](https://github.com/JanDupal)) --- Homebrew - **Jan Dupal** ([\@JanDupal](https://github.com/JanDupal)) --- Homebrew
package for `magnum-bindings` package for `magnum-bindings`
- **[\@Janos95](https://github.com/Janos95)** -- @ref Math additions
- **Jonathan Hale** ([\@Squareys](https://github.com/Squareys)) --- - **Jonathan Hale** ([\@Squareys](https://github.com/Squareys)) ---
@ref Audio and @ref Trade library enhancements, @ref Audio and @ref Trade library enhancements,
@ref Platform::GlfwApplication and @ref Platform::EmscriptenApplication @ref Platform::GlfwApplication and @ref Platform::EmscriptenApplication

21
src/Magnum/Math/Functions.cpp

@ -3,6 +3,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz> 2020 Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2020 janos <janos.meny@googlemail.com>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),
@ -43,19 +44,23 @@ UnsignedInt log2(UnsignedInt number) {
return log; return log;
} }
UnsignedLong binomialCoefficient(const UnsignedInt n, UnsignedInt k) {
if(k > n) return 0;
UnsignedLong binomialCoefficient(UnsignedInt n, UnsignedInt k) { /* k and n - k gives the same value, optimize the calculation to do fewer
if (k > n) return 0; steps */
if (k * 2 > n) if(k*2 > n) k = n - k;
k = n-k;
if (k == 0) return 1; if(k == 0) return 1;
UnsignedLong result = n; UnsignedLong result = n;
for(UnsignedInt i = 2; i <= k; ++i ) { for(UnsignedInt i = 2; i <= k; ++i) {
CORRADE_ASSERT(result < ~UnsignedLong{} / (n-i+1), "Math::binomialCoefficient(): overflow for (" << Corrade::Utility::Debug::nospace << n << "choose" << k << Corrade::Utility::Debug::nospace << ")", 0ul); CORRADE_ASSERT(result < ~UnsignedLong{} / (n-i+1), "Math::binomialCoefficient(): overflow for (" << Corrade::Utility::Debug::nospace << n << "choose" << k << Corrade::Utility::Debug::nospace << ")", {});
result *= (n-i+1);
result *= n - i + 1;
result /= i; result /= i;
} }
return result; return result;
} }

15
src/Magnum/Math/Functions.h

@ -7,6 +7,7 @@
2020 Vladimír Vondruš <mosra@centrum.cz> 2020 Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2020 Nghia Truong <nghiatruong.vn@gmail.com> Copyright © 2020 Nghia Truong <nghiatruong.vn@gmail.com>
Copyright © 2020 Pablo Escobar <mail@rvrs.in> Copyright © 2020 Pablo Escobar <mail@rvrs.in>
Copyright © 2020 janos <janos.meny@googlemail.com>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),
@ -410,14 +411,16 @@ template<std::size_t size, class T> inline Vector<size, T> ceil(const Vector<siz
return out; return out;
} }
/** /**
@brief [Binomial Coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient) @brief [Binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient).
@m_since_latest
Returns the number of combinations of @f$ n @f$ things taken @f$ k @f$ at a time. Returns the number of combinations of @f$ n @f$ things taken @f$ k @f$ at a
The number of ways to do this is given by time, with @f$ n \ge k \ge 0 @f$: @f[
@f[ \begin{pmatrix} n \\ k \end{pmatrix} =
\begin{pmatrix} n \\ k \end{pmatrix} = \frac{n! \cdot (n-k)!}{k!} = \frac{n \cdot (n-1) \cdots (n - k + 1)}{k \cdots 1}. \frac{n! (n - k)!}{k!} =
\frac{n (n - 1) (n - 2) ~ \cdots ~ (n - (k - 1))}{k (k - 1) ~ \cdots ~ 1} =
\prod_{i=1}^k \frac{n + 1 - i}{i}
@f] @f]
*/ */
UnsignedLong MAGNUM_EXPORT binomialCoefficient(UnsignedInt n, UnsignedInt k); UnsignedLong MAGNUM_EXPORT binomialCoefficient(UnsignedInt n, UnsignedInt k);

1
src/Magnum/Math/Test/FunctionsTest.cpp

@ -3,6 +3,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz> 2020 Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2020 janos <janos.meny@googlemail.com>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

Loading…
Cancel
Save