RasterProcessTool/RasterMainWidgetGUI/RasterMainWidget/LAMPMainWidget.h

57 lines
1.2 KiB
C
Raw Normal View History

2025-02-07 09:16:22 +00:00
#pragma once
#include <QtCore/QtGlobal>
#include <QtCore/QDebug>
#include <QtCore/QTime>
#include <QRandomGenerator>
2025-02-07 09:16:22 +00:00
namespace LAMPMainWidget {
/*
*
*/
const double DoublePrecision{0.00000001};
/*
* d1d2
* @param d1
* @param d2
* @param precision
* @return truefalse
*/
inline bool
isDoubleNearby(double d1, double d2, double precision = DoublePrecision) {
return qAbs(d1 - d2) < precision;
}
/*
* minmax
* @param min
* @param max
* @return
*/
inline int
randomInt(int min, int max) {
if (max <= min) {
qDebug() << "随机数的最大值大于最小值";
return -1;
}
//qsrand(static_cast<uint>(QTime{0, 0}.msecsTo(QTime::currentTime())));
quint32 seed = static_cast<quint32>(QTime{ 0, 0 }.msecsTo(QTime::currentTime()));
QRandomGenerator seededGenerator(seed);
return min + seededGenerator.bounded(max - min) ;
2025-02-07 09:16:22 +00:00
}
/*
* 2
* @param n
* @return
*/
inline int
power2(int n) {
return 1u << static_cast<unsigned>(n);
}
}