Browse Source

Added MathConstants::halfPi to improve readability

tags/2021-05-28
jules 8 years ago
parent
commit
d727f2a35a
10 changed files with 38 additions and 27 deletions
  1. +1
    -1
      examples/audio plugin host/Source/GraphEditorPanel.cpp
  2. +1
    -1
      extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp
  3. +9
    -1
      modules/juce_core/maths/juce_MathsFunctions.h
  4. +10
    -9
      modules/juce_dsp/filter_design/juce_FilterDesign.cpp
  5. +6
    -4
      modules/juce_dsp/maths/juce_SpecialFunctions.cpp
  6. +1
    -1
      modules/juce_dsp/processors/juce_LadderFilter.cpp
  7. +2
    -2
      modules/juce_graphics/geometry/juce_Path.cpp
  8. +1
    -1
      modules/juce_gui_basics/drawables/juce_SVGParser.cpp
  9. +3
    -3
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
  10. +4
    -4
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp

+ 1
- 1
examples/audio plugin host/Source/GraphEditorPanel.cpp View File

@@ -509,7 +509,7 @@ struct GraphEditorPanel::ConnectorComponent : public Component,
arrowL, 0.0f);
arrow.applyTransform (AffineTransform()
.rotated (MathConstants<float>::pi * 0.5f - (float) atan2 (p2.x - p1.x, p2.y - p1.y))
.rotated (MathConstants<float>::halfPi - (float) atan2 (p2.x - p1.x, p2.y - p1.y))
.translated ((p1 + p2) * 0.5f));
linePath.addPath (arrow);


+ 1
- 1
extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp View File

@@ -461,7 +461,7 @@ Path ProjucerLookAndFeel::getArrowPath (Rectangle<float> arrowZone, const int di
if (filled)
path.closeSubPath();
path.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi / 2.0f),
path.applyTransform (AffineTransform::rotation (direction * MathConstants<float>::halfPi,
arrowZone.getCentreX(), arrowZone.getCentreY()));
return path;


+ 9
- 1
modules/juce_core/maths/juce_MathsFunctions.h View File

