Skip to content

Commit

Permalink
Remove unneeded private method and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 11, 2014
1 parent 2e972b1 commit 8aaf8b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
42 changes: 19 additions & 23 deletions src/core/qgsmaptopixel.cpp
Expand Up @@ -29,15 +29,15 @@ QgsMapToPixel::QgsMapToPixel( double mapUnitsPerPixel,
double yc,
int width,
int height,
double rotation )
double rotation )
: mMapUnitsPerPixel( mapUnitsPerPixel )
, mWidth( width )
, mHeight( height )
, mRotation( rotation )
, xCenter( xc )
, yCenter( yc )
, xMin ( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
, yMin ( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
, xMin( xc - ( mWidth * mMapUnitsPerPixel / 2.0 ) )
, yMin( yc - ( mHeight * mMapUnitsPerPixel / 2.0 ) )
{
updateMatrix();
}
Expand All @@ -49,8 +49,8 @@ QgsMapToPixel::QgsMapToPixel()
, mRotation( 0.0 )
, xCenter( 0.5 )
, yCenter( 0.5 )
, xMin ( 0 )
, yMin ( 0 )
, xMin( 0 )
, yMin( 0 )
{
updateMatrix();
}
Expand All @@ -65,8 +65,8 @@ QgsMapToPixel::QgsMapToPixel( double mapUnitsPerPixel,
, mRotation( 0.0 )
, xCenter( 0.0 )
, yCenter( 0.0 )
, xMin ( xmin )
, yMin ( ymin )
, xMin( xmin )
, yMin( ymin )
{
updateMatrix();
}
Expand Down Expand Up @@ -106,28 +106,23 @@ void QgsMapToPixel::updateMatrix()
// results from an existing test, see
// https://travis-ci.org/qgis/QGIS/builds/42508945
mMatrix = QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
.translate( -xMin, - ( yMin + mHeight*mMapUnitsPerPixel ) );
.translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
return;
}

double cy = mapHeight() / 2.0;
double cx = mapWidth() / 2.0;
mMatrix = QTransform::fromTranslate( cx, cy )
.rotate( rotation )
.scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
.translate( -xCenter, -yCenter )
;
}

const QTransform& QgsMapToPixel::getMatrix() const
{
return mMatrix;
.rotate( rotation )
.scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
.translate( -xCenter, -yCenter )
;
}

QgsPoint QgsMapToPixel::toMapPoint( double x, double y ) const
{
bool invertible;
QTransform matrix = getMatrix().inverted( &invertible );
QTransform matrix = mMatrix.inverted( &invertible );
assert( invertible );
double mx, my;
matrix.map( x, y, &mx, &my );
Expand Down Expand Up @@ -170,9 +165,10 @@ void QgsMapToPixel::setMapRotation( double degrees, double cx, double cy )
mRotation = degrees;
xCenter = cx;
yCenter = cy;
if ( mWidth < 0 ) {
if ( mWidth < 0 )
{
// set width not that we can compute it
mWidth = (( xCenter -xMin )*2 ) / mMapUnitsPerPixel;
mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
}
updateMatrix();
}
Expand Down Expand Up @@ -216,7 +212,7 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
double yc,
int width,
int height,
double rotation )
double rotation )
{
mMapUnitsPerPixel = mapUnitsPerPixel;
xCenter = xc;
Expand All @@ -234,7 +230,7 @@ QString QgsMapToPixel::showParameters() const
QString rep;
QTextStream( &rep ) << "Map units/pixel: " << mMapUnitsPerPixel
<< " center: " << xCenter << "," << yCenter
<< " rotation: " << mRotation
<< " rotation: " << mRotation
<< " size: " << mWidth << "x" << mHeight;
return rep;

Expand Down Expand Up @@ -273,7 +269,7 @@ void QgsMapToPixel::transformInPlace( qreal& x, qreal& y ) const
{
// Map 2 Pixel

QTransform matrix = getMatrix();
QTransform matrix = mMatrix;

This comment has been minimized.

Copy link
@strk

strk Dec 11, 2014

Contributor

This could be a const reference, to avoid the copy

This comment has been minimized.

Copy link
@3nids

3nids Dec 11, 2014

Member

The private var can be used directly, map is constant.
2b210a5

double mx, my;
matrix.map( x, y, &mx, &my );
//QgsDebugMsg(QString("XXX transformInPlace X : %1-->%2, Y: %3 -->%4").arg(x).arg(mx).arg(y).arg(my));
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgsmaptopixel.h
Expand Up @@ -187,9 +187,6 @@ class CORE_EXPORT QgsMapToPixel
double yMin; // @deprecated in 2.8
QTransform mMatrix;

// Matrix to map from map (geographical) to screen (pixels) units
const QTransform& getMatrix() const;

void updateMatrix();
};

Expand Down

0 comments on commit 8aaf8b5

Please sign in to comment.