Skip to content

Commit

Permalink
Replace large 'magic' double values with DBL_MAX
Browse files Browse the repository at this point in the history
and remove unneeded includes which QtCreator warns about
  • Loading branch information
Jojo-Schmitz committed Mar 25, 2024
1 parent cfe95be commit 33cafe9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 47 deletions.
11 changes: 4 additions & 7 deletions libmscore/chordrest.cpp
Expand Up @@ -19,18 +19,15 @@
#include "staff.h"
#include "tuplet.h"
#include "score.h"
#include "sym.h"
#include "slur.h"
#include "beam.h"
#include "breath.h"
#include "barline.h"
#include "articulation.h"
#include "tempo.h"
#include "tempotext.h"
#include "note.h"
#include "arpeggio.h"
#include "dynamic.h"
#include "stafftext.h"
#include "sig.h"
#include "clef.h"
#include "lyrics.h"
Expand Down Expand Up @@ -1260,8 +1257,8 @@ Shape ChordRest::shape() const
{
Shape shape;
{
qreal x1 = 1000000.0;
qreal x2 = -1000000.0;
qreal x1 = DBL_MAX;
qreal x2 = -DBL_MAX;
bool adjustWidth = false;
for (Lyrics* l : _lyrics) {
if (!l || !l->addToSkyline())
Expand All @@ -1283,8 +1280,8 @@ Shape ChordRest::shape() const
}

{
qreal x1 = 1000000.0;
qreal x2 = -1000000.0;
qreal x1 = DBL_MAX;
qreal x2 = -DBL_MAX;
bool adjustWidth = false;
for (Element* e : segment()->annotations()) {
if (!e || !e->addToSkyline())
Expand Down
2 changes: 1 addition & 1 deletion libmscore/keyfinder.cpp
Expand Up @@ -521,7 +521,7 @@ static void match_profiles()

for (key=0; key<56; ++key) {
kprob[key] = 0.0;
keyscore()[key][s] = -1000000.0;
keyscore()[key][s] = -DBL_MAX;
if (npc_or_tpc_profile==0 && (key<9 || (key>20 && key<37) || key>48))
continue;
kprob[key] = 1.0;
Expand Down
11 changes: 2 additions & 9 deletions libmscore/measure.cpp
Expand Up @@ -35,37 +35,30 @@
#include "fret.h"
#include "glissando.h"
#include "hairpin.h"
#include "harmony.h"
#include "hook.h"
#include "icon.h"
#include "image.h"
#include "key.h"
#include "keysig.h"
#include "layoutbreak.h"
#include "layout.h"
#include "note.h"
#include "ottava.h"
#include "page.h"
#include "part.h"
#include "pedal.h"
#include "pitchspelling.h"
#include "repeat.h"
#include "rest.h"
#include "score.h"
#include "segment.h"
#include "select.h"
#include "sig.h"
#include "slur.h"
#include "spacer.h"
#include "staff.h"
#include "stafftext.h"
#include "stafftype.h"
#include "stem.h"
#include "stringdata.h"
#include "style.h"
#include "sym.h"
#include "system.h"
#include "tempotext.h"
#include "measurenumber.h"
#include "mmrestrange.h"
#include "tie.h"
Expand Down Expand Up @@ -4493,7 +4486,7 @@ void Measure::computeMinWidth(Segment* s, qreal x, bool isSystemHeader)
if (!fs->visible()) // first enabled could be a clef change on invisible staff
fs = fs->nextActive();
bool first = isFirstInSystem();
const Shape ls(first ? QRectF(0.0, -1000000.0, 0.0, 2000000.0) : QRectF(0.0, 0.0, 0.0, spatium() * 4));
const Shape ls(first ? QRectF(0.0, -DBL_MAX, 0.0, DBL_MAX) : QRectF(0.0, 0.0, 0.0, spatium() * 4));

if (isMMRest()) {
// Reset MM rest to initial size and position
Expand Down Expand Up @@ -4615,7 +4608,7 @@ void Measure::computeMinWidth()
// left barriere:
// Make sure no elements crosses the left boarder if first measure in a system.
//
Shape ls(first ? QRectF(0.0, -1000000.0, 0.0, 2000000.0) : QRectF(0.0, 0.0, 0.0, spatium() * 4));
Shape ls(first ? QRectF(0.0, -DBL_MAX, 0.0, DBL_MAX) : QRectF(0.0, 0.0, 0.0, spatium() * 4));

x = s->minLeft(ls);

Expand Down
4 changes: 1 addition & 3 deletions libmscore/segment.cpp
Expand Up @@ -18,15 +18,13 @@
#include "score.h"
#include "beam.h"
#include "tuplet.h"
#include "text.h"
#include "measure.h"
#include "barline.h"
#include "part.h"
#include "repeat.h"
#include "staff.h"
#include "line.h"
#include "hairpin.h"
#include "ottava.h"
#include "sig.h"
#include "keysig.h"
#include "staffstate.h"
Expand Down Expand Up @@ -2217,7 +2215,7 @@ qreal Segment::minHorizontalCollidingDistance(Segment* ns) const
qreal Segment::minHorizontalDistance(Segment* ns, bool systemHeaderGap) const
{

qreal ww = -1000000.0; // can remain negative
qreal ww = -DBL_MAX; // can remain negative
for (unsigned staffIdx = 0; staffIdx < _shapes.size(); ++staffIdx) {
if (score()->staff(staffIdx) && !score()->staff(staffIdx)->show())
continue;
Expand Down
13 changes: 6 additions & 7 deletions libmscore/shape.cpp
Expand Up @@ -11,7 +11,6 @@
//=============================================================================

#include "shape.h"
#include "segment.h"

namespace Ms {

Expand Down Expand Up @@ -81,7 +80,7 @@ Shape Shape::translated(const QPointF& pt) const

qreal Shape::minHorizontalDistance(const Shape& a) const
{
qreal dist = -1000000.0; // min real
qreal dist = -DBL_MAX; // min real
for (const QRectF& r2 : a) {
qreal by1 = r2.top();
qreal by2 = r2.bottom();
Expand All @@ -105,7 +104,7 @@ qreal Shape::minHorizontalDistance(const Shape& a) const

qreal Shape::minVerticalDistance(const Shape& a) const
{
qreal dist = -1000000.0; // min real
qreal dist = -DBL_MAX; // min real
for (const QRectF& r2 : a) {
if (r2.height() <= 0.0)
continue;
Expand Down Expand Up @@ -160,7 +159,7 @@ qreal Shape::right() const

qreal Shape::top() const
{
qreal dist = 1000000.0;
qreal dist = DBL_MAX;
for (const QRectF& r : *this) {
if (r.top() < dist)
dist = r.top();
Expand All @@ -174,7 +173,7 @@ qreal Shape::top() const

qreal Shape::bottom() const
{
qreal dist = -1000000.0;
qreal dist = -DBL_MAX;
for (const QRectF& r : *this) {
if (r.bottom() > dist)
dist = r.bottom();
Expand All @@ -190,7 +189,7 @@ qreal Shape::bottom() const

qreal Shape::topDistance(const QPointF& p) const
{
qreal dist = 1000000.0;
qreal dist = DBL_MAX;
for (const QRectF& r : *this) {
if (p.x() >= r.left() && p.x() < r.right())
dist = qMin(dist, r.top() - p.y());
Expand All @@ -206,7 +205,7 @@ qreal Shape::topDistance(const QPointF& p) const

qreal Shape::bottomDistance(const QPointF& p) const
{
qreal dist = 1000000.0;
qreal dist = DBL_MAX;
for (const QRectF& r : *this) {
if (p.x() >= r.left() && p.x() < r.right())
dist = qMin(dist, p.y() - r.bottom());
Expand Down
15 changes: 6 additions & 9 deletions libmscore/skyline.cpp
Expand Up @@ -11,13 +11,10 @@
//=============================================================================

#include "skyline.h"
#include "segment.h"
#include "shape.h"

namespace Ms {

static const qreal MAXIMUM_Y = 1000000.0;
static const qreal MINIMUM_Y = -1000000.0;

// #define SKL_DEBUG

#ifdef SKL_DEBUG
Expand Down Expand Up @@ -176,7 +173,7 @@ void SkylineLine::add(qreal x, qreal y, qreal w)
}
if (x >= cx) {
if (x > cx) {
qreal cy = north ? MAXIMUM_Y : MINIMUM_Y;
qreal cy = north ? DBL_MAX : -DBL_MAX;
DP(" append1 %f %f\n", cy, x - cx);
append(cx, cy, x - cx);
}
Expand Down Expand Up @@ -210,7 +207,7 @@ qreal Skyline::minDistance(const Skyline& s) const

qreal SkylineLine::minDistance(const SkylineLine& sl) const
{
qreal dist = MINIMUM_Y;
qreal dist = -DBL_MAX;

qreal x1 = 0.0;
qreal x2 = 0.0;
Expand Down Expand Up @@ -287,7 +284,7 @@ bool SkylineLine::valid() const

bool SkylineLine::valid(const SkylineSegment& s) const
{
return north ? (s.y != MAXIMUM_Y) : (s.y != MINIMUM_Y);
return north ? (s.y != DBL_MAX) : (s.y != -DBL_MAX);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -320,12 +317,12 @@ qreal SkylineLine::max() const
{
qreal val;
if (north) {
val = MAXIMUM_Y;
val = DBL_MAX;
for (const SkylineSegment& s : *this)
val = qMin(val, s.y);
}
else {
val = MINIMUM_Y;
val = -DBL_MAX;
for (const SkylineSegment& s : *this)
val = qMax(val, s.y);
}
Expand Down
9 changes: 4 additions & 5 deletions mscore/chordview.cpp
Expand Up @@ -15,7 +15,6 @@
#include "libmscore/chord.h"
#include "libmscore/note.h"
#include "libmscore/noteevent.h"
#include "preferences.h"
#include "musescore.h"
#include "libmscore/mscore.h"
#include "libmscore/score.h"
Expand Down Expand Up @@ -181,10 +180,10 @@ void ChordView::drawBackground(QPainter* p, const QRectF& r)
{
if (chord == 0)
return;
QRectF r1(-1000000.0, 0.0, 1000000.0+CHORD_MAP_OFFSET, 1000000.0);
QRectF r2(ticks + CHORD_MAP_OFFSET, 0.0, 1000000.0, 1000000.0);
QRectF r3(-1000000.0, 127*keyHeight, 1000000.0+CHORD_MAP_OFFSET, keyHeight);
QRectF r4(ticks + CHORD_MAP_OFFSET, 127*keyHeight, 1000000.0, keyHeight);
QRectF r1(-DBL_MAX, 0.0, DBL_MAX, DBL_MAX);
QRectF r2(ticks + CHORD_MAP_OFFSET, 0.0, DBL_MAX, DBL_MAX);
QRectF r3(-DBL_MAX, 127*keyHeight, DBL_MAX, keyHeight);
QRectF r4(ticks + CHORD_MAP_OFFSET, 127*keyHeight, DBL_MAX, keyHeight);

QColor bg(0x71, 0x8d, 0xbe);
QColor bg1 = bg.darker(150);
Expand Down
5 changes: 2 additions & 3 deletions mscore/drumview.cpp
Expand Up @@ -24,7 +24,6 @@
#include "libmscore/chord.h"
#include "libmscore/score.h"
#include "libmscore/note.h"
#include "libmscore/slur.h"
#include "libmscore/segment.h"

namespace Ms {
Expand Down Expand Up @@ -112,9 +111,9 @@ void DrumView::drawBackground(QPainter* p, const QRectF& r)
Score* _score = staff->score();

QRectF r1;
r1.setCoords(-1000000.0, 0.0, 480.0, 1000000.0);
r1.setCoords(-DBL_MAX, 0.0, 480.0, DBL_MAX);
QRectF r2;
r2.setCoords(ticks + 480, 0.0, 1000000.0, 1000000.0);
r2.setCoords(ticks + 480, 0.0, DBL_MAX, DBL_MAX);
QColor bg(0x71, 0x8d, 0xbe);

p->fillRect(r, bg);
Expand Down
6 changes: 3 additions & 3 deletions mscore/pianoroll/pianoview.cpp
Expand Up @@ -378,12 +378,12 @@ void PianoView::drawBackground(QPainter* p, const QRectF& r)

const QPen penLineMajor = QPen(colGridLine, 2.0, Qt::SolidLine);
const QPen penLineMinor = QPen(colGridLine, 1.0, Qt::SolidLine);
const QPen penLineSub = QPen(colGridLine, 1.0, Qt::DotLine);
const QPen penLineSub = QPen(colGridLine, 1.0, Qt::DotLine);

QRectF r1;
r1.setCoords(-1000000.0, 0.0, tickToPixelX(0), 1000000.0);
r1.setCoords(-DBL_MAX, 0.0, tickToPixelX(0), DBL_MAX);
QRectF r2;
r2.setCoords(tickToPixelX(_ticks), 0.0, 1000000.0, 1000000.0);
r2.setCoords(tickToPixelX(_ticks), 0.0, DBL_MAX, DBL_MAX);

p->fillRect(r, colWhiteKeyBg);
if (r.intersects(r1))
Expand Down

0 comments on commit 33cafe9

Please sign in to comment.