@@ -326,7 +326,6 @@ inline int64 abs64 (const int64 n) noexcept
#endif
//==============================================================================
#if JUCE_HAS_CONSTEXPR
/** Commonly used mathematical constants */
@@ -339,6 +338,9 @@ struct MathConstants
/** A predefined value for 2 * Pi */
static constexpr FloatType twoPi = static_cast<FloatType> (2 * 3.141592653589793238L);
/** A predefined value for Pi / 2 */
static constexpr FloatType halfPi = static_cast<FloatType> (3.141592653589793238L / 2);
/** A predfined value for Euler's number */
static constexpr FloatType euler = static_cast<FloatType> (2.71828182845904523536L);
};
@@ -355,6 +357,9 @@ struct MathConstants
/** A predefined value for 2 * Pi */
static const FloatType twoPi;
/** A predefined value for Pi / 2 */
static const FloatType halfPi;
/** A predfined value for Euler's number */
static const FloatType euler;
};
@@ -365,6 +370,9 @@ const FloatType MathConstants<FloatType>::pi = static_cast<FloatType> (3.1415926
template <typename FloatType>
const FloatType MathConstants<FloatType>::twoPi = static_cast<FloatType> (2 * 3.141592653589793238L);
template <typename FloatType>
const FloatType MathConstants<FloatType>::halfPi = static_cast<FloatType> (3.141592653589793238L / 2);
template <typename FloatType>
const FloatType MathConstants<FloatType>::euler = static_cast<FloatType> (2.71828182845904523536L);


+ 10
- 9
modules/juce_dsp/filter_design/juce_FilterDesign.cpp View File

@@ -407,6 +407,7 @@ Array<IIR::Coefficients<FloatType>>
auto omegap = std::tan (MathConstants<double>::pi * fp);
auto omegas = std::tan (MathConstants<double>::pi * fs);
constexpr auto halfPi = MathConstants<double>::halfPi;
auto k = omegap / omegas;
auto k1 = epsp / epss;
@@ -446,35 +447,35 @@ Array<IIR::Coefficients<FloatType>>
for (int i = 1; i <= L; ++i)
{
auto ui = (2 * i - 1.0) / (double) N;
pa.add (omegap * std::pow (epsp, -1.0 / (double) N) * j * exp (ui * 0.5 * MathConstants<double>::pi * j));
pa.add (omegap * std::pow (epsp, -1.0 / (double) N) * j * exp (ui * halfPi * j));
}
}
else if (type == 1)
{
auto v0 = std::asinh (1.0 / epsp) / (0.5 * N * MathConstants<double>::pi);
auto v0 = std::asinh (1.0 / epsp) / (N * halfPi);
if (r == 1)
pa.add (-omegap * std::sinh (v0 * 0.5 * MathConstants<double>::pi));
pa.add (-omegap * std::sinh (v0 * halfPi));
for (int i = 1; i <= L; ++i)
{
auto ui = (2 * i - 1.0) / (double) N;
pa.add (omegap * j * std::cos ((ui - j * v0) * 0.5 * MathConstants<double>::pi));
pa.add (omegap * j * std::cos ((ui - j * v0) * halfPi));
}
}
else if (type == 2)
{
auto v0 = std::asinh (epss) / (N * 0.5 * MathConstants<double>::pi);
auto v0 = std::asinh (epss) / (N * halfPi);
if (r == 1)
pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * MathConstants<double>::pi)));
pa.add(-1.0 / (k / omegap * std::sinh (v0 * halfPi)));
for (int i = 1; i <= L; ++i)
{
auto ui = (2 * i - 1.0) / (double) N;
pa.add (1.0 / (k / omegap * j * std::cos ((ui - j * v0) * 0.5 * MathConstants<double>::pi)));
za.add (1.0 / (k / omegap * j * std::cos (ui * 0.5 * MathConstants<double>::pi)));
pa.add (1.0 / (k / omegap * j * std::cos ((ui - j * v0) * halfPi)));
za.add (1.0 / (k / omegap * j * std::cos (ui * halfPi)));
}
}
else
@@ -591,7 +592,7 @@ typename FilterDesign<FloatType>::IIRPolyphaseAllpassStructure
while (std::abs (delta) > 1e-100)
{
delta = std::pow (-1, m) * std::pow (q, m * m)
* std::cos (2 * m * MathConstants<double>::pi * i / (double) n);
* std::cos (m * MathConstants<double>::twoPi * i / (double) n);
den += delta;
++m;
}


+ 6
- 4
modules/juce_dsp/maths/juce_SpecialFunctions.cpp View File

@@ -53,7 +53,7 @@ void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexc
{
constexpr int M = 4;
K = MathConstants<double>::pi * 0.5;
K = MathConstants<double>::halfPi;
auto lastK = k;
for (int i = 0; i < M; ++i)
@@ -62,7 +62,7 @@ void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexc
K *= 1 + lastK;
}
Kp = MathConstants<double>::pi * 0.5;
Kp = MathConstants<double>::halfPi;
auto last = std::sqrt (1 - k * k);
for (int i = 0; i < M; ++i)
@@ -86,7 +86,8 @@ Complex<double> SpecialFunctions::cde (Complex<double> u, double k) noexcept
*++kei = next;
}
std::complex<double> last = std::cos (0.5 * u * MathConstants<double>::pi);
// NB: the spurious cast to double here is a workaround for a very odd link-time failure
std::complex<double> last = std::cos (u * (double) MathConstants<double>::halfPi);
for (int i = M - 1; i >= 0; --i)
last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);
@@ -108,7 +109,8 @@ Complex<double> SpecialFunctions::sne (Complex<double> u, double k) noexcept
*++kei = next;
}
std::complex<double> last = std::sin (0.5 * u * MathConstants<double>::pi);
// NB: the spurious cast to double here is a workaround for a very odd link-time failure
std::complex<double> last = std::sin (u * (double) MathConstants<double>::halfPi);
for (int i = M - 1; i >= 0; --i)
last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last);


