From d0111a4f96d2812866f5a52f0480caaf62da0736 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 6 Dec 2017 11:16:22 +0000 Subject: [PATCH] Began phasing out double_Pi and float_Pi in favour of MathConstants::pi. Also added MathConstants::twoPi --- .../AudioAppExample/Source/MainComponent.cpp | 4 +- .../BlocksMonitor/Source/MainComponent.h | 2 +- .../BLOCKS/BlocksSynth/Source/Oscillators.h | 16 +- .../BlocksSynth/Source/WaveshapeProgram.h | 4 +- .../DSPDemo/Source/Demos/OscillatorDemo.cpp | 8 +- examples/Demo/Source/Demos/AnimationDemo.cpp | 4 +- .../Source/Demos/AudioSynthesiserDemo.cpp | 2 +- examples/Demo/Source/Demos/GraphicsDemo.cpp | 4 +- .../Demo/Source/Demos/LookAndFeelDemo.cpp | 2 +- .../Demo/Source/Demos/MultithreadingDemo.cpp | 3 +- examples/Demo/Source/Demos/WidgetsDemo.cpp | 2 +- examples/MPETest/Source/MPEDemoSynthVoice.h | 6 +- examples/NetworkGraphicsDemo/Source/Demos.h | 4 +- .../Source/StringComponent.h | 10 +- .../Source/StringSynthesiser.h | 2 +- .../Surround/Source/SurroundProcessor.cpp | 2 +- .../audio plugin demo/Source/SinewaveSynth.h | 2 +- .../Source/GraphEditorPanel.cpp | 2 +- .../Utility/UI/jucer_ProjucerLookAndFeel.cpp | 8 +- .../effects/juce_IIRFilter.cpp | 171 +++++++++--------- .../effects/juce_IIRFilter.h | 4 +- .../sources/juce_ResamplingAudioSource.cpp | 2 +- .../sources/juce_ToneGeneratorAudioSource.cpp | 2 +- .../audio_io/juce_AudioDeviceManager.cpp | 10 +- .../codecs/juce_MP3AudioFormat.cpp | 16 +- .../gui/juce_MidiKeyboardComponent.cpp | 2 +- .../players/juce_SoundPlayer.cpp | 9 +- .../juce_core/javascript/juce_Javascript.cpp | 2 +- modules/juce_core/maths/juce_MathsFunctions.h | 33 ++-- .../filter_design/juce_FilterDesign.cpp | 62 ++++--- modules/juce_dsp/frequency/juce_FFT.cpp | 12 +- modules/juce_dsp/frequency/juce_FFT_test.cpp | 12 +- .../juce_dsp/maths/juce_SpecialFunctions.cpp | 10 +- .../juce_dsp/processors/juce_FIRFilter.cpp | 8 +- .../juce_dsp/processors/juce_IIRFilter.cpp | 8 +- .../juce_dsp/processors/juce_LadderFilter.cpp | 4 +- modules/juce_dsp/processors/juce_Oscillator.h | 26 +-- .../juce_dsp/processors/juce_Oversampling.cpp | 4 +- .../processors/juce_StateVariableFilter.h | 4 +- modules/juce_graphics/geometry/juce_Path.cpp | 14 +- .../geometry/juce_PathStrokeType.cpp | 12 +- .../buttons/juce_ArrowButton.cpp | 2 +- .../drawables/juce_SVGParser.cpp | 16 +- .../lookandfeel/juce_LookAndFeel_V2.cpp | 18 +- .../lookandfeel/juce_LookAndFeel_V3.cpp | 4 +- .../lookandfeel/juce_LookAndFeel_V4.cpp | 10 +- .../juce_gui_basics/mouse/juce_MouseEvent.cpp | 4 +- .../mouse/juce_MouseInputSource.cpp | 4 +- .../juce_gui_basics/widgets/juce_Slider.cpp | 27 +-- 49 files changed, 307 insertions(+), 292 deletions(-) diff --git a/examples/AudioAppExample/Source/MainComponent.cpp b/examples/AudioAppExample/Source/MainComponent.cpp index a945cd97ea..8ff8bbd0c0 100644 --- a/examples/AudioAppExample/Source/MainComponent.cpp +++ b/examples/AudioAppExample/Source/MainComponent.cpp @@ -78,7 +78,7 @@ public: channelData[i] = amplitude * std::sin (phase); // increment the phase step for the next sample - phase = std::fmod (phase + phaseDelta, float_Pi * 2.0f); + phase = std::fmod (phase + phaseDelta, MathConstants::twoPi); } } } @@ -130,7 +130,7 @@ public: frequency = (getHeight() - e.y) * 10.0f; amplitude = jmin (0.9f, 0.2f * e.position.x / getWidth()); - phaseDelta = (float) (2.0 * double_Pi * frequency / sampleRate); + phaseDelta = (float) (MathConstants::twoPi * frequency / sampleRate); repaint(); } diff --git a/examples/BLOCKS/BlocksMonitor/Source/MainComponent.h b/examples/BLOCKS/BlocksMonitor/Source/MainComponent.h index 366e12f69e..ec2966a185 100644 --- a/examples/BLOCKS/BlocksMonitor/Source/MainComponent.h +++ b/examples/BLOCKS/BlocksMonitor/Source/MainComponent.h @@ -166,7 +166,7 @@ public: blockComponent->block->getHeight() * blockUnitInPixels); if (blockComponent->rotation != 0) - blockComponent->setTransform (AffineTransform::rotation (blockComponent->rotation * (static_cast (double_Pi) / 180.0f), + blockComponent->setTransform (AffineTransform::rotation (degreesToRadians (blockComponent->rotation), static_cast (blockComponent->getX()), static_cast (blockComponent->getY()))); } diff --git a/examples/BLOCKS/BlocksSynth/Source/Oscillators.h b/examples/BLOCKS/BlocksSynth/Source/Oscillators.h index 66936ce44f..f802bc51d3 100644 --- a/examples/BLOCKS/BlocksSynth/Source/Oscillators.h +++ b/examples/BLOCKS/BlocksSynth/Source/Oscillators.h @@ -43,7 +43,7 @@ public: void startNote (int midiNoteNumber, float velocity, SynthesiserSound*, int) override { frequency = MidiMessage::getMidiNoteInHertz (midiNoteNumber); - phaseIncrement.setValue (((2.0 * double_Pi) * frequency) / sampleRate); + phaseIncrement.setValue (((MathConstants::twoPi) * frequency) / sampleRate); amplitude.setValue (velocity); // Store the initial note and work out the maximum frequency deviations for pitch bend @@ -62,7 +62,7 @@ public: { // Change the phase increment based on pitch bend amount auto frequencyOffset = ((newValue > 0 ? maxFreq : minFreq) * (newValue / 127.0)); - phaseIncrement.setValue (((2.0 * double_Pi) * (frequency + frequencyOffset)) / sampleRate); + phaseIncrement.setValue (((MathConstants::twoPi) * (frequency + frequencyOffset)) / sampleRate); } void controllerMoved (int, int) override @@ -95,8 +95,8 @@ public: phasePos += phaseIncrement.getNextValue(); - if (phasePos > (2.0 * double_Pi)) - phasePos -= (2.0 * double_Pi); + if (phasePos > MathConstants::twoPi) + phasePos -= MathConstants::twoPi; return output; } @@ -177,7 +177,7 @@ struct SquareVoice : public Oscillator bool canPlaySound (SynthesiserSound* sound) override { return dynamic_cast (sound) != nullptr; } - double renderWaveShape (const double currentPhase) override { return (currentPhase < double_Pi ? 0.0 : 1.0); } + double renderWaveShape (const double currentPhase) override { return (currentPhase < MathConstants::pi ? 0.0 : 1.0); } //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SquareVoice) @@ -208,7 +208,7 @@ struct SawVoice : public Oscillator bool canPlaySound (SynthesiserSound* sound) override { return dynamic_cast (sound) != nullptr; } - double renderWaveShape (const double currentPhase) override { return (1.0 / double_Pi) * currentPhase - 1.0; } + double renderWaveShape (const double currentPhase) override { return (1.0 / MathConstants::pi) * currentPhase - 1.0; } //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SawVoice) @@ -241,8 +241,8 @@ struct TriangleVoice : public Oscillator double renderWaveShape (const double currentPhase) override { - return (currentPhase < double_Pi ? -1.0 + (2.0 / double_Pi) * currentPhase - : 3.0 - (2.0 / double_Pi) * currentPhase); + return currentPhase < MathConstants::pi ? -1.0 + (2.0 / MathConstants::pi) * currentPhase + : 3.0 - (2.0 / MathConstants::pi) * currentPhase; } //============================================================================== diff --git a/examples/BLOCKS/BlocksSynth/Source/WaveshapeProgram.h b/examples/BLOCKS/BlocksSynth/Source/WaveshapeProgram.h index ef31ff21ed..44b9993bf1 100644 --- a/examples/BLOCKS/BlocksSynth/Source/WaveshapeProgram.h +++ b/examples/BLOCKS/BlocksSynth/Source/WaveshapeProgram.h @@ -51,7 +51,7 @@ public: // Set current phase position to 0 and work out the required phase increment for one cycle auto currentPhase = 0.0; - auto phaseInc = (1.0 / 30.0) * (2.0 * double_Pi); + auto phaseInc = (1.0 / 30.0) * MathConstants::twoPi; for (auto x = 0; x < 30; ++x) { @@ -60,7 +60,7 @@ public: sineWaveY[x] = static_cast (roundToInt ((sineOutput * 6.5) + 7.0)); // Square wave output, set flags for when vertical line should be drawn - if (currentPhase < double_Pi) + if (currentPhase < MathConstants::pi) { if (x == 0) squareWaveY[x] = 255; diff --git a/examples/DSPDemo/Source/Demos/OscillatorDemo.cpp b/examples/DSPDemo/Source/Demos/OscillatorDemo.cpp index 388e0d6f06..8bd7409a0f 100644 --- a/examples/DSPDemo/Source/Demos/OscillatorDemo.cpp +++ b/examples/DSPDemo/Source/Demos/OscillatorDemo.cpp @@ -83,13 +83,13 @@ struct OscillatorDemo { // No Approximation {[] (float x) { return std::sin (x); }}, // sine - {[] (float x) { return x / float_Pi; }}, // saw + {[] (float x) { return x / MathConstants::pi; }}, // saw {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }}, // square // Approximated by a wave-table - {[] (float x) { return std::sin (x); }, 100}, // sine - {[] (float x) { return x / float_Pi; }, 100}, // saw - {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100} // square + {[] (float x) { return std::sin (x); }, 100}, // sine + {[] (float x) { return x / MathConstants::pi; }, 100}, // saw + {[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100} // square }; int currentOscillatorIdx = 0; diff --git a/examples/Demo/Source/Demos/AnimationDemo.cpp b/examples/Demo/Source/Demos/AnimationDemo.cpp index daff2ca965..b0d05dbd85 100644 --- a/examples/Demo/Source/Demos/AnimationDemo.cpp +++ b/examples/Demo/Source/Demos/AnimationDemo.cpp @@ -149,7 +149,7 @@ public: for (int i = 0; i < componentsToAnimate.size(); ++i) { const int newIndex = (i + 3) % componentsToAnimate.size(); - const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); + const float angle = newIndex * MathConstants::twoPi / componentsToAnimate.size(); const float radius = getWidth() * 0.35f; Rectangle r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, @@ -258,7 +258,7 @@ private: for (int i = 0; i < componentsToAnimate.size(); ++i) { const int newIndex = (i + 3 * cycleCount) % componentsToAnimate.size(); - const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); + const float angle = newIndex * MathConstants::twoPi / componentsToAnimate.size(); const float radius = getWidth() * 0.35f; Rectangle r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, diff --git a/examples/Demo/Source/Demos/AudioSynthesiserDemo.cpp b/examples/Demo/Source/Demos/AudioSynthesiserDemo.cpp index 5730ee71ec..c78bdce0c8 100644 --- a/examples/Demo/Source/Demos/AudioSynthesiserDemo.cpp +++ b/examples/Demo/Source/Demos/AudioSynthesiserDemo.cpp @@ -59,7 +59,7 @@ struct SineWaveVoice : public SynthesiserVoice double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber); double cyclesPerSample = cyclesPerSecond / getSampleRate(); - angleDelta = cyclesPerSample * 2.0 * double_Pi; + angleDelta = cyclesPerSample * MathConstants::twoPi; } void stopNote (float /*velocity*/, bool allowTailOff) override diff --git a/examples/Demo/Source/Demos/GraphicsDemo.cpp b/examples/Demo/Source/Demos/GraphicsDemo.cpp index b764c02d7c..2c6bde8ea0 100644 --- a/examples/Demo/Source/Demos/GraphicsDemo.cpp +++ b/examples/Demo/Source/Demos/GraphicsDemo.cpp @@ -110,7 +110,7 @@ public: AffineTransform t; if (controls.animateRotation.getToggleState()) - t = t.rotated (rotation.getValue() * float_Pi * 2.0f); + t = t.rotated (rotation.getValue() * MathConstants::twoPi); if (controls.animateSize.getToggleState()) t = t.scaled (0.3f + size.getValue() * 2.0f); @@ -220,7 +220,7 @@ public: AffineTransform transform (AffineTransform::translation (clipImage.getWidth() / -2.0f, clipImage.getHeight() / -2.0f) - .rotated (clipImageAngle.getValue() * float_Pi * 2.0f) + .rotated (clipImageAngle.getValue() * MathConstants::twoPi) .scaled (2.0f + clipImageSize.getValue() * 3.0f) .translated (getWidth() * 0.5f, getHeight() * 0.5f)); diff --git a/examples/Demo/Source/Demos/LookAndFeelDemo.cpp b/examples/Demo/Source/Demos/LookAndFeelDemo.cpp index e675debd5d..57e50401dd 100644 --- a/examples/Demo/Source/Demos/LookAndFeelDemo.cpp +++ b/examples/Demo/Source/Demos/LookAndFeelDemo.cpp @@ -374,7 +374,7 @@ struct SquareLookAndFeel : public CustomLookAndFeel float rotaryStartAngle, float rotaryEndAngle, Slider& slider) override { auto diameter = jmin (width, height) - 4.0f; - auto radius = (diameter / 2.0f) * std::cos (float_Pi / 4.0f); + auto radius = (diameter / 2.0f) * std::cos (MathConstants::pi / 4.0f); auto centreX = x + width * 0.5f; auto centreY = y + height * 0.5f; auto rx = centreX - radius; diff --git a/examples/Demo/Source/Demos/MultithreadingDemo.cpp b/examples/Demo/Source/Demos/MultithreadingDemo.cpp index 5d0bc466b2..71284b4ec9 100644 --- a/examples/Demo/Source/Demos/MultithreadingDemo.cpp +++ b/examples/Demo/Source/Demos/MultithreadingDemo.cpp @@ -44,7 +44,8 @@ public: const float speed = 5.0f; // give each ball a fixed speed so we can // see the effects of thread priority on how fast // they actually go. - const float angle = Random::getSystemRandom().nextFloat() * float_Pi * 2.0f; + + auto angle = Random::getSystemRandom().nextFloat() * MathConstants::twoPi; dx = std::sin (angle) * speed; dy = std::cos (angle) * speed; diff --git a/examples/Demo/Source/Demos/WidgetsDemo.cpp b/examples/Demo/Source/Demos/WidgetsDemo.cpp index 46057e0e45..4d8a69bbb8 100644 --- a/examples/Demo/Source/Demos/WidgetsDemo.cpp +++ b/examples/Demo/Source/Demos/WidgetsDemo.cpp @@ -155,7 +155,7 @@ struct SlidersPage : public Component s = createSlider (false); s->setSliderStyle (Slider::Rotary); - s->setRotaryParameters (float_Pi * 1.2f, float_Pi * 2.8f, false); + s->setRotaryParameters (MathConstants::pi * 1.2f, MathConstants::pi * 2.8f, false); s->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20); horizonalSliderArea.removeFromTop (15); s->setBounds (horizonalSliderArea.removeFromTop (70)); diff --git a/examples/MPETest/Source/MPEDemoSynthVoice.h b/examples/MPETest/Source/MPEDemoSynthVoice.h index fbaec44ec3..0c358ba9f3 100644 --- a/examples/MPETest/Source/MPEDemoSynthVoice.h +++ b/examples/MPETest/Source/MPEDemoSynthVoice.h @@ -50,7 +50,7 @@ public: phase = 0.0; const double cyclesPerSample = frequency.getNextValue() / currentSampleRate; - phaseDelta = 2.0 * double_Pi * cyclesPerSample; + phaseDelta = MathConstants::twoPi * cyclesPerSample; tailOff = 0.0; } @@ -168,8 +168,8 @@ private: const float nextSample = float (amplitude * ((a1 * f1) + (a2 * f2))); const double cyclesPerSample = frequency.getNextValue() / currentSampleRate; - phaseDelta = 2.0 * double_Pi * cyclesPerSample; - phase = std::fmod (phase + phaseDelta, 2.0 * double_Pi); + phaseDelta = MathConstants::twoPi * cyclesPerSample; + phase = std::fmod (phase + phaseDelta, MathConstants::twoPi); return nextSample; } diff --git a/examples/NetworkGraphicsDemo/Source/Demos.h b/examples/NetworkGraphicsDemo/Source/Demos.h index a50117d171..b2e0797451 100644 --- a/examples/NetworkGraphicsDemo/Source/Demos.h +++ b/examples/NetworkGraphicsDemo/Source/Demos.h @@ -299,7 +299,7 @@ struct FlockDemo : public BackgroundLogo { const float regionSize = high - low; const float adjustedProportion = (proportion - low) / regionSize; - const float F = (0.5f - std::cos (adjustedProportion * float_Pi * 2.0f) * 0.5f + 0.5f) * strength; + const float F = (0.5f - std::cos (adjustedProportion * MathConstants::twoPi) * 0.5f + 0.5f) * strength; b1.accelerate (getVectorWithLength (b2.velocity, F)); b2.accelerate (getVectorWithLength (b1.velocity, F)); @@ -308,7 +308,7 @@ struct FlockDemo : public BackgroundLogo { const float regionSize = 1.0f - high; const float adjustedProportion = (proportion - high) / regionSize; - const float F = (0.5f - std::cos (adjustedProportion * float_Pi * 2.0f) * 0.5f + 0.5f) * strength; + const float F = (0.5f - std::cos (adjustedProportion * MathConstants::twoPi) * 0.5f + 0.5f) * strength; delta = getVectorWithLength (delta, F); b1.accelerate (-delta); diff --git a/examples/PluckedStringsDemo/Source/StringComponent.h b/examples/PluckedStringsDemo/Source/StringComponent.h index 89d8124963..5a2f1ca18d 100644 --- a/examples/PluckedStringsDemo/Source/StringComponent.h +++ b/examples/PluckedStringsDemo/Source/StringComponent.h @@ -44,8 +44,8 @@ public: //============================================================================== void stringPlucked (float pluckPositionRelative) { - amplitude = maxAmplitude * std::sin (pluckPositionRelative * float_Pi); - phase = float_Pi; + amplitude = maxAmplitude * std::sin (pluckPositionRelative * MathConstants::pi); + phase = MathConstants::pi; } //============================================================================== @@ -57,7 +57,7 @@ public: Path generateStringPath() const { - const float y = height / 2.0f; + auto y = height / 2.0f; Path stringPath; stringPath.startNewSubPath (0, y); @@ -87,8 +87,8 @@ public: phase += phaseStep; - if (phase > float_Pi) - phase -= 2.0f * float_Pi; + if (phase >= MathConstants::twoPi) + phase -= MathConstants::twoPi; } private: diff --git a/examples/PluckedStringsDemo/Source/StringSynthesiser.h b/examples/PluckedStringsDemo/Source/StringSynthesiser.h index 3d98eaabc3..8890177be3 100644 --- a/examples/PluckedStringsDemo/Source/StringSynthesiser.h +++ b/examples/PluckedStringsDemo/Source/StringSynthesiser.h @@ -64,7 +64,7 @@ public: { // plucking in the middle gives the largest amplitude; // plucking at the very ends will do nothing. - amplitude = std::sin (float_Pi * pluckPosition); + amplitude = std::sin (MathConstants::pi * pluckPosition); } } diff --git a/examples/PlugInSamples/Surround/Source/SurroundProcessor.cpp b/examples/PlugInSamples/Surround/Source/SurroundProcessor.cpp index faeb4f28e5..4da678a4e5 100644 --- a/examples/PlugInSamples/Surround/Source/SurroundProcessor.cpp +++ b/examples/PlugInSamples/Surround/Source/SurroundProcessor.cpp @@ -88,7 +88,7 @@ public: const float freq = (float) (440.0 / getSampleRate()); for (int i = 0; i < fillSamples; ++i) - channelBuffer[i] += std::sin (2.0f * float_Pi * freq * static_cast (sampleOffset++)); + channelBuffer[i] += std::sin (MathConstants::twoPi * freq * static_cast (sampleOffset++)); } } diff --git a/examples/audio plugin demo/Source/SinewaveSynth.h b/examples/audio plugin demo/Source/SinewaveSynth.h index 40f832f3d7..ecd520220f 100644 --- a/examples/audio plugin demo/Source/SinewaveSynth.h +++ b/examples/audio plugin demo/Source/SinewaveSynth.h @@ -61,7 +61,7 @@ public: double cyclesPerSecond = MidiMessage::getMidiNoteInHertz (midiNoteNumber); double cyclesPerSample = cyclesPerSecond / getSampleRate(); - angleDelta = cyclesPerSample * 2.0 * double_Pi; + angleDelta = cyclesPerSample * MathConstants::twoPi; } void stopNote (float /*velocity*/, bool allowTailOff) override diff --git a/examples/audio plugin host/Source/GraphEditorPanel.cpp b/examples/audio plugin host/Source/GraphEditorPanel.cpp index 5d4d05e588..d864330ce9 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 (float_Pi * 0.5f - (float) atan2 (p2.x - p1.x, p2.y - p1.y)) + .rotated (MathConstants::pi * 0.5f - (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 8f6f14bc6e..727942e4a6 100644 --- a/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp +++ b/extras/Projucer/Source/Utility/UI/jucer_ProjucerLookAndFeel.cpp @@ -400,7 +400,7 @@ void ProjucerLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar barBounds.getWidth() * 0.5f, barBounds.getHeight() * 0.5f, 0.0f, 0.0f, - 2.0f * float_Pi, + MathConstants::twoPi, true); g.strokePath (arcPath2, PathStrokeType (2.0f)); @@ -415,7 +415,8 @@ void ProjucerLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar degreesToRadians (endInDegrees), true); - arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * float_Pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); + arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * MathConstants::pi * 2.25f, + barBounds.getCentreX(), barBounds.getCentreY())); g.strokePath (arcPath, PathStrokeType (2.0f)); if (textToShow.isNotEmpty()) @@ -460,7 +461,8 @@ Path ProjucerLookAndFeel::getArrowPath (Rectangle arrowZone, const int di if (filled) path.closeSubPath(); - path.applyTransform (AffineTransform::rotation (direction * (float_Pi / 2.0f), arrowZone.getCentreX(), arrowZone.getCentreY())); + path.applyTransform (AffineTransform::rotation (direction * (MathConstants::pi / 2.0f), + arrowZone.getCentreX(), arrowZone.getCentreY())); return path; } diff --git a/modules/juce_audio_basics/effects/juce_IIRFilter.cpp b/modules/juce_audio_basics/effects/juce_IIRFilter.cpp index 357196b4a6..50fb28da6c 100644 --- a/modules/juce_audio_basics/effects/juce_IIRFilter.cpp +++ b/modules/juce_audio_basics/effects/juce_IIRFilter.cpp @@ -44,7 +44,7 @@ IIRCoefficients& IIRCoefficients::operator= (const IIRCoefficients& other) noexc IIRCoefficients::IIRCoefficients (double c1, double c2, double c3, double c4, double c5, double c6) noexcept { - const double a = 1.0 / c4; + auto a = 1.0 / c4; coefficients[0] = (float) (c1 * a); coefficients[1] = (float) (c2 * a); @@ -53,23 +53,23 @@ IIRCoefficients::IIRCoefficients (double c1, double c2, double c3, coefficients[4] = (float) (c6 * a); } -IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, - const double frequency) noexcept +IIRCoefficients IIRCoefficients::makeLowPass (double sampleRate, + double frequency) noexcept { return makeLowPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); } -IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, - const double frequency, - const double Q) noexcept +IIRCoefficients IIRCoefficients::makeLowPass (double sampleRate, + double frequency, + double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); - const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); + auto n = 1.0 / std::tan (MathConstants::pi * frequency / sampleRate); + auto nSquared = n * n; + auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); return IIRCoefficients (c1, c1 * 2.0, @@ -79,23 +79,23 @@ IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, c1 * (1.0 - 1.0 / Q * n + nSquared)); } -IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, - const double frequency) noexcept +IIRCoefficients IIRCoefficients::makeHighPass (double sampleRate, + double frequency) noexcept { return makeHighPass (sampleRate, frequency, 1.0 / std::sqrt(2.0)); } -IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, - const double frequency, - const double Q) noexcept +IIRCoefficients IIRCoefficients::makeHighPass (double sampleRate, + double frequency, + double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double n = std::tan (double_Pi * frequency / sampleRate); - const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); + auto n = std::tan (MathConstants::pi * frequency / sampleRate); + auto nSquared = n * n; + auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); return IIRCoefficients (c1, c1 * -2.0, @@ -105,23 +105,23 @@ IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, c1 * (1.0 - 1.0 / Q * n + nSquared)); } -IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, - const double frequency) noexcept +IIRCoefficients IIRCoefficients::makeBandPass (double sampleRate, + double frequency) noexcept { return makeBandPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); } -IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, - const double frequency, - const double Q) noexcept +IIRCoefficients IIRCoefficients::makeBandPass (double sampleRate, + double frequency, + double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); - const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); + auto n = 1.0 / std::tan (MathConstants::pi * frequency / sampleRate); + auto nSquared = n * n; + auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); return IIRCoefficients (c1 * n / Q, 0.0, @@ -131,23 +131,23 @@ IIRCoefficients IIRCoefficients::makeBandPass (const double sampleRate, c1 * (1.0 - 1.0 / Q * n + nSquared)); } -IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, - const double frequency) noexcept +IIRCoefficients IIRCoefficients::makeNotchFilter (double sampleRate, + double frequency) noexcept { return makeNotchFilter (sampleRate, frequency, 1.0 / std::sqrt (2.0)); } -IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, - const double frequency, - const double Q) noexcept +IIRCoefficients IIRCoefficients::makeNotchFilter (double sampleRate, + double frequency, + double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); - const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + n / Q + nSquared); + auto n = 1.0 / std::tan (MathConstants::pi * frequency / sampleRate); + auto nSquared = n * n; + auto c1 = 1.0 / (1.0 + n / Q + nSquared); return IIRCoefficients (c1 * (1.0 + nSquared), 2.0 * c1 * (1.0 - nSquared), @@ -157,23 +157,23 @@ IIRCoefficients IIRCoefficients::makeNotchFilter (const double sampleRate, c1 * (1.0 - n / Q + nSquared)); } -IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, - const double frequency) noexcept +IIRCoefficients IIRCoefficients::makeAllPass (double sampleRate, + double frequency) noexcept { return makeAllPass (sampleRate, frequency, 1.0 / std::sqrt (2.0)); } -IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, - const double frequency, - const double Q) noexcept +IIRCoefficients IIRCoefficients::makeAllPass (double sampleRate, + double frequency, + double Q) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double n = 1.0 / std::tan (double_Pi * frequency / sampleRate); - const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); + auto n = 1.0 / std::tan (MathConstants::pi * frequency / sampleRate); + auto nSquared = n * n; + auto c1 = 1.0 / (1.0 + 1.0 / Q * n + nSquared); return IIRCoefficients (c1 * (1.0 - n / Q + nSquared), c1 * 2.0 * (1.0 - nSquared), @@ -183,22 +183,22 @@ IIRCoefficients IIRCoefficients::makeAllPass (const double sampleRate, c1 * (1.0 - n / Q + nSquared)); } -IIRCoefficients IIRCoefficients::makeLowShelf (const double sampleRate, - const double cutOffFrequency, - const double Q, - const float gainFactor) noexcept +IIRCoefficients IIRCoefficients::makeLowShelf (double sampleRate, + double cutOffFrequency, + double Q, + float gainFactor) noexcept { jassert (sampleRate > 0.0); jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double A = jmax (0.0f, std::sqrt (gainFactor)); - const double aminus1 = A - 1.0; - const double aplus1 = A + 1.0; - const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; - const double coso = std::cos (omega); - const double beta = std::sin (omega) * std::sqrt (A) / Q; - const double aminus1TimesCoso = aminus1 * coso; + auto A = jmax (0.0f, std::sqrt (gainFactor)); + auto aminus1 = A - 1.0; + auto aplus1 = A + 1.0; + auto omega = (MathConstants::twoPi * jmax (cutOffFrequency, 2.0)) / sampleRate; + auto coso = std::cos (omega); + auto beta = std::sin (omega) * std::sqrt (A) / Q; + auto aminus1TimesCoso = aminus1 * coso; return IIRCoefficients (A * (aplus1 - aminus1TimesCoso + beta), A * 2.0 * (aminus1 - aplus1 * coso), @@ -208,22 +208,22 @@ IIRCoefficients IIRCoefficients::makeLowShelf (const double sampleRate, aplus1 + aminus1TimesCoso - beta); } -IIRCoefficients IIRCoefficients::makeHighShelf (const double sampleRate, - const double cutOffFrequency, - const double Q, - const float gainFactor) noexcept +IIRCoefficients IIRCoefficients::makeHighShelf (double sampleRate, + double cutOffFrequency, + double Q, + float gainFactor) noexcept { jassert (sampleRate > 0.0); jassert (cutOffFrequency > 0.0 && cutOffFrequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double A = jmax (0.0f, std::sqrt (gainFactor)); - const double aminus1 = A - 1.0; - const double aplus1 = A + 1.0; - const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; - const double coso = std::cos (omega); - const double beta = std::sin (omega) * std::sqrt (A) / Q; - const double aminus1TimesCoso = aminus1 * coso; + auto A = jmax (0.0f, std::sqrt (gainFactor)); + auto aminus1 = A - 1.0; + auto aplus1 = A + 1.0; + auto omega = (MathConstants::twoPi * jmax (cutOffFrequency, 2.0)) / sampleRate; + auto coso = std::cos (omega); + auto beta = std::sin (omega) * std::sqrt (A) / Q; + auto aminus1TimesCoso = aminus1 * coso; return IIRCoefficients (A * (aplus1 + aminus1TimesCoso + beta), A * -2.0 * (aminus1 + aplus1 * coso), @@ -233,21 +233,21 @@ IIRCoefficients IIRCoefficients::makeHighShelf (const double sampleRate, aplus1 - aminus1TimesCoso - beta); } -IIRCoefficients IIRCoefficients::makePeakFilter (const double sampleRate, - const double frequency, - const double Q, - const float gainFactor) noexcept +IIRCoefficients IIRCoefficients::makePeakFilter (double sampleRate, + double frequency, + double Q, + float gainFactor) noexcept { jassert (sampleRate > 0.0); jassert (frequency > 0.0 && frequency <= sampleRate * 0.5); jassert (Q > 0.0); - const double A = jmax (0.0f, std::sqrt (gainFactor)); - const double omega = (double_Pi * 2.0 * jmax (frequency, 2.0)) / sampleRate; - const double alpha = 0.5 * std::sin (omega) / Q; - const double c2 = -2.0 * std::cos (omega); - const double alphaTimesA = alpha * A; - const double alphaOverA = alpha / A; + auto A = jmax (0.0f, std::sqrt (gainFactor)); + auto omega = (MathConstants::twoPi * jmax (frequency, 2.0)) / sampleRate; + auto alpha = 0.5 * std::sin (omega) / Q; + auto c2 = -2.0 * std::cos (omega); + auto alphaTimesA = alpha * A; + auto alphaOverA = alpha / A; return IIRCoefficients (1.0 + alphaTimesA, c2, @@ -259,12 +259,10 @@ IIRCoefficients IIRCoefficients::makePeakFilter (const double sampleRate, //============================================================================== IIRFilter::IIRFilter() noexcept - : v1 (0.0), v2 (0.0), active (false) { } -IIRFilter::IIRFilter (const IIRFilter& other) noexcept - : v1 (0.0), v2 (0.0), active (other.active) +IIRFilter::IIRFilter (const IIRFilter& other) noexcept : active (other.active) { const SpinLock::ScopedLockType sl (other.processLock); coefficients = other.coefficients; @@ -284,7 +282,6 @@ void IIRFilter::makeInactive() noexcept void IIRFilter::setCoefficients (const IIRCoefficients& newCoefficients) noexcept { const SpinLock::ScopedLockType sl (processLock); - coefficients = newCoefficients; active = true; } @@ -296,9 +293,9 @@ void IIRFilter::reset() noexcept v1 = v2 = 0.0; } -float IIRFilter::processSingleSampleRaw (const float in) noexcept +float IIRFilter::processSingleSampleRaw (float in) noexcept { - float out = coefficients.coefficients[0] * in + v1; + auto out = coefficients.coefficients[0] * in + v1; JUCE_SNAP_TO_ZERO (out); @@ -314,17 +311,17 @@ void IIRFilter::processSamples (float* const samples, const int numSamples) noex if (active) { - const float c0 = coefficients.coefficients[0]; - const float c1 = coefficients.coefficients[1]; - const float c2 = coefficients.coefficients[2]; - const float c3 = coefficients.coefficients[3]; - const float c4 = coefficients.coefficients[4]; - float lv1 = v1, lv2 = v2; + auto c0 = coefficients.coefficients[0]; + auto c1 = coefficients.coefficients[1]; + auto c2 = coefficients.coefficients[2]; + auto c3 = coefficients.coefficients[3]; + auto c4 = coefficients.coefficients[4]; + auto lv1 = v1, lv2 = v2; for (int i = 0; i < numSamples; ++i) { - const float in = samples[i]; - const float out = c0 * in + lv1; + auto in = samples[i]; + auto out = c0 * in + lv1; samples[i] = out; lv1 = c1 * in - c3 * out + lv2; diff --git a/modules/juce_audio_basics/effects/juce_IIRFilter.h b/modules/juce_audio_basics/effects/juce_IIRFilter.h index 9db85b5828..f313e3eedc 100644 --- a/modules/juce_audio_basics/effects/juce_IIRFilter.h +++ b/modules/juce_audio_basics/effects/juce_IIRFilter.h @@ -200,8 +200,8 @@ protected: //============================================================================== SpinLock processLock; IIRCoefficients coefficients; - float v1, v2; - bool active; + float v1 = 0, v2 = 0; + bool active = false; IIRFilter& operator= (const IIRFilter&); JUCE_LEAK_DETECTOR (IIRFilter) diff --git a/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp b/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp index c8c339ce4d..1dcbf51e7b 100644 --- a/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp +++ b/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp @@ -201,7 +201,7 @@ void ResamplingAudioSource::createLowPass (const double frequencyRatio) const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio : 0.5 * frequencyRatio; - const double n = 1.0 / std::tan (double_Pi * jmax (0.001, proportionalRate)); + const double n = 1.0 / std::tan (MathConstants::pi * jmax (0.001, proportionalRate)); const double nSquared = n * n; const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); diff --git a/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.cpp b/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.cpp index b33a922494..1707db7c9b 100644 --- a/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.cpp +++ b/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.cpp @@ -63,7 +63,7 @@ void ToneGeneratorAudioSource::releaseResources() void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info) { if (phasePerSample == 0.0) - phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); + phasePerSample = MathConstants::twoPi / (sampleRate / frequency); for (int i = 0; i < info.numSamples; ++i) { diff --git a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp index 4cbe6e1db8..d4fd629150 100644 --- a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp +++ b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp @@ -986,13 +986,13 @@ void AudioDeviceManager::playTestSound() if (currentAudioDevice != nullptr) { - const double sampleRate = currentAudioDevice->getCurrentSampleRate(); - const int soundLength = (int) sampleRate; + auto sampleRate = currentAudioDevice->getCurrentSampleRate(); + auto soundLength = (int) sampleRate; - const double frequency = 440.0; - const float amplitude = 0.5f; + double frequency = 440.0; + float amplitude = 0.5f; - const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); + auto phasePerSample = MathConstants::twoPi / (sampleRate / frequency); auto* newSound = new AudioBuffer (1, soundLength); diff --git a/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp index 70dc52ef36..a565f4c7a4 100644 --- a/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_MP3AudioFormat.cpp @@ -611,7 +611,7 @@ private: float* costab = cosTables[i]; for (int k = 0; k < kr; ++k) - costab[k] = (float) (1.0 / (2.0 * std::cos (double_Pi * (k * 2 + 1) / divv))); + costab[k] = (float) (1.0 / (2.0 * std::cos (MathConstants::pi * (k * 2 + 1) / divv))); } for (i = 0, j = 0; i < 256; ++i, ++j, table += 32) @@ -696,23 +696,23 @@ private: for (i = 0; i < 18; ++i) { - win[0][i] = win[1][i] = (float) (0.5 * std::sin (double_Pi / 72.0 * (2 * i + 1)) / std::cos (double_Pi * (2 * i + 19) / 72.0)); - win[0][i + 18] = win[3][i + 18] = (float) (0.5 * std::sin (double_Pi / 72.0 * (2 * (i + 18) + 1)) / std::cos (double_Pi * (2 * (i + 18) + 19) / 72.0)); + win[0][i] = win[1][i] = (float) (0.5 * std::sin (MathConstants::pi / 72.0 * (2 * i + 1)) / std::cos (MathConstants::pi * (2 * i + 19) / 72.0)); + win[0][i + 18] = win[3][i + 18] = (float) (0.5 * std::sin (MathConstants::pi / 72.0 * (2 * (i + 18) + 1)) / std::cos (MathConstants::pi * (2 * (i + 18) + 19) / 72.0)); } - const double piOver72 = double_Pi / 72.0; + const double piOver72 = MathConstants::pi / 72.0; for (i = 0; i < 6; ++i) { win[1][i + 18] = (float) (0.5 / std::cos (piOver72 * (2 * (i + 18) + 19))); win[3][i + 12] = (float) (0.5 / std::cos (piOver72 * (2 * (i + 12) + 19))); - win[1][i + 24] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 13)) / std::cos (piOver72 * (2 * (i + 24) + 19))); + win[1][i + 24] = (float) (0.5 * std::sin (MathConstants::pi / 24.0 * (2 * i + 13)) / std::cos (piOver72 * (2 * (i + 24) + 19))); win[1][i + 30] = win[3][i] = 0; - win[3][i + 6] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 1)) / std::cos (piOver72 * (2 * (i + 6) + 19))); + win[3][i + 6] = (float) (0.5 * std::sin (MathConstants::pi / 24.0 * (2 * i + 1)) / std::cos (piOver72 * (2 * (i + 6) + 19))); } for (i = 0; i < 12; ++i) - win[2][i] = (float) (0.5 * std::sin (double_Pi / 24.0 * (2 * i + 1)) / std::cos (double_Pi * (2 * i + 7) / 24.0)); + win[2][i] = (float) (0.5 * std::sin (MathConstants::pi / 24.0 * (2 * i + 1)) / std::cos (MathConstants::pi * (2 * i + 7) / 24.0)); for (j = 0; j < 4; ++j) { @@ -725,7 +725,7 @@ private: for (i = 0; i < 16; ++i) { - const double t = std::tan (i * double_Pi / 12.0); + const double t = std::tan (i * MathConstants::pi / 12.0); tan1_1[i] = (float) (t / (1.0 + t)); tan2_1[i] = (float) (1.0 / (1.0 + t)); tan1_2[i] = (float) (sqrt2 * t / (1.0 + t)); diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index 3365c45f1d..7c6398d44d 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -541,7 +541,7 @@ void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h, Path path; path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); - path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f)); + path.applyTransform (AffineTransform::rotation (MathConstants::twoPi * angle, 0.5f, 0.5f)); g.setColour (findColour (upDownButtonArrowColourId) .withAlpha (buttonDown ? 1.0f : (mouseOver ? 0.6f : 0.4f))); diff --git a/modules/juce_audio_utils/players/juce_SoundPlayer.cpp b/modules/juce_audio_utils/players/juce_SoundPlayer.cpp index 7b8acedb19..21854966a4 100644 --- a/modules/juce_audio_utils/players/juce_SoundPlayer.cpp +++ b/modules/juce_audio_utils/players/juce_SoundPlayer.cpp @@ -225,12 +225,11 @@ void SoundPlayer::play (PositionableAudioSource* audioSource, bool deleteWhenFin void SoundPlayer::playTestSound() { - const int soundLength = (int) sampleRate; + auto soundLength = (int) sampleRate; + double frequency = 440.0; + float amplitude = 0.5f; - const double frequency = 440.0; - const float amplitude = 0.5f; - - const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); + auto phasePerSample = MathConstants::twoPi / (sampleRate / frequency); auto* newSound = new AudioBuffer (1, soundLength); diff --git a/modules/juce_core/javascript/juce_Javascript.cpp b/modules/juce_core/javascript/juce_Javascript.cpp index aaa5fb1d14..9229217264 100644 --- a/modules/juce_core/javascript/juce_Javascript.cpp +++ b/modules/juce_core/javascript/juce_Javascript.cpp @@ -1700,7 +1700,7 @@ struct JavascriptEngine::RootObject : public DynamicObject setMethod ("sqr", Math_sqr); setMethod ("sqrt", Math_sqrt); setMethod ("ceil", Math_ceil); setMethod ("floor", Math_floor); - setProperty ("PI", double_Pi); + setProperty ("PI", MathConstants::pi); setProperty ("E", exp (1.0)); } diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index 59e6d7a87a..203796607a 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -336,6 +336,9 @@ struct MathConstants /** A predefined value for Pi */ static constexpr FloatType pi = static_cast (3.141592653589793238L); + /** A predefined value for 2 * Pi */ + static constexpr FloatType twoPi = static_cast (2 * 3.141592653589793238L); + /** A predfined value for Euler's number */ static constexpr FloatType euler = static_cast (2.71828182845904523536L); }; @@ -349,6 +352,9 @@ struct MathConstants /** A predefined value for Pi */ static const FloatType pi; + /** A predefined value for 2 * Pi */ + static const FloatType twoPi; + /** A predfined value for Euler's number */ static const FloatType euler; }; @@ -356,34 +362,37 @@ struct MathConstants template const FloatType MathConstants::pi = static_cast (3.141592653589793238L); +template +const FloatType MathConstants::twoPi = static_cast (2 * 3.141592653589793238L); + template const FloatType MathConstants::euler = static_cast (2.71828182845904523536L); #endif -/** A predefined value for Pi, at double-precision. - @see float_Pi +/** A double-precision constant for pi. + @deprecated This is deprecated in favour of MathConstants::pi. + The reason is that "double_Pi" was a confusing name, and many people misused it, + wrongly thinking it meant 2 * pi ! */ const JUCE_CONSTEXPR double double_Pi = MathConstants::pi; -/** A predefined value for Pi, at single-precision. - @see double_Pi +/** A single-precision constant for pi. + @deprecated This is deprecated in favour of MathConstants::pi. + The reason is that "double_Pi" was a confusing name, and many people misused it, + wrongly thinking it meant 2 * pi ! */ const JUCE_CONSTEXPR float float_Pi = MathConstants::pi; /** Converts an angle in degrees to radians. */ -inline JUCE_CONSTEXPR float degreesToRadians (float degrees) noexcept { return degrees * (float_Pi / 180.0f); } - -/** Converts an angle in degrees to radians. */ -inline JUCE_CONSTEXPR double degreesToRadians (double degrees) noexcept { return degrees * (double_Pi / 180.0); } - -/** Converts an angle in radians to degrees. */ -inline JUCE_CONSTEXPR float radiansToDegrees (float radians) noexcept { return radians * (180.0f / float_Pi); } +template +JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees) noexcept { return degrees * (MathConstants::pi / FloatType (180)); } /** Converts an angle in radians to degrees. */ -inline JUCE_CONSTEXPR double radiansToDegrees (double radians) noexcept { return radians * (180.0 / double_Pi); } +template +JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians) noexcept { return radians * (FloatType (180) / MathConstants::pi); } //============================================================================== diff --git a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp index f961fcabaa..287cc1dc68 100644 --- a/modules/juce_dsp/filter_design/juce_FilterDesign.cpp +++ b/modules/juce_dsp/filter_design/juce_FilterDesign.cpp @@ -52,7 +52,7 @@ typename FIR::Coefficients::Ptr } else { - auto indice = double_Pi * (static_cast (i) - 0.5 * static_cast (order)); + auto indice = MathConstants::pi * (static_cast (i) - 0.5 * static_cast (order)); c[i] = static_cast (std::sin (2.0 * indice * normalizedFrequency) / indice); } } @@ -81,8 +81,8 @@ typename FIR::Coefficients::Ptr else if (attenuationdB <= 21) beta = static_cast (0.5842 * std::pow (-attenuationdB - 21, 0.4) + 0.07886 * (-attenuationdB - 21)); - int order = attenuationdB < -21 ? roundDoubleToInt (ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * 2.0 * double_Pi))) - : roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * 2.0 * double_Pi))); + int order = attenuationdB < -21 ? roundDoubleToInt (ceil ((-attenuationdB - 7.95) / (2.285 * normalizedTransitionWidth * MathConstants::twoPi))) + : roundDoubleToInt (ceil (5.79 / (normalizedTransitionWidth * MathConstants::twoPi))); jassert (order >= 0); @@ -114,8 +114,8 @@ typename FIR::Coefficients::Ptr } else { - auto indice = double_Pi * (i - 0.5 * order); - auto indice2 = double_Pi * normalizedTransitionWidth * (i - 0.5 * order) / spline; + auto indice = MathConstants::pi * (i - 0.5 * order); + auto indice2 = MathConstants::pi * normalizedTransitionWidth * (i - 0.5 * order) / spline; c[i] = static_cast (std::sin (2 * indice * normalizedFrequency) / indice * std::pow (std::sin (indice2) / indice2, spline)); } @@ -138,8 +138,8 @@ typename FIR::Coefficients::Ptr auto normalizedFrequency = static_cast (frequency) / sampleRate; - auto wp = 2.0 * double_Pi * (static_cast (normalizedFrequency - normalizedTransitionWidth / 2.0)); - auto ws = 2.0 * double_Pi * (static_cast (normalizedFrequency + normalizedTransitionWidth / 2.0)); + auto wp = MathConstants::twoPi * (static_cast (normalizedFrequency - normalizedTransitionWidth / 2.0)); + auto ws = MathConstants::twoPi * (static_cast (normalizedFrequency + normalizedTransitionWidth / 2.0)); auto N = order + 1; @@ -154,10 +154,11 @@ typename FIR::Coefficients::Ptr Matrix b (M + 1, 1), q (2 * M + 1, 1); - auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * double_Pi) / (double_Pi * x); }; + auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * MathConstants::pi) + / (MathConstants::pi * x); }; - auto factorp = wp / double_Pi; - auto factors = ws / double_Pi; + auto factorp = wp / MathConstants::pi; + auto factors = ws / MathConstants::pi; for (size_t i = 0; i <= M; ++i) b (i, 0) = factorp * sinc (factorp * i); @@ -191,10 +192,11 @@ typename FIR::Coefficients::Ptr Matrix qp (2 * M, 1); Matrix qs (2 * M, 1); - auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * double_Pi) / (double_Pi * x); }; + auto sinc = [](double x) { return x == 0 ? 1 : std::sin (x * MathConstants::pi) + / (MathConstants::pi * x); }; - auto factorp = wp / double_Pi; - auto factors = ws / double_Pi; + auto factorp = wp / MathConstants::pi; + auto factors = ws / MathConstants::pi; for (size_t i = 0; i < M; ++i) b (i, 0) = factorp * sinc (factorp * (i + 0.5)); @@ -240,7 +242,7 @@ typename FIR::Coefficients::Ptr jassert (normalizedTransitionWidth > 0 && normalizedTransitionWidth <= 0.5); jassert (attenuationdB >= -300 && attenuationdB <= -10); - auto wpT = (0.5 - normalizedTransitionWidth) * double_Pi; + auto wpT = (0.5 - normalizedTransitionWidth) * MathConstants::pi; auto n = roundDoubleToInt (ceil ((attenuationdB - 18.18840664 * wpT + 33.64775300) / (18.54155181 * wpT - 29.13196871))); auto kp = (n * wpT - 1.57111377 * n + 0.00665857) / (-1.01927560 * n + 0.37221484); @@ -277,10 +279,10 @@ typename FIR::Coefficients::Ptr } else { - auto w01 = std::sqrt (kp * kp + (1 - kp * kp) * std::pow (std::cos (double_Pi / (2.0 * n + 1.0)), 2.0)); + auto w01 = std::sqrt (kp * kp + (1 - kp * kp) * std::pow (std::cos (MathConstants::pi / (2.0 * n + 1.0)), 2.0)); auto om01 = std::acos (-w01); - NN = -2.0 * result->getMagnitudeForFrequency (om01 / (2 * double_Pi), 1.0); + NN = -2.0 * result->getMagnitudeForFrequency (om01 / MathConstants::twoPi, 1.0); } for (int i = 0; i < hh.size(); ++i) @@ -403,8 +405,8 @@ Array> auto epsp = std::sqrt (1.0 / (Gp * Gp) - 1.0); auto epss = std::sqrt (1.0 / (Gs * Gs) - 1.0); - auto omegap = std::tan (double_Pi * fp); - auto omegas = std::tan (double_Pi * fs); + auto omegap = std::tan (MathConstants::pi * fp); + auto omegas = std::tan (MathConstants::pi * fs); auto k = omegap / omegas; auto k1 = epsp / epss; @@ -444,35 +446,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 * double_Pi * j)); + pa.add (omegap * std::pow (epsp, -1.0 / (double) N) * j * exp (ui * 0.5 * MathConstants::pi * j)); } } else if (type == 1) { - auto v0 = std::asinh (1.0 / epsp) / (0.5 * N * double_Pi); + auto v0 = std::asinh (1.0 / epsp) / (0.5 * N * MathConstants::pi); if (r == 1) - pa.add (-omegap * std::sinh (v0 * 0.5 * double_Pi)); + pa.add (-omegap * std::sinh (v0 * 0.5 * MathConstants::pi)); 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 * double_Pi)); + pa.add (omegap * j * std::cos ((ui - j * v0) * 0.5 * MathConstants::pi)); } } else if (type == 2) { - auto v0 = std::asinh (epss) / (N * 0.5 * double_Pi); + auto v0 = std::asinh (epss) / (N * 0.5 * MathConstants::pi); if (r == 1) - pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * double_Pi))); + pa.add(-1.0 / (k / omegap * std::sinh (v0 * 0.5 * MathConstants::pi))); 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 * double_Pi))); - za.add (1.0 / (k / omegap * j * std::cos (ui * 0.5 * double_Pi))); + 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))); } } else @@ -543,10 +545,10 @@ typename FilterDesign::IIRPolyphaseAllpassStructure jassert (normalizedTransitionWidth > 0 && normalizedTransitionWidth <= 0.5); jassert (stopbandAttenuationdB > -300 && stopbandAttenuationdB < -10); - const double wt = 2 * double_Pi * normalizedTransitionWidth; + const double wt = MathConstants::twoPi * normalizedTransitionWidth; const double ds = Decibels::decibelsToGain (stopbandAttenuationdB, static_cast (-300.0)); - auto k = std::pow (std::tan ((double_Pi - wt) / 4), 2.0); + auto k = std::pow (std::tan ((MathConstants::pi - wt) / 4), 2.0); auto kp = std::sqrt (1.0 - k * k); auto e = (1 - std::sqrt (kp)) / (1 + std::sqrt (kp)) * 0.5; auto q = e + 2 * std::pow (e, 5.0) + 15 * std::pow (e, 9.0) + 150 * std::pow (e, 13.0); @@ -575,7 +577,7 @@ typename FilterDesign::IIRPolyphaseAllpassStructure while (std::abs (delta) > 1e-100) { delta = std::pow (-1, m) * std::pow (q, m * (m + 1)) - * std::sin ((2 * m + 1) * double_Pi * i / (double) n); + * std::sin ((2 * m + 1) * MathConstants::pi * i / (double) n); num += delta; m++; } @@ -589,7 +591,7 @@ typename FilterDesign::IIRPolyphaseAllpassStructure while (std::abs (delta) > 1e-100) { delta = std::pow (-1, m) * std::pow (q, m * m) - * std::cos (2 * m * double_Pi * i / (double) n); + * std::cos (2 * m * MathConstants::pi * i / (double) n); den += delta; ++m; } diff --git a/modules/juce_dsp/frequency/juce_FFT.cpp b/modules/juce_dsp/frequency/juce_FFT.cpp index 2dfe9eb40c..f734c121ca 100644 --- a/modules/juce_dsp/frequency/juce_FFT.cpp +++ b/modules/juce_dsp/frequency/juce_FFT.cpp @@ -196,13 +196,13 @@ struct FFTFallback : public FFT::Instance FFTConfig (int sizeOfFFT, bool isInverse) : fftSize (sizeOfFFT), inverse (isInverse), twiddleTable ((size_t) sizeOfFFT) { - const double inverseFactor = (inverse ? 2.0 : -2.0) * double_Pi / (double) fftSize; + auto inverseFactor = (inverse ? 2.0 : -2.0) * MathConstants::pi / (double) fftSize; if (fftSize <= 4) { for (int i = 0; i < fftSize; ++i) { - const double phase = i * inverseFactor; + auto phase = i * inverseFactor; twiddleTable[i].real ((float) std::cos (phase)); twiddleTable[i].imag ((float) std::sin (phase)); @@ -212,7 +212,7 @@ struct FFTFallback : public FFT::Instance { for (int i = 0; i < fftSize / 4; ++i) { - const double phase = i * inverseFactor; + auto phase = i * inverseFactor; twiddleTable[i].real ((float) std::cos (phase)); twiddleTable[i].imag ((float) std::sin (phase)); @@ -220,7 +220,7 @@ struct FFTFallback : public FFT::Instance for (int i = fftSize / 4; i < fftSize / 2; ++i) { - const int index = i - fftSize / 4; + auto index = i - fftSize / 4; twiddleTable[i].real (inverse ? -twiddleTable[index].imag() : twiddleTable[index].imag()); twiddleTable[i].imag (inverse ? twiddleTable[index].real() : -twiddleTable[index].real()); @@ -231,12 +231,12 @@ struct FFTFallback : public FFT::Instance for (int i = fftSize / 2; i < fftSize; ++i) { - const int index = fftSize / 2 - (i - fftSize / 2); + auto index = fftSize / 2 - (i - fftSize / 2); twiddleTable[i] = conj(twiddleTable[index]); } } - const int root = (int) std::sqrt ((double) fftSize); + auto root = (int) std::sqrt ((double) fftSize); int divisor = 4, n = fftSize; for (int i = 0; i < numElementsInArray (factors); ++i) diff --git a/modules/juce_dsp/frequency/juce_FFT_test.cpp b/modules/juce_dsp/frequency/juce_FFT_test.cpp index 653102f0eb..5a15802914 100644 --- a/modules/juce_dsp/frequency/juce_FFT_test.cpp +++ b/modules/juce_dsp/frequency/juce_FFT_test.cpp @@ -56,25 +56,25 @@ struct FFTUnitTest : public UnitTest } static void performReferenceFourier (const Complex* in, Complex* out, - size_t n, bool reverve) + size_t n, bool reverse) { - float base_freq = static_cast(((reverve ? 1.0 : -1.0) * 2.0 * double_Pi) - / static_cast (n)); + auto base_freq = static_cast (((reverse ? 1.0 : -1.0) * MathConstants::twoPi) + / static_cast (n)); for (size_t i = 0; i < n; ++i) out[i] = freqConvolution (in, static_cast(i) * base_freq, n); } static void performReferenceFourier (const float* in, Complex* out, - size_t n, bool reverve) + size_t n, bool reverse) { HeapBlock> buffer (n); for (size_t i = 0; i < n; ++i) buffer.getData()[i] = Complex (in[i], 0.0f); - float base_freq = static_cast(((reverve ? 1.0 : -1.0) * 2.0 * double_Pi) - / static_cast (n)); + float base_freq = static_cast (((reverse ? 1.0 : -1.0) * MathConstants::twoPi) + / static_cast (n)); for (size_t i = 0; i < n; ++i) out[i] = freqConvolution (buffer.getData(), static_cast(i) * base_freq, n); diff --git a/modules/juce_dsp/maths/juce_SpecialFunctions.cpp b/modules/juce_dsp/maths/juce_SpecialFunctions.cpp index 55da31118b..cda31c857b 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 = double_Pi * 0.5; + K = MathConstants::pi * 0.5; 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 = double_Pi * 0.5; + Kp = MathConstants::pi * 0.5; auto last = std::sqrt (1 - k * k); for (int i = 0; i < M; ++i) @@ -86,7 +86,7 @@ Complex SpecialFunctions::cde (Complex u, double k) noexcept *++kei = next; } - std::complex last = std::cos (0.5 * u * double_Pi); + std::complex last = std::cos (0.5 * u * MathConstants::pi); for (int i = M - 1; i >= 0; --i) last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last); @@ -108,7 +108,7 @@ Complex SpecialFunctions::sne (Complex u, double k) noexcept *++kei = next; } - std::complex last = std::sin (0.5 * u * double_Pi); + std::complex last = std::sin (0.5 * u * MathConstants::pi); for (int i = M - 1; i >= 0; --i) last = (1.0 + ke[i + 1]) / (1.0 / last + ke[i + 1] * last); @@ -135,7 +135,7 @@ Complex SpecialFunctions::asne (Complex w, double k) noexcept for (int i = 1; i <= M; ++i) last = 2.0 * last / ((1.0 + ke[i]) * (1.0 + std::sqrt (1.0 - std::pow (ke[i - 1] * last, 2.0)))); - return 2.0 / double_Pi * std::asin (last); + return 2.0 / MathConstants::pi * std::asin (last); } } // namespace dsp diff --git a/modules/juce_dsp/processors/juce_FIRFilter.cpp b/modules/juce_dsp/processors/juce_FIRFilter.cpp index abcf5d27a9..b0607783be 100644 --- a/modules/juce_dsp/processors/juce_FIRFilter.cpp +++ b/modules/juce_dsp/processors/juce_FIRFilter.cpp @@ -39,7 +39,7 @@ double FIR::Coefficients::Coefficients::getMagnitudeForFrequency (d auto order = getFilterOrder(); Complex numerator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequency * j / theSampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequency * j / theSampleRate); const auto* coefs = coefficients.begin(); @@ -69,7 +69,7 @@ void FIR::Coefficients::Coefficients::getMagnitudeForFrequencyArray Complex numerator = 0.0; Complex factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / theSampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequencies[i] * j / theSampleRate); for (size_t n = 0; n <= order; ++n) { @@ -92,7 +92,7 @@ double FIR::Coefficients::Coefficients::getPhaseForFrequency (doubl Complex numerator = 0.0; Complex factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequency * j / theSampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequency * j / theSampleRate); const auto* coefs = coefficients.begin(); auto order = getFilterOrder(); @@ -122,7 +122,7 @@ void FIR::Coefficients::Coefficients::getPhaseForFrequencyArray (do jassert (frequencies[i] >= 0.0 && frequencies[i] <= theSampleRate * 0.5); Complex numerator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / theSampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequencies[i] * j / theSampleRate); for (size_t n = 0; n <= order; ++n) { diff --git a/modules/juce_dsp/processors/juce_IIRFilter.cpp b/modules/juce_dsp/processors/juce_IIRFilter.cpp index 1c3995968e..7cdf2f32b4 100644 --- a/modules/juce_dsp/processors/juce_IIRFilter.cpp +++ b/modules/juce_dsp/processors/juce_IIRFilter.cpp @@ -349,7 +349,7 @@ double IIR::Coefficients::getMagnitudeForFrequency (double frequenc jassert (frequency >= 0 && frequency <= sampleRate * 0.5); Complex numerator = 0.0, denominator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequency * j / sampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequency * j / sampleRate); for (size_t n = 0; n <= order; ++n) { @@ -384,7 +384,7 @@ void IIR::Coefficients::getMagnitudeForFrequencyArray (const double jassert (frequencies[i] >= 0 && frequencies[i] <= sampleRate * 0.5); Complex numerator = 0.0, denominator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequencies[i] * j / sampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequencies[i] * j / sampleRate); for (size_t n = 0; n <= order; ++n) { @@ -415,7 +415,7 @@ double IIR::Coefficients::getPhaseForFrequency (double frequency, d jassert (frequency >= 0 && frequency <= sampleRate * 0.5); Complex numerator = 0.0, denominator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequency * j / sampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequency * j / sampleRate); for (size_t n = 0; n <= order; ++n) { @@ -453,7 +453,7 @@ void IIR::Coefficients::getPhaseForFrequencyArray (double* frequenc jassert (frequencies[i] >= 0 && frequencies[i] <= sampleRate * 0.5); Complex numerator = 0.0, denominator = 0.0, factor = 1.0; - Complex jw = std::exp (-2.0 * double_Pi * frequencies[i] * j * invSampleRate); + Complex jw = std::exp (-MathConstants::twoPi * frequencies[i] * j * invSampleRate); for (size_t n = 0; n <= order; ++n) { diff --git a/modules/juce_dsp/processors/juce_LadderFilter.cpp b/modules/juce_dsp/processors/juce_LadderFilter.cpp index fcfd05e65d..c9161012ea 100644 --- a/modules/juce_dsp/processors/juce_LadderFilter.cpp +++ b/modules/juce_dsp/processors/juce_LadderFilter.cpp @@ -153,9 +153,9 @@ template void LadderFilter::setSampleRate (Type newValue) noexcept { jassert (newValue > Type (0)); - cutoffFreqScaler = Type (-2 * juce::double_Pi) / newValue; + cutoffFreqScaler = Type (-2.0 * juce::MathConstants::pi) / newValue; - static constexpr auto smootherRampTimeSec = Type (5e-2); + static constexpr Type smootherRampTimeSec (0.05); cutoffTransformSmoother.reset (newValue, smootherRampTimeSec); scaledResonanceSmoother.reset (newValue, smootherRampTimeSec); diff --git a/modules/juce_dsp/processors/juce_Oscillator.h b/modules/juce_dsp/processors/juce_Oscillator.h index 3851995bfe..d3cf2f51c3 100644 --- a/modules/juce_dsp/processors/juce_Oscillator.h +++ b/modules/juce_dsp/processors/juce_Oscillator.h @@ -63,8 +63,10 @@ public: { if (lookupTableNumPoints != 0) { - auto* table = new LookupTableTransform (function, static_cast (-1.0 * double_Pi), - static_cast (double_Pi), lookupTableNumPoints); + auto* table = new LookupTableTransform (function, + static_cast (-1.0 * MathConstants::pi), + static_cast (MathConstants::pi), + lookupTableNumPoints); lookupTable = table; generator = [table] (NumericType x) { return (*table) (x); }; @@ -106,9 +108,9 @@ public: SampleType JUCE_VECTOR_CALLTYPE processSample (SampleType) noexcept { jassert (isInitialised()); - auto increment = static_cast (2.0 * double_Pi) * frequency.getNextValue() / sampleRate; - auto value = generator (pos - static_cast (double_Pi)); - pos = std::fmod (pos + increment, static_cast (2.0 * double_Pi)); + auto increment = static_cast (MathConstants::twoPi) * frequency.getNextValue() / sampleRate; + auto value = generator (pos - static_cast (MathConstants::pi)); + pos = std::fmod (pos + increment, static_cast (MathConstants::twoPi)); return value; } @@ -126,7 +128,7 @@ public: auto len = outBlock.getNumSamples(); auto numChannels = outBlock.getNumChannels(); - auto baseIncrement = static_cast (2.0 * double_Pi) / sampleRate; + auto baseIncrement = static_cast (MathConstants::twoPi) / sampleRate; if (frequency.isSmoothing()) { @@ -134,9 +136,10 @@ public: for (size_t i = 0; i < len; ++i) { - buffer[i] = pos - static_cast (double_Pi); + buffer[i] = pos - static_cast (MathConstants::pi); - pos = std::fmod (pos + (baseIncrement * frequency.getNextValue()), static_cast (2.0 * double_Pi)); + pos = std::fmod (pos + (baseIncrement * frequency.getNextValue()), + static_cast (MathConstants::twoPi)); } for (size_t ch = 0; ch < numChannels; ++ch) @@ -158,12 +161,13 @@ public: for (size_t i = 0; i < len; ++i) { - dst[i] = generator (p - static_cast (double_Pi)); - p = std::fmod (p + freq, static_cast (2.0 * double_Pi)); + dst[i] = generator (p - static_cast (MathConstants::pi)); + p = std::fmod (p + freq, static_cast (MathConstants::twoPi)); } } - pos = std::fmod (pos + freq * static_cast (len), static_cast (2.0 * double_Pi)); + pos = std::fmod (pos + freq * static_cast (len), + static_cast (MathConstants::twoPi)); } } diff --git a/modules/juce_dsp/processors/juce_Oversampling.cpp b/modules/juce_dsp/processors/juce_Oversampling.cpp index 88589fd400..657da301ae 100644 --- a/modules/juce_dsp/processors/juce_Oversampling.cpp +++ b/modules/juce_dsp/processors/juce_Oversampling.cpp @@ -286,11 +286,11 @@ public: { auto structureUp = dsp::FilterDesign::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthUp, stopbandAttenuationdBUp); dsp::IIR::Coefficients coeffsUp = getCoefficients (structureUp); - latency = static_cast (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi)); + latency = static_cast (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants::twoPi)); auto structureDown = dsp::FilterDesign::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthDown, stopbandAttenuationdBDown); dsp::IIR::Coefficients coeffsDown = getCoefficients (structureDown); - latency += static_cast (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi)); + latency += static_cast (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants::twoPi)); for (auto i = 0; i < structureUp.directPath.size(); i++) coefficientsUp.add (structureUp.directPath[i].coefficients[0]); diff --git a/modules/juce_dsp/processors/juce_StateVariableFilter.h b/modules/juce_dsp/processors/juce_StateVariableFilter.h index 35d24acb11..279c2d0471 100644 --- a/modules/juce_dsp/processors/juce_StateVariableFilter.h +++ b/modules/juce_dsp/processors/juce_StateVariableFilter.h @@ -187,7 +187,7 @@ namespace StateVariableFilter void setCutOffFrequency (double sampleRate, NumericType frequency, NumericType resonance = static_cast (1.0 / std::sqrt (2.0))) noexcept { - g = static_cast (std::tan (double_Pi * frequency / sampleRate)); + g = static_cast (std::tan (MathConstants::pi * frequency / sampleRate)); R2 = static_cast (1.0 / resonance); h = static_cast (1.0 / (1.0 + R2 * g + g * g)); } @@ -204,7 +204,7 @@ namespace StateVariableFilter Parameters& operator= (const Parameters& o) noexcept { g = o.g; R2 = o.R2; h = o.h; return *this; } //============================================================================== - NumericType g = static_cast (std::tan (double_Pi * 200.0 / 44100.0)); + NumericType g = static_cast (std::tan (MathConstants::pi * 200.0 / 44100.0)); NumericType R2 = static_cast (std::sqrt (2.0)); NumericType h = static_cast (1.0 / (1.0 + R2 * g + g * g)); }; diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp index 849d4a0835..455aa13325 100644 --- a/modules/juce_graphics/geometry/juce_Path.cpp +++ b/modules/juce_graphics/geometry/juce_Path.cpp @@ -631,7 +631,7 @@ void Path::addPieSegment (const float x, const float y, startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, fromRadians)); addArc (x, y, width, height, fromRadians, toRadians); - if (std::abs (fromRadians - toRadians) > float_Pi * 1.999f) + if (std::abs (fromRadians - toRadians) > MathConstants::pi * 1.999f) { closeSubPath(); @@ -714,7 +714,7 @@ void Path::addPolygon (Point centre, int numberOfSides, if (numberOfSides > 1) { - auto angleBetweenPoints = float_Pi * 2.0f / numberOfSides; + auto angleBetweenPoints = MathConstants::twoPi / numberOfSides; for (int i = 0; i < numberOfSides; ++i) { @@ -738,7 +738,7 @@ void Path::addStar (Point centre, int numberOfPoints, float innerRadius, if (numberOfPoints > 1) { - auto angleBetweenPoints = float_Pi * 2.0f / numberOfPoints; + auto angleBetweenPoints = MathConstants::twoPi / numberOfPoints; for (int i = 0; i < numberOfPoints; ++i) { @@ -784,7 +784,7 @@ void Path::addBubble (Rectangle bodyArea, } lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY()); - addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, float_Pi * 0.5f); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, MathConstants::pi * 0.5f); 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, float_Pi * 0.5f, float_Pi); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants::pi * 0.5f, MathConstants::pi); if (Rectangle (targetLimit.getX(), bodyArea.getBottom(), targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip)) @@ -806,7 +806,7 @@ void Path::addBubble (Rectangle bodyArea, } lineTo (bodyArea.getX() + cornerSizeW, bodyArea.getBottom()); - addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, float_Pi, float_Pi * 1.5f); + addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, MathConstants::pi, MathConstants::pi * 1.5f); if (Rectangle (maximumArea.getX(), targetLimit.getY(), bodyArea.getX() - maximumArea.getX(), targetLimit.getHeight()).contains (arrowTip)) @@ -817,7 +817,7 @@ void Path::addBubble (Rectangle bodyArea, } lineTo (bodyArea.getX(), bodyArea.getY() + cornerSizeH); - addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, float_Pi * 1.5f, float_Pi * 2.0f - 0.05f); + addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, MathConstants::pi * 1.5f, MathConstants::twoPi - 0.05f); closeSubPath(); } diff --git a/modules/juce_graphics/geometry/juce_PathStrokeType.cpp b/modules/juce_graphics/geometry/juce_PathStrokeType.cpp index 8069a696d2..d1b3d177e3 100644 --- a/modules/juce_graphics/geometry/juce_PathStrokeType.cpp +++ b/modules/juce_graphics/geometry/juce_PathStrokeType.cpp @@ -243,13 +243,13 @@ namespace PathStrokeHelpers if (std::abs (angle1 - angle2) > angleIncrement) { - if (angle2 > angle1 + float_Pi - || (angle2 < angle1 && angle2 >= angle1 - float_Pi)) + if (angle2 > angle1 + MathConstants::pi + || (angle2 < angle1 && angle2 >= angle1 - MathConstants::pi)) { if (angle2 > angle1) - angle2 -= float_Pi * 2.0f; + angle2 -= MathConstants::twoPi; - jassert (angle1 <= angle2 + float_Pi); + jassert (angle1 <= angle2 + MathConstants::pi); angle1 -= angleIncrement; while (angle1 > angle2) @@ -263,9 +263,9 @@ namespace PathStrokeHelpers else { if (angle1 > angle2) - angle1 -= float_Pi * 2.0f; + angle1 -= MathConstants::twoPi; - jassert (angle1 >= angle2 - float_Pi); + jassert (angle1 >= angle2 - MathConstants::pi); angle1 += angleIncrement; while (angle1 < angle2) diff --git a/modules/juce_gui_basics/buttons/juce_ArrowButton.cpp b/modules/juce_gui_basics/buttons/juce_ArrowButton.cpp index fa76bc1d3d..a5abb5264b 100644 --- a/modules/juce_gui_basics/buttons/juce_ArrowButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_ArrowButton.cpp @@ -31,7 +31,7 @@ ArrowButton::ArrowButton (const String& name, float arrowDirectionInRadians, Col : Button (name), colour (arrowColour) { path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); - path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians, 0.5f, 0.5f)); + path.applyTransform (AffineTransform::rotation (MathConstants::twoPi * arrowDirectionInRadians, 0.5f, 0.5f)); } ArrowButton::~ArrowButton() {} diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index 0d55c5161e..f5666c7d52 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -1611,10 +1611,10 @@ private: return result; } - static void endpointToCentreParameters (const double x1, const double y1, - const double x2, const double y2, - const double angle, - const bool largeArc, const bool sweep, + static void endpointToCentreParameters (double x1, double y1, + double x2, double y2, + double angle, + bool largeArc, bool sweep, double& rx, double& ry, double& centreX, double& centreY, double& startAngle, double& deltaAngle) noexcept @@ -1669,7 +1669,7 @@ private: if (uy < 0) startAngle = -startAngle; - startAngle += double_Pi * 0.5; + startAngle += MathConstants::pi * 0.5; deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy)) / (length * juce_hypot (vx, vy)))); @@ -1680,15 +1680,15 @@ private: if (sweep) { if (deltaAngle < 0) - deltaAngle += double_Pi * 2.0; + deltaAngle += MathConstants::twoPi; } else { if (deltaAngle > 0) - deltaAngle -= double_Pi * 2.0; + deltaAngle -= MathConstants::twoPi; } - deltaAngle = fmod (deltaAngle, double_Pi * 2.0); + deltaAngle = fmod (deltaAngle, MathConstants::twoPi); } SVGState& operator= (const SVGState&) JUCE_DELETED_FUNCTION; diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp index 4d015c9d74..4f005ccf15 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp @@ -623,9 +623,9 @@ void LookAndFeel_V2::drawSpinningWaitAnimation (Graphics& g, const Colour& colou for (uint32 i = 0; i < 12; ++i) { const uint32 n = (i + 12 - animationIndex) % 12; - g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); - g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f)) + g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f)); + g.fillPath (p, AffineTransform::rotation (i * (MathConstants::pi / 6.0f)) .translated (cx, cy)); } } @@ -2024,16 +2024,16 @@ 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, float_Pi * 0.5f); + p.addArc (x + w - cs2, y, cs2, cs2, 0, MathConstants::pi * 0.5f); p.lineTo (x + w, y + h - cs); - p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi); + p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, MathConstants::pi * 0.5f, MathConstants::pi); p.lineTo (x + cs, y + h); - p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f); + p.addArc (x, y + h - cs2, cs2, cs2, MathConstants::pi, MathConstants::pi * 1.5f); p.lineTo (x, y + cs); - p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f); + p.addArc (x, y, cs2, cs2, MathConstants::pi * 1.5f, MathConstants::twoPi); p.lineTo (x + textX, y); const float alpha = group.isEnabled() ? 1.0f : 0.5f; @@ -2207,8 +2207,8 @@ void LookAndFeel_V2::drawTabButtonText (TabBarButton& button, Graphics& g, bool switch (button.getTabbedButtonBar().getOrientation()) { - case TabbedButtonBar::TabsAtLeft: t = t.rotated (float_Pi * -0.5f).translated (area.getX(), area.getBottom()); break; - case TabbedButtonBar::TabsAtRight: t = t.rotated (float_Pi * 0.5f).translated (area.getRight(), area.getY()); break; + case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants::pi * -0.5f).translated (area.getX(), area.getBottom()); break; + case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants::pi * 0.5f).translated (area.getRight(), area.getY()); break; case TabbedButtonBar::TabsAtTop: case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break; default: jassertfalse; break; @@ -2948,7 +2948,7 @@ void LookAndFeel_V2::drawGlassPointer (Graphics& g, p.lineTo (x, y + diameter * 0.6f); p.closeSubPath(); - p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); + p.applyTransform (AffineTransform::rotation (direction * (MathConstants::pi * 0.5f), 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_V3.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V3.cpp index 5ff181a10e..df7feb784d 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V3.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V3.cpp @@ -259,8 +259,8 @@ void LookAndFeel_V3::drawTabButton (TabBarButton& button, Graphics& g, bool isMo switch (o) { - case TabbedButtonBar::TabsAtLeft: t = t.rotated (float_Pi * -0.5f).translated (area.getX(), area.getBottom()); break; - case TabbedButtonBar::TabsAtRight: t = t.rotated (float_Pi * 0.5f).translated (area.getRight(), area.getY()); break; + case TabbedButtonBar::TabsAtLeft: t = t.rotated (MathConstants::pi * -0.5f).translated (area.getX(), area.getBottom()); break; + case TabbedButtonBar::TabsAtRight: t = t.rotated (MathConstants::pi * 0.5f).translated (area.getRight(), area.getY()); break; case TabbedButtonBar::TabsAtTop: case TabbedButtonBar::TabsAtBottom: t = t.translated (area.getX(), area.getY()); break; default: jassertfalse; break; diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp index 11bde9a26f..c101c39f0e 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp @@ -569,7 +569,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, ProgressBar& progress barBounds.getWidth() * 0.5f, barBounds.getHeight() * 0.5f, 0.0f, 0.0f, - 2.0f * float_Pi, + MathConstants::twoPi, true); g.strokePath (arcPath2, PathStrokeType (4.0f)); @@ -584,7 +584,7 @@ void LookAndFeel_V4::drawCircularProgressBar (Graphics& g, ProgressBar& progress degreesToRadians (endInDegrees), true); - arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * float_Pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); + arcPath.applyTransform (AffineTransform::rotation (normalisedRotation * MathConstants::pi * 2.25f, barBounds.getCentreX(), barBounds.getCentreY())); g.strokePath (arcPath, PathStrokeType (4.0f)); if (progressText.isNotEmpty()) @@ -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 - float_Pi * 0.5f), - bounds.getCentreY() + arcRadius * std::sin (toAngle - float_Pi * 0.5f)); + Point thumbPoint (bounds.getCentreX() + arcRadius * std::cos (toAngle - MathConstants::pi * 0.5f), + bounds.getCentreY() + arcRadius * std::sin (toAngle - MathConstants::pi * 0.5f)); g.setColour (slider.findColour (Slider::thumbColourId)); g.fillEllipse (Rectangle (thumbWidth, thumbWidth).withCentre (thumbPoint)); @@ -1089,7 +1089,7 @@ 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 * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); + p.applyTransform (AffineTransform::rotation (direction * (MathConstants::pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f)); g.setColour (colour); g.fillPath (p); diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp index 126d0ada07..7fac55204c 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp @@ -130,8 +130,8 @@ int MouseEvent::getMouseDownScreenX() const { return getMous int MouseEvent::getMouseDownScreenY() const { return getMouseDownScreenPosition().y; } bool MouseEvent::isPressureValid() const noexcept { return pressure > 0.0f && pressure < 1.0f; } -bool MouseEvent::isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= 2.0f * float_Pi; } -bool MouseEvent::isRotationValid() const noexcept { return rotation >= 0 && rotation <= 2.0f * float_Pi; } +bool MouseEvent::isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= MathConstants::twoPi; } +bool MouseEvent::isRotationValid() const noexcept { return rotation >= 0 && rotation <= MathConstants::twoPi; } bool MouseEvent::isTiltValid (bool isX) const noexcept { return isX ? (tiltX >= -1.0f && tiltX <= 1.0f) : (tiltY >= -1.0f && tiltY <= 1.0f); } //============================================================================== diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index 5bb71d29bd..07a9225b2c 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -106,8 +106,8 @@ public: } bool isPressureValid() const noexcept { return pressure >= 0.0f && pressure <= 1.0f; } - bool isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= 2.0f * float_Pi; } - bool isRotationValid() const noexcept { return rotation >= 0.0f && rotation <= 2.0f * float_Pi; } + bool isOrientationValid() const noexcept { return orientation >= 0.0f && orientation <= MathConstants::twoPi; } + bool isRotationValid() const noexcept { return rotation >= 0.0f && rotation <= MathConstants::twoPi; } bool isTiltValid (bool isX) const noexcept { return isX ? (tiltX >= -1.0f && tiltX <= 1.0f) : (tiltY >= -1.0f && tiltY <= 1.0f); } //============================================================================== diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index c6c8f77ed3..71a3cca0e3 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -39,8 +39,8 @@ public: style (sliderStyle), textBoxPos (textBoxPosition) { - rotaryParams.startAngleRadians = float_Pi * 1.2f; - rotaryParams.endAngleRadians = float_Pi * 2.8f; + rotaryParams.startAngleRadians = MathConstants::pi * 1.2f; + rotaryParams.endAngleRadians = MathConstants::pi * 2.8f; rotaryParams.stopAtEnd = true; } @@ -676,16 +676,16 @@ public: auto angle = std::atan2 ((double) dx, (double) -dy); while (angle < 0.0) - angle += double_Pi * 2.0; + angle += MathConstants::twoPi; if (rotaryParams.stopAtEnd && e.mouseWasDraggedSinceMouseDown()) { - if (std::abs (angle - lastAngle) > double_Pi) + if (std::abs (angle - lastAngle) > MathConstants::pi) { if (angle >= lastAngle) - angle -= double_Pi * 2.0; + angle -= MathConstants::twoPi; else - angle += double_Pi * 2.0; + angle += MathConstants::twoPi; } if (angle >= lastAngle) @@ -696,7 +696,7 @@ public: else { while (angle < rotaryParams.startAngleRadians) - angle += double_Pi * 2.0; + angle += MathConstants::twoPi; if (angle > rotaryParams.endAngleRadians) { @@ -777,9 +777,9 @@ public: if (speed != 0.0) { speed = 0.2 * velocityModeSensitivity - * (1.0 + std::sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset - + jmax (0.0, (double) (speed - velocityModeThreshold)) - / maxSpeed)))); + * (1.0 + std::sin (MathConstants::pi * (1.5 + jmin (0.5, velocityModeOffset + + jmax (0.0, (double) (speed - velocityModeThreshold)) + / maxSpeed)))); if (mouseDiff < 0) speed = -speed; @@ -1321,8 +1321,8 @@ public: static double smallestAngleBetween (double a1, double a2) noexcept { return jmin (std::abs (a1 - a2), - std::abs (a1 + double_Pi * 2.0 - a2), - std::abs (a2 + double_Pi * 2.0 - a1)); + std::abs (a1 + MathConstants::twoPi - a2), + std::abs (a2 + MathConstants::twoPi - a1)); } }; @@ -1370,7 +1370,8 @@ void Slider::setRotaryParameters (RotaryParameters p) noexcept { // make sure the values are sensible.. jassert (p.startAngleRadians >= 0 && p.endAngleRadians >= 0); - jassert (p.startAngleRadians < float_Pi * 4.0f && p.endAngleRadians < float_Pi * 4.0f); + jassert (p.startAngleRadians < MathConstants::pi * 4.0f + && p.endAngleRadians < MathConstants::pi * 4.0f); pimpl->rotaryParams = p; }