Use Qt abstractions of cmath functions.

This commit is contained in:
Jim Evins
2016-12-23 22:09:49 -05:00
parent 34da3fe17c
commit 6dba70dfd1
13 changed files with 25 additions and 62 deletions
+1 -5
View File
@@ -20,8 +20,6 @@
#include "BarcodeStyle.h" #include "BarcodeStyle.h"
#include <algorithm>
/// ///
/// Default Constructor /// Default Constructor
@@ -163,11 +161,9 @@ int BarcodeStyle::preferedN() const
/// ///
QString BarcodeStyle::exampleDigits( int n ) const QString BarcodeStyle::exampleDigits( int n ) const
{ {
using std::max;
if ( mCanFreeform ) if ( mCanFreeform )
{ {
return QString( max( n, 1 ), QChar('0') ); return QString( qMax( n, 1 ), QChar('0') );
} }
else else
{ {
+11 -21
View File
@@ -20,8 +20,7 @@
#include "LabelEditor.h" #include "LabelEditor.h"
#include <algorithm> #include <QtMath>
#include <cmath>
#include <QMouseEvent> #include <QMouseEvent>
#include <QtDebug> #include <QtDebug>
@@ -181,11 +180,11 @@ LabelEditor::zoomIn()
// Find closest standard zoom level to our current zoom // Find closest standard zoom level to our current zoom
// Start with 2nd largest scale // Start with 2nd largest scale
int i_min = 1; int i_min = 1;
double dist_min = fabs( zoomLevels[1] - mZoom ); double dist_min = qFabs( zoomLevels[1] - mZoom );
for ( int i = 2; i < nZoomLevels; i++ ) for ( int i = 2; i < nZoomLevels; i++ )
{ {
double dist = fabs( zoomLevels[i] - mZoom ); double dist = qFabs( zoomLevels[i] - mZoom );
if ( dist < dist_min ) if ( dist < dist_min )
{ {
i_min = i; i_min = i;
@@ -207,11 +206,11 @@ LabelEditor::zoomOut()
// Find closest standard zoom level to our current zoom // Find closest standard zoom level to our current zoom
// Start with largest scale, end on 2nd smallest // Start with largest scale, end on 2nd smallest
int i_min = 0; int i_min = 0;
double dist_min = fabs( zoomLevels[0] - mZoom ); double dist_min = qFabs( zoomLevels[0] - mZoom );
for ( int i = 1; i < (nZoomLevels-1); i++ ) for ( int i = 1; i < (nZoomLevels-1); i++ )
{ {
double dist = fabs( zoomLevels[i] - mZoom ); double dist = qFabs( zoomLevels[i] - mZoom );
if ( dist < dist_min ) if ( dist < dist_min )
{ {
i_min = i; i_min = i;
@@ -240,19 +239,16 @@ LabelEditor::zoom1To1()
void void
LabelEditor::zoomToFit() LabelEditor::zoomToFit()
{ {
using std::min;
using std::max;
double wPixels = mScrollArea->maximumViewportSize().width(); double wPixels = mScrollArea->maximumViewportSize().width();
double hPixels = mScrollArea->maximumViewportSize().height(); double hPixels = mScrollArea->maximumViewportSize().height();
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt(); double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt(); double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
double newZoom = min( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX(); double newZoom = qMin( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
// Limits // Limits
newZoom = min( newZoom, zoomLevels[0] ); newZoom = qMin( newZoom, zoomLevels[0] );
newZoom = max( newZoom, zoomLevels[nZoomLevels-1] ); newZoom = qMax( newZoom, zoomLevels[nZoomLevels-1] );
setZoomReal( newZoom, true ); setZoomReal( newZoom, true );
} }
@@ -563,9 +559,6 @@ LabelEditor::mousePressEvent( QMouseEvent* event )
void void
LabelEditor::mouseMoveEvent( QMouseEvent* event ) LabelEditor::mouseMoveEvent( QMouseEvent* event )
{ {
using std::min;
using std::max;
if ( mModel ) if ( mModel )
{ {
/* /*
@@ -1211,9 +1204,6 @@ void LabelEditor::onSettingsChanged()
/// ///
void LabelEditor::onModelSizeChanged() void LabelEditor::onModelSizeChanged()
{ {
using std::min;
using std::max;
if (mZoomToFitFlag) if (mZoomToFitFlag)
{ {
double wPixels = mScrollArea->maximumViewportSize().width(); double wPixels = mScrollArea->maximumViewportSize().width();
@@ -1221,11 +1211,11 @@ void LabelEditor::onModelSizeChanged()
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt(); double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt(); double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
double newZoom = min( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX(); double newZoom = qMin( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
// Limits // Limits
newZoom = min( newZoom, zoomLevels[0] ); newZoom = qMin( newZoom, zoomLevels[0] );
newZoom = max( newZoom, zoomLevels[nZoomLevels-1] ); newZoom = qMax( newZoom, zoomLevels[nZoomLevels-1] );
mZoom = newZoom; mZoom = newZoom;
} }
-5
View File
@@ -21,8 +21,6 @@
#include "LabelModel.h" #include "LabelModel.h"
#include <QFileInfo> #include <QFileInfo>
#include <algorithm>
#include <cmath>
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QMimeData> #include <QMimeData>
@@ -500,9 +498,6 @@ void LabelModel::unselectAll()
/// ///
void LabelModel::selectRegion( const LabelRegion &region ) void LabelModel::selectRegion( const LabelRegion &region )
{ {
using std::min;
using std::max;
glabels::Distance rX1 = min( region.x1(), region.x2() ); glabels::Distance rX1 = min( region.x1(), region.x2() );
glabels::Distance rY1 = min( region.y1(), region.y2() ); glabels::Distance rY1 = min( region.y1(), region.y2() );
glabels::Distance rX2 = max( region.x1(), region.x2() ); glabels::Distance rX2 = max( region.x1(), region.x2() );
+5 -8
View File
@@ -21,8 +21,6 @@
#include "LabelModelObject.h" #include "LabelModelObject.h"
#include <QFont> #include <QFont>
#include <algorithm>
#include <cmath>
#include <QtDebug> #include <QtDebug>
#include "ColorNode.h" #include "ColorNode.h"
@@ -874,8 +872,7 @@ void LabelModelObject::setHHonorAspect( const glabels::Distance& h )
/// ///
LabelRegion LabelModelObject::getExtent() LabelRegion LabelModelObject::getExtent()
{ {
using std::min; using namespace glabels;
using std::max;
QPointF a1( ( - lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); QPointF a1( ( - lineWidth()/2).pt(), ( - lineWidth()/2).pt() );
QPointF a2( (mW + lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); QPointF a2( (mW + lineWidth()/2).pt(), ( - lineWidth()/2).pt() );
@@ -888,10 +885,10 @@ LabelRegion LabelModelObject::getExtent()
a4 = mMatrix.map( a4 ); a4 = mMatrix.map( a4 );
LabelRegion region; LabelRegion region;
region.setX1( glabels::Distance(min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) )) + mX0 ); region.setX1( min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) ) + mX0 );
region.setY1( glabels::Distance(min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) )) + mY0 ); region.setY1( min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) ) + mY0 );
region.setX2( glabels::Distance(max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) )) + mX0 ); region.setX2( max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) ) + mX0 );
region.setY2( glabels::Distance(max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) )) + mY0 ); region.setY2( max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) ) + mY0 );
return region; return region;
} }
-6
View File
@@ -20,9 +20,6 @@
#include "LabelRegion.h" #include "LabelRegion.h"
#include <algorithm>
#include <cmath>
/// ///
/// Get x1 /// Get x1
@@ -101,9 +98,6 @@ void LabelRegion::setY2( const glabels::Distance& value )
/// ///
QRectF LabelRegion::rect() const QRectF LabelRegion::rect() const
{ {
using std::min;
using std::fabs;
QRectF r; QRectF r;
r.setX( min( mX1, mX2 ).pt() ); r.setX( min( mX1, mX2 ).pt() );
-1
View File
@@ -21,7 +21,6 @@
#include "Text.h" #include "Text.h"
#include "Record.h" #include "Record.h"
#include <algorithm>
#include <QtDebug> #include <QtDebug>
+4 -4
View File
@@ -34,7 +34,7 @@
#include "Settings.h" #include "Settings.h"
#include <QFileDialog> #include <QFileDialog>
#include <cmath> #include <QtMath>
#include <QtDebug> #include <QtDebug>
@@ -180,7 +180,7 @@ void ObjectEditor::loadLineSizePage()
double w = mObject->w().inUnits(mUnits); double w = mObject->w().inUnits(mUnits);
double h = mObject->h().inUnits(mUnits); double h = mObject->h().inUnits(mUnits);
sizeLineLengthSpin->setValue( sqrt( w*w + h*h ) ); sizeLineLengthSpin->setValue( sqrt( w*w + h*h ) );
sizeLineAngleSpin->setValue( (180/M_PI)*atan2( h, w ) ); sizeLineAngleSpin->setValue( qRadiansToDegrees( qAtan2( h, w ) ) );
mBlocked = false; mBlocked = false;
} }
@@ -515,9 +515,9 @@ void ObjectEditor::onLineSizeControlsChanged()
mUndoRedoModel->checkpoint( tr("Size") ); mUndoRedoModel->checkpoint( tr("Size") );
glabels::Distance spinLength = glabels::Distance(sizeLineLengthSpin->value(), mUnits); glabels::Distance spinLength = glabels::Distance(sizeLineLengthSpin->value(), mUnits);
double spinAngleRads = (M_PI/180)*sizeLineAngleSpin->value(); double spinAngleRads = qDegreesToRadians( sizeLineAngleSpin->value() );
mObject->setSize( spinLength*cos(spinAngleRads), spinLength*sin(spinAngleRads) ); mObject->setSize( spinLength*qCos(spinAngleRads), spinLength*qSin(spinAngleRads) );
mBlocked = false; mBlocked = false;
} }
+2 -2
View File
@@ -20,7 +20,7 @@
#include "Constants.h" #include "Constants.h"
#include <cmath> #include <QtMath>
namespace glabels namespace glabels
@@ -195,7 +195,7 @@ namespace glabels
inline Distance fabs( const Distance& d ) inline Distance fabs( const Distance& d )
{ {
return Distance::pt( std::fabs( d.mDPts ) ); return Distance::pt( qFabs( d.mDPts ) );
} }
-2
View File
@@ -20,8 +20,6 @@
#include "FrameCd.h" #include "FrameCd.h"
#include <cmath>
#include "StrUtil.h" #include "StrUtil.h"
#include "privateConstants.h" #include "privateConstants.h"
#include <QtDebug> #include <QtDebug>
-2
View File
@@ -20,8 +20,6 @@
#include "FrameEllipse.h" #include "FrameEllipse.h"
#include <cmath>
#include "StrUtil.h" #include "StrUtil.h"
#include "privateConstants.h" #include "privateConstants.h"
-2
View File
@@ -20,8 +20,6 @@
#include "FrameRect.h" #include "FrameRect.h"
#include <cmath>
#include "StrUtil.h" #include "StrUtil.h"
#include "privateConstants.h" #include "privateConstants.h"
-2
View File
@@ -20,8 +20,6 @@
#include "FrameRound.h" #include "FrameRound.h"
#include <cmath>
#include "StrUtil.h" #include "StrUtil.h"
#include "privateConstants.h" #include "privateConstants.h"
+2 -2
View File
@@ -20,7 +20,7 @@
#include "StrUtil.h" #include "StrUtil.h"
#include <cmath> #include <QtMath>
namespace namespace
@@ -49,7 +49,7 @@ namespace glabels
for ( i=0; denom[i] != 0.0; i++ ) for ( i=0; denom[i] != 0.0; i++ )
{ {
product = x * denom[i]; product = x * denom[i];
remainder = fabs(product - ((int)(product+0.5))); remainder = qFabs(product - ((int)(product+0.5)));
if ( remainder < FRAC_EPSILON ) break; if ( remainder < FRAC_EPSILON ) break;
} }