+ 1
- 1
modules/juce_dsp/processors/juce_LadderFilter.cpp View File

@@ -155,7 +155,7 @@ void LadderFilter<Type>::setSampleRate (Type newValue) noexcept
jassert (newValue > Type (0));
cutoffFreqScaler = Type (-2.0 * juce::MathConstants<double>::pi) / newValue;
static constexpr Type smootherRampTimeSec (0.05);
static constexpr Type smootherRampTimeSec = Type (0.05);
cutoffTransformSmoother.reset (newValue, smootherRampTimeSec);
scaledResonanceSmoother.reset (newValue, smootherRampTimeSec);


+ 2
- 2
modules/juce_graphics/geometry/juce_Path.cpp View File

@@ -784,7 +784,7 @@ void Path::addBubble (Rectangle<float> bodyArea,
}
lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY());
addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants<float>::pi * 0.5f);
addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants<float>::halfPi);
if (Rectangle<float> (bodyArea.getRight(), targetLimit.getY(),
maximumArea.getRight() - bodyArea.getRight(), targetLimit.getHeight()).contains (arrowTip))
@@ -795,7 +795,7 @@ void Path::addBubble (Rectangle<float> bodyArea,
}
lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSizeH);
addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::pi * 0.5f, MathConstants<float>::pi);
addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants<float>::halfPi, MathConstants<float>::pi);
if (Rectangle<float> (targetLimit.getX(), bodyArea.getBottom(),
targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip))


+ 1
- 1
modules/juce_gui_basics/drawables/juce_SVGParser.cpp View File

@@ -1669,7 +1669,7 @@ private:
if (uy < 0)
startAngle = -startAngle;
startAngle += MathConstants<double>::pi * 0.5;
startAngle += MathConstants<double>::halfPi;
deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
/ (length * juce_hypot (vx, vy))));


+ 3
- 3
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp View File

@@ -2024,10 +2024,10 @@ void LookAndFeel_V2::drawGroupComponentOutline (Graphics& g, int width, int heig
p.startNewSubPath (x + textX + textW, y);
p.lineTo (x + w - cs, y);
p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants<float>::pi * 0.5f);
p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants<float>::halfPi);
p.lineTo (x + w, y + h - cs);
p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants<float>::pi * 0.5f, MathConstants<float>::pi);
p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants<float>::halfPi, MathConstants<float>::pi);
p.lineTo (x + cs, y + h);
p.addArc (x, y + h - cs2, cs2, cs2, MathConstants<float>::pi, MathConstants<float>::pi * 1.5f);
@@ -2948,7 +2948,7 @@ void LookAndFeel_V2::drawGlassPointer (Graphics& g,
p.lineTo (x, y + diameter * 0.6f);
p.closeSubPath();
p.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
p.applyTransform (AffineTransform::rotation (direction * MathConstants<float>::halfPi, x + diameter * 0.5f, y + diameter * 0.5f));
{
ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,


+ 4
- 4
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp View File

@@ -1071,8 +1071,8 @@ void LookAndFeel_V4::drawRotarySlider (Graphics& g, int x, int y, int width, int
}
auto thumbWidth = lineW * 2.0f;
Point<float> thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants<float>::pi * 0.5f),
bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants<float>::pi * 0.5f));
Point<float> thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants<float>::halfPi),
bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants<float>::halfPi));
g.setColour (slider.findColour (Slider::thumbColourId));
g.fillEllipse (Rectangle<float> (thumbWidth, thumbWidth).withCentre (thumbPoint));
@@ -1089,8 +1089,8 @@ void LookAndFeel_V4::drawPointer (Graphics& g, const float x, const float y, con
p.lineTo (x, y + diameter * 0.6f);
p.closeSubPath();
p.applyTransform (AffineTransform::rotation (direction * (MathConstants<float>::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
p.applyTransform (AffineTransform::rotation (direction * MathConstants<float>::halfPi,
x + diameter * 0.5f, y + diameter * 0.5f));
g.setColour (colour);
g.fillPath (p);
}


Loading…
Cancel
Save