1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Global: Avoid floating-point equality checks where possible

This commit is contained in:
reuk 2023-03-23 12:02:38 +00:00
parent 081b1ff216
commit 28414a6af8
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
150 changed files with 762 additions and 672 deletions

View file

@ -30,7 +30,7 @@ ColourGradient::ColourGradient() noexcept : isRadial (false)
{
#if JUCE_DEBUG
point1.setX (987654.0f);
#define JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED jassert (point1.x != 987654.0f);
#define JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED jassert (! exactlyEqual (point1.x, 987654.0f));
#else
#define JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED
#endif
@ -174,7 +174,7 @@ void ColourGradient::setColour (int index, Colour newColour) noexcept
Colour ColourGradient::getColourAtPosition (double position) const noexcept
{
jassert (colours.getReference(0).position == 0.0); // the first colour specified has to go at position 0
jassert (approximatelyEqual (colours.getReference (0).position, 0.0)); // the first colour specified has to go at position 0
if (position <= 0 || colours.size() <= 1)
return colours.getReference(0).colour;
@ -199,7 +199,7 @@ void ColourGradient::createLookupTable (PixelARGB* const lookupTable, const int
JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED // Trying to use this object without setting its coordinates?
jassert (colours.size() >= 2);
jassert (numEntries > 0);
jassert (colours.getReference(0).position == 0.0); // The first colour specified has to go at position 0
jassert (approximatelyEqual (colours.getReference(0).position, 0.0)); // The first colour specified has to go at position 0
int index = 0;
@ -258,12 +258,13 @@ bool ColourGradient::isInvisible() const noexcept
bool ColourGradient::ColourPoint::operator== (ColourPoint other) const noexcept
{
return position == other.position && colour == other.colour;
const auto tie = [] (const ColourPoint& p) { return std::tie (p.position, p.colour); };
return tie (*this) == tie (other);
}
bool ColourGradient::ColourPoint::operator!= (ColourPoint other) const noexcept
{
return position != other.position || colour != other.colour;
return ! operator== (other);
}
} // namespace juce