mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
* require qwt >=6.2 (and fallback to internal 6.3 if system's qwt doesn't suffice) * debian doesn't have qwt for Qt6 and won't have it for trixie
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/******************************************************************************
|
|
* Qwt Widget Library
|
|
* Copyright (C) 1997 Josef Wilgen
|
|
* Copyright (C) 2002 Uwe Rathmann
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the Qwt License, Version 1.0
|
|
*****************************************************************************/
|
|
|
|
#include "qwt_math.h"
|
|
#if QT_VERSION >= 0x050a00
|
|
#include <qrandom.h>
|
|
#endif
|
|
|
|
/*!
|
|
\brief Normalize an angle to be int the range [0.0, 2 * PI[
|
|
\param radians Angle in radians
|
|
\return Normalized angle in radians
|
|
*/
|
|
double qwtNormalizeRadians( double radians )
|
|
{
|
|
double a = std::fmod( radians, 2.0 * M_PI );
|
|
if ( a < 0.0 )
|
|
a += 2.0 * M_PI;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
/*!
|
|
\brief Normalize an angle to be int the range [0.0, 360.0[
|
|
\param radians Angle in degrees
|
|
\return Normalized angle in degrees
|
|
*/
|
|
double qwtNormalizeDegrees( double degrees )
|
|
{
|
|
double a = std::fmod( degrees, 360.0 );
|
|
if ( a < 0.0 )
|
|
a += 360.0;
|
|
|
|
return a;
|
|
}
|
|
|
|
/*!
|
|
\brief Uses QRandomGenerator for Qt >= 5.10 and qRand() otherwise
|
|
\return A 32-bit random quantity
|
|
*/
|
|
quint32 qwtRand()
|
|
{
|
|
#if QT_VERSION >= 0x050a00
|
|
return QRandomGenerator::global()->generate();
|
|
#else
|
|
return static_cast< quint32 >( qrand() ); // [0, RAND_MAX ]
|
|
#endif
|
|
}
|