diff --git a/examples/audio plugin host/Source/GraphEditorPanel.cpp b/examples/audio plugin host/Source/GraphEditorPanel.cpp index d864330ce9..40cf310bc7 100644 --- a/examples/audio plugin host/Source/GraphEditorPanel.cpp +++ b/examples/audio plugin host/Source/GraphEditorPanel.cpp @@ -509,7 +509,7 @@ struct GraphEditorPanel::ConnectorComponent : public Component, arrowL, 0.0f); arrow.applyTransform (AffineTransform() - .rotated (MathConstants::pi * 0.5f - (float) atan2 (p2.x - p1.x, p2.y - p1.y)) + .rotated (MathConstants::halfPi - (float) atan2 (p2.x - p1.x, p2.y - p1.y)) .translated ((p1 + p2) * 0.5f)); linePath.addPath (arrow); diff --git a/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp b/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp index 727942e4a6..a84adb7aa5 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp +++ b/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp @@ -461,7 +461,7 @@ Path ProjucerLookAndFeel::getArrowPath (Rectangle arrowZone, const int di if (filled) path.closeSubPath(); - path.applyTransform (AffineTransform::rotation (direction * (MathConstants::pi / 2.0f), + path.applyTransform (AffineTransform::rotation (direction * MathConstants::halfPi, arrowZone.getCentreX(), arrowZone.getCentreY())); return path; diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index 203796607a..bb550d9a19 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -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 (2 * 3.141592653589793238L); + /** A predefined value for Pi / 2 */ + static constexpr FloatType halfPi = static_cast (3.141592653589793238L / 2); + /** A predfined value for Euler's number */ static constexpr FloatType euler = static_cast (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::pi = static_cast (3.1415926 template const FloatType MathConstants::twoPi = static_cast (2 * 3.141592653589793238L); +template +const FloatType MathConstants::halfPi = static_cast (3.141592653589793238L / 2); + template const FloatType MathConstants::euler = static_cast (2.71828182845904523536L); diff --git a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp index 287cc1dc68..9b8139e71a 100644 --- a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp +++ b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp @@ -407,6 +407,7 @@ Array> auto omegap = std::tan (MathConstants::pi * fp); auto omegas = std::tan (MathConstants::pi * fs); + constexpr auto halfPi = MathConstants::halfPi; auto k = omegap / omegas; auto k1 = epsp / epss; @@ -446,35 +447,35 @@ Array> 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::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::pi); + auto v0 = std::asinh (1.0 / epsp) / (N * halfPi); if (r == 1) - pa.add (-omegap * std::sinh (v0 * 0.5 * MathConstants::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::pi)); + pa.add (omegap * j * std::cos ((ui - j * v0) * halfPi)); } } else if (type == 2) { - auto v0 = std::asinh (epss) / (N * 0.5 * MathConstants::pi); + auto v0 = std::asinh (epss) / (N * halfPi); if (r == 1) - pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * MathConstants::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::pi))); - za.add (1.0 / (k / omegap * j * std::cos (ui * 0.5 * MathConstants::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::IIRPolyphaseAllpassStructure while (std::abs (delta) > 1e-100) { delta = std::pow (-1, m) * std::pow (q, m * m) - * std::cos (2 * m * MathConstants::pi * i / (double) n); + * std::cos (m * MathConstants::twoPi * i / (double) n); den += delta; ++m; } diff --git a/modules/juce_dsp/maths/juce_SpecialFunctions.cpp b/modules/juce_dsp/maths/juce_SpecialFunctions.cpp index cda31c857b..ac7997430c 100644 --- a/modules/juce_dsp/maths/juce_SpecialFunctions.cpp +++ b/modules/juce_dsp/maths/juce_SpecialFunctions.cpp @@ -53,7 +53,7 @@ void SpecialFunctions::ellipticIntegralK (double k, double& K, double& Kp) noexc { constexpr int M = 4; - K = MathConstants::pi * 0.5; + K = MathConstants::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::pi * 0.5; + Kp = MathConstants::halfPi; auto last = std::sqrt (1 - k * k); for (int i = 0; i < M; ++i) @@ -86,7 +86,8 @@ Complex SpecialFunctions::cde (Complex u, double k) noexcept *++kei = next; } - std::complex last = std::cos (0.5 * u * MathConstants::pi); + // NB: the spurious cast to double here is a workaround for a very odd link-time failure + std::complex last = std::cos (u * (double) MathConstants::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 SpecialFunctions::sne (Complex u, double k) noexcept *++kei = next; } - std::complex last = std::sin (0.5 * u * MathConstants::pi); + // NB: the spurious cast to double here is a workaround for a very odd link-time failure + std::complex last = std::sin (u * (double) MathConstants::halfPi); for (int i = M - 1; i >= 0; --i) last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last); diff --git a/modules/juce_dsp/processors/juce_LadderFilter.cpp b/modules/juce_dsp/processors/juce_LadderFilter.cpp index c9161012ea..6c1704dfb9 100644 --- a/modules/juce_dsp/processors/juce_LadderFilter.cpp +++ b/modules/juce_dsp/processors/juce_LadderFilter.cpp @@ -155,7 +155,7 @@ void LadderFilter::setSampleRate (Type newValue) noexcept jassert (newValue > Type (0)); cutoffFreqScaler = Type (-2.0 * juce::MathConstants::pi) / newValue; - static constexpr Type smootherRampTimeSec (0.05); + static constexpr Type smootherRampTimeSec = Type (0.05); cutoffTransformSmoother.reset (newValue, smootherRampTimeSec); scaledResonanceSmoother.reset (newValue, smootherRampTimeSec); diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp index 455aa13325..196582d9c9 100644 --- a/modules/juce_graphics/geometry/juce_Path.cpp +++ b/modules/juce_graphics/geometry/juce_Path.cpp @@ -784,7 +784,7 @@ void Path::addBubble (Rectangle bodyArea, } lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY()); - addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants::pi * 0.5f); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants::halfPi); if (Rectangle (bodyArea.getRight(), targetLimit.getY(), maximumArea.getRight() - bodyArea.getRight(), targetLimit.getHeight()).contains (arrowTip)) @@ -795,7 +795,7 @@ void Path::addBubble (Rectangle bodyArea, } lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSizeH); - addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants::pi * 0.5f, MathConstants::pi); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants::halfPi, MathConstants::pi); if (Rectangle (targetLimit.getX(), bodyArea.getBottom(), targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip)) diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index f5666c7d52..698eaeed26 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -1669,7 +1669,7 @@ private: if (uy < 0) startAngle = -startAngle; - startAngle += MathConstants::pi * 0.5; + startAngle += MathConstants::halfPi; deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy)) / (length * juce_hypot (vx, vy)))); diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 4f005ccf15..75cf1bdec8 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -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::pi * 0.5f); + p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants::halfPi); p.lineTo (x + w, y + h - cs); - p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants::pi * 0.5f, MathConstants::pi); + p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants::halfPi, MathConstants::pi); p.lineTo (x + cs, y + h); p.addArc (x, y + h - cs2, cs2, cs2, MathConstants::pi, MathConstants::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::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); + p.applyTransform (AffineTransform::rotation (direction * MathConstants::halfPi, x + diameter * 0.5f, y + diameter * 0.5f)); { ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y, diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp index c101c39f0e..57773b37da 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp @@ -1071,8 +1071,8 @@ void LookAndFeel_V4::drawRotarySlider (Graphics& g, int x, int y, int width, int } auto thumbWidth = lineW * 2.0f; - Point thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants::pi * 0.5f), - bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants::pi * 0.5f)); + Point thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants::halfPi), + bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants::halfPi)); g.setColour (slider.findColour (Slider::thumbColourId)); g.fillEllipse (Rectangle (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::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); - + p.applyTransform (AffineTransform::rotation (direction * MathConstants::halfPi, + x + diameter * 0.5f, y + diameter * 0.5f)); g.setColour (colour); g.fillPath (p); }