Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 137b11fd authored by Vincent Pinon's avatar Vincent Pinon

Switch to qFuzzy* float comparison function

parent 85f6cd3a
......@@ -278,7 +278,7 @@ bool KeyframeModel::updateKeyframe(GenTime pos, QVariant value, Fun &undo, Fun &
QVariant oldValue = m_keyframeList[pos].second;
// Chek if keyframe is different
if (m_paramType == ParamType::KeyframeParam) {
if (qAbs(oldValue.toDouble() - value.toDouble()) < 1e-6) return true;
if (qFuzzyCompare(oldValue.toDouble(), value.toDouble())) return true;
}
auto operation = updateKeyframe_lambda(pos, type, value, true);
auto reverse = updateKeyframe_lambda(pos, type, oldValue, true);
......
......@@ -2677,7 +2677,7 @@ void Bin::slotGotFilterJobResults(const QString &id, int startPos, int track, co
int index = 1;
bool simpleList = false;
double sourceFps = clip->getOriginalFps();
if (qAbs(sourceFps) < 1e-4) {
if (qFuzzyIsNull(sourceFps)) {
sourceFps = pCore->getCurrentFps();
}
if (filterInfo.contains(QStringLiteral("simplelist"))) {
......@@ -2743,7 +2743,7 @@ void Bin::showTitleWidget(std::shared_ptr<ProjectClip> clip)
if (dia_ui.exec() == QDialog::Accepted) {
QMap<QString, QString> newprops;
newprops.insert(QStringLiteral("xmldata"), dia_ui.xml().toString());
if (qAbs(dia_ui.duration() - clip->duration().frames(pCore->getCurrentFps())) > 1e-4) {
if (!qFuzzyCompare((double)dia_ui.duration(), clip->duration().frames(pCore->getCurrentFps()))) {
// duration changed, we need to update duration
newprops.insert(QStringLiteral("out"), QString::number(dia_ui.duration() - 1));
int currentLength = clip->getProducerIntProperty(QStringLiteral("kdenlive:duration"));
......
......@@ -356,7 +356,7 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
qCDebug(KDENLIVE_LOG) << "Opening a document with version " << version << " / " << currentVersion;
// No conversion needed
if (qAbs(version - currentVersion) < 0.001) {
if (qFuzzyCompare(version, currentVersion)) {
return true;
}
......@@ -371,7 +371,7 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
}
// Unsupported document versions
if (version <= 0.5 || version == 0.7) {
if (qFuzzyCompare(version, 0.5) || qFuzzyCompare(version, 0.7)) {
// 0.7 is unsupported
// qCDebug(KDENLIVE_LOG) << "Unable to open document with version " << version;
KMessageBox::sorry(QApplication::activeWindow(), i18n("This project type is unsupported (version %1) and can't be loaded.", version),
......
......@@ -1304,7 +1304,7 @@ void KdenliveDoc::updateProjectProfile(bool reloadProducers)
return;
}
emit updateFps(fpsChanged);
if (qAbs(fpsChanged - 1.0) > 1e-6) {
if (!qFuzzyCompare(fpsChanged, 1.0)) {
pCore->bin()->reloadAllProducers();
}
}
......@@ -1383,18 +1383,18 @@ void KdenliveDoc::switchProfile(std::unique_ptr<ProfileParam> &profile, const QS
profile->m_frame_rate_den = 1;
} else {
// Check for 23.98, 29.97, 59.94
if (qAbs(fps_int - 23.0) < 1e-5) {
if (qAbs(fps - 23.98) < 0.01) {
if (qFuzzyCompare(fps_int, 23.0)) {
if (qFuzzyCompare(fps, 23.98)) {
profile->m_frame_rate_num = 24000;
profile->m_frame_rate_den = 1001;
}
} else if (qAbs(fps_int - 29.0) < 1e-5) {
if (qAbs(fps - 29.97) < 0.01) {
} else if (qFuzzyCompare(fps_int, 29.0)) {
if (qFuzzyCompare(fps, 29.97)) {
profile->m_frame_rate_num = 30000;
profile->m_frame_rate_den = 1001;
}
} else if (qAbs(fps_int - 59.0) < 1e-5) {
if (qAbs(fps - 59.94) < 0.01) {
} else if (qFuzzyCompare(fps_int, 59.0)) {
if (qFuzzyCompare(fps, 59.94)) {
profile->m_frame_rate_num = 60000;
profile->m_frame_rate_den = 1001;
}
......@@ -1403,7 +1403,7 @@ void KdenliveDoc::switchProfile(std::unique_ptr<ProfileParam> &profile, const QS
adjustMessage = i18n("\nWarning: unknown non integer fps, might cause incorrect duration display.");
}
}
if (qAbs((double)profile->m_frame_rate_num / profile->m_frame_rate_den - fps) < 1e-4) {
if (qFuzzyCompare((double)profile->m_frame_rate_num / profile->m_frame_rate_den, fps)) {
adjustMessage = i18n("\nProfile fps adjusted from original %1", QString::number(fps, 'f', 4));
}
if (KMessageBox::warningContinueCancel(QApplication::activeWindow(),
......
......@@ -304,7 +304,7 @@ void DvdWizardVob::slotAddVobFile(const QUrl &url, const QString &chapters, bool
double fps = profile.fps();
profile.from_producer(*producer);
profile.set_explicit(1);
if (abs(profile.fps()-fps)>0.001) {
if (!qFuzzyCompare(profile.fps(),fps)) {
// fps changed, rebuild producer
delete producer;
producer = new Mlt::Producer(profile, resource.toUtf8().data());
......@@ -321,7 +321,7 @@ void DvdWizardVob::slotAddVobFile(const QUrl &url, const QString &chapters, bool
item->setData(1, Qt::UserRole, playTime);
int standard = -1;
int aspect = profile.dar() * 100;
if (profile.height() == 576 && profile.fps() == 25.0) {
if (profile.height() == 576 && qFuzzyCompare(profile.fps(), 25.0)) {
if (aspect > 150) {
standard = 1;
} else {
......@@ -793,7 +793,7 @@ void DvdWizardVob::slotTranscodedClip(const QString &src, const QString &transco
double fps = profile.fps();
profile.from_producer(*producer);
profile.set_explicit(1);
if (abs(profile.fps()-fps)>0.001) {
if (!qFuzzyCompare(profile.fps(),fps)) {
// fps changed, rebuild producer
delete producer;
producer = new Mlt::Producer(profile, resource.toUtf8().data());
......
......@@ -341,7 +341,7 @@ bool LoadJob::startJob()
original_profile.set_explicit(1);
double originalFps = original_profile.fps();
fps = originalFps;
if (originalFps > 0 && qAbs(originalFps - pCore->getCurrentFps()) > 1e-4) {
if (originalFps > 0 && !qFuzzyCompare(originalFps, pCore->getCurrentFps())) {
int originalLength = tmpProd->get_length();
int fixedLength = (int)(originalLength * pCore->getCurrentFps() / originalFps);
m_producer->set("length", fixedLength);
......
......@@ -119,7 +119,7 @@ bool MeltJob::startJob()
m_profile.set_explicit(1);
}
configureProfile();
if (qAbs(m_profile.fps() - fps) > 0.01 || m_useProducerProfile) {
if (!qFuzzyCompare(m_profile.fps(), fps) || m_useProducerProfile) {
// Reload producer
// Force same fps as projec profile or the resulting .mlt will not load in our project
m_profile.set_frame_rate(fps_num, fps_den);
......
......@@ -474,7 +474,7 @@ void GLWidget::paintGL()
// Set model view.
QMatrix4x4 modelView;
if (qAbs(m_zoom-1.0)>0.01) {
if (!qFuzzyCompare(m_zoom, 1.0f)) {
if ((offset().x() != 0) || (offset().y() != 0)) modelView.translate(-offset().x() * devicePixelRatio(), offset().y() * devicePixelRatio());
modelView.scale(zoom(), zoom());
}
......@@ -571,17 +571,17 @@ void GLWidget::wheelEvent(QWheelEvent *event)
{
if (((event->modifiers() & Qt::ControlModifier) != 0u) && ((event->modifiers() & Qt::ShiftModifier) != 0u)) {
if (event->delta() > 0) {
if (qAbs(m_zoom-1.0)<0.01) {
if (qFuzzyCompare(m_zoom, 1.0f)) {
setZoom(2.0f);
} else if (qAbs(m_zoom-2.0)<0.01) {
} else if (qFuzzyCompare(m_zoom, 2.0f)) {
setZoom(3.0f);
} else if (m_zoom < 1.0) {
} else if (m_zoom < 1.0f) {
setZoom(m_zoom * 2);
}
} else {
if (qAbs(m_zoom-3.0)<0.01) {
if (qFuzzyCompare(m_zoom, 3.0f)) {
setZoom(2.0);
} else if (qAbs(m_zoom-2.0)<0.01) {
} else if (qFuzzyCompare(m_zoom, 2.0f)) {
setZoom(1.0);
} else if (m_zoom > 0.2) {
setZoom(m_zoom / 2);
......@@ -599,7 +599,7 @@ void GLWidget::requestSeek()
return;
}
if (m_proxy->seekPosition() != SEEK_INACTIVE) {
if (qAbs(m_producer->get_speed()) > 0.001) {
if (!qFuzzyIsNull(m_producer->get_speed())) {
m_consumer->purge();
}
m_producer->seek(m_proxy->seekPosition());
......@@ -615,7 +615,7 @@ void GLWidget::seek(int pos)
// Testing puspose only
if (m_proxy->seekPosition() == SEEK_INACTIVE) {
m_proxy->setSeekPosition(pos);
if (qAbs(m_producer->get_speed()) > 0.001) {
if (!qFuzzyIsNull(m_producer->get_speed())) {
m_consumer->purge();
}
m_producer->seek(pos);
......@@ -630,7 +630,7 @@ void GLWidget::seek(int pos)
void GLWidget::requestRefresh()
{
if ((m_producer != nullptr) && (qAbs(m_producer->get_speed()) < 0.001)) {
if ((m_producer != nullptr) && qFuzzyIsNull(m_producer->get_speed())) {
m_refreshTimer.start();
}
}
......@@ -657,12 +657,12 @@ bool GLWidget::checkFrameNumber(int pos)
if (m_proxy->seekPosition() != SEEK_INACTIVE) {
m_producer->set_speed(0);
m_producer->seek(m_proxy->seekPosition());
if (qAbs(speed) < 0.001) {
if (qFuzzyIsNull(speed)) {
m_consumer->set("refresh", 1);
} else {
m_producer->set_speed(speed);
}
} else if (qAbs(speed) < 0.001) {
} else if (qFuzzyIsNull(speed)) {
if (m_isLoopMode) {
if (pos >= m_producer->get_int("out") - 1) {
m_consumer->purge();
......@@ -1699,7 +1699,7 @@ void GLWidget::switchPlay(bool play, double speed)
m_consumer->stop();
}
}
if (qAbs(currentSpeed) < 0.001) {
if (qFuzzyIsNull(currentSpeed)) {
m_consumer->start();
m_consumer->set("refresh", 1);
} else {
......
......@@ -740,7 +740,7 @@ void Monitor::adjustScrollBars(float horizontal, float vertical)
void Monitor::setZoom()
{
if (qAbs(m_glMonitor->zoom() - 1.0) < 0.01) {
if (qFuzzyCompare(m_glMonitor->zoom(), 1.0f)) {
m_horizontalScroll->hide();
m_verticalScroll->hide();
m_glMonitor->setOffsetX(m_horizontalScroll->value(), m_horizontalScroll->maximum());
......@@ -1130,7 +1130,7 @@ void Monitor::slotZoneEnd()
void Monitor::slotRewind(double speed)
{
slotActivateMonitor();
if (abs(speed) < 0.001) {
if (qFuzzyIsNull(speed)) {
double currentspeed = m_glMonitor->playSpeed();
if (currentspeed >= 0) {
speed = -1;
......@@ -1156,7 +1156,7 @@ void Monitor::slotRewind(double speed)
void Monitor::slotForward(double speed)
{
slotActivateMonitor();
if (abs(speed) < 0.001) {
if (qFuzzyIsNull(speed)) {
double currentspeed = m_glMonitor->playSpeed();
if (currentspeed <= 0) {
speed = 1;
......
......@@ -51,7 +51,7 @@ void ProfileFilter::setFilterFps(bool enabled, double fps)
bool ProfileFilter::filterFps(std::unique_ptr<ProfileModel> &ptr) const
{
return !m_fps_enabled || qAbs(ptr->fps() - m_fps_value) < 1e-4;
return !m_fps_enabled || qFuzzyCompare(ptr->fps(), m_fps_value);
}
bool ProfileFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
......
......@@ -61,7 +61,7 @@ void ClipSpeed::slotUpdateSlider(double speed)
m_view.speedSlider->blockSignals(true);
m_view.speedSlider->setValue((int)speed);
m_view.speedSlider->blockSignals(false);
m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(qAbs(speed) > 1e-6);
m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!qFuzzyIsNull(speed));
}
void ClipSpeed::slotUpdateSpeed(int speed)
......
......@@ -158,7 +158,7 @@ void Render::seek(int time)
time = qBound(0, time, m_mltProducer->get_length() - 1);
if (requestedSeekPosition == SEEK_INACTIVE) {
requestedSeekPosition = time;
if (qAbs(m_mltProducer->get_speed()) > 1e-5) {
if (!qFuzzyIsNull(m_mltProducer->get_speed())) {
m_mltConsumer->purge();
}
m_mltProducer->seek(time);
......
......@@ -331,7 +331,7 @@ void ClipModel::useTimewarpProducer(double speed, int extraSpace)
out = warp_out / speed;
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
std::shared_ptr<Mlt::Producer> originalProducer = binClip->originalProducer();
if (qAbs(speed - 1.0) < 0.001) {
if (qFuzzyCompare(speed, 1.0)) {
m_producer.reset(originalProducer->cut(in, out));
} else {
QString resource = QString("%1:%2").arg(speed).arg(originalProducer->get("resource"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment