Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix for qreal - double problem when crosscompiling for android
  • Loading branch information
Marco Bernasocchi committed Jul 27, 2011
1 parent a9ab98f commit a7522b6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
74 changes: 74 additions & 0 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -343,6 +343,80 @@ void QgsCoordinateTransform::transformInPlace( std::vector<double>& x,
}
}

#ifdef ANDROID
void QgsCoordinateTransform::transformInPlace( float& x, float& y, float& z,
TransformDirection direction ) const
{
if ( mShortCircuit || !mInitialisedFlag )
return;
#ifdef QGISDEBUG
// QgsDebugMsg(QString("Using transform in place %1 %2").arg(__FILE__).arg(__LINE__));
#endif
// transform x
try
{
double xd = x;
double yd = y;
double zd = z;
transformCoords( 1, &xd, &yd, &zd, direction );
x = xd;
y = yd;
z = zd;
}
catch ( QgsCsException &cse )
{
// rethrow the exception
QgsDebugMsg( "rethrowing exception" );
throw cse;
}
}

void QgsCoordinateTransform::transformInPlace( std::vector<float>& x,
std::vector<float>& y, std::vector<float>& z,
TransformDirection direction ) const
{
if ( mShortCircuit || !mInitialisedFlag )
return;

Q_ASSERT( x.size() == y.size() );

// Apparently, if one has a std::vector, it is valid to use the
// address of the first element in the vector as a pointer to an
// array of the vectors data, and hence easily interface with code
// that wants C-style arrays.

try
{
//copy everything to double vectors since proj needs double
int vectorSize = x.size();
std::vector<double> xd( x.size() );
std::vector<double> yd( y.size() );
std::vector<double> zd( z.size() );
for( int i = 0; i < vectorSize; ++i )
{
xd[i] = x[i];
yd[i] = y[i];
zd[i] = z[i];
}
transformCoords( x.size(), &xd[0], &yd[0], &zd[0], direction );

//copy back
for( int i = 0; i < vectorSize; ++i )
{
x[i] = xd[i];
y[i] = yd[i];
z[i] = zd[i];
}
}
catch ( QgsCsException &cse )
{
// rethrow the exception
QgsDebugMsg( "rethrowing exception" );
throw cse;
}
}
#endif //ANDROID


QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle rect, TransformDirection direction ) const
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgscoordinatetransform.h
Expand Up @@ -157,6 +157,13 @@ class CORE_EXPORT QgsCoordinateTransform: public QObject
void transformInPlace( std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
TransformDirection direction = ForwardTransform ) const;

#ifdef ANDROID
void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;

void transformInPlace( std::vector<float>& x, std::vector<float>& y, std::vector<float>& z,
TransformDirection direction = ForwardTransform ) const;
#endif

/*! Transform a QgsRectangle to the dest Coordinate system
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsmaptopixel.cpp
Expand Up @@ -143,3 +143,19 @@ void QgsMapToPixel::transformInPlace( std::vector<double>& x,
for ( unsigned int i = 0; i < x.size(); ++i )
transformInPlace( x[i], y[i] );
}

#ifdef ANDROID
void QgsMapToPixel::transformInPlace( float& x, float& y ) const
{
x = ( x - xMin ) / mMapUnitsPerPixel;
y = yMax - ( y - yMin ) / mMapUnitsPerPixel;
}

void QgsMapToPixel::transformInPlace( std::vector<float>& x,
std::vector<float>& y ) const
{
assert( x.size() == y.size() );
for ( unsigned int i = 0; i < x.size(); ++i )
transformInPlace( x[i], y[i] );
}
#endif
6 changes: 6 additions & 0 deletions src/core/qgsmaptopixel.h
Expand Up @@ -73,6 +73,12 @@ class CORE_EXPORT QgsMapToPixel
void transformInPlace( std::vector<double>& x,
std::vector<double>& y ) const;

#ifdef ANDROID
void transformInPlace( float& x, float& y ) const;
void transformInPlace( std::vector<float>& x,
std::vector<float>& y ) const;
#endif

QgsPoint toMapCoordinates( int x, int y ) const;

/*! Transform device coordinates to map (world) coordinates
Expand Down
5 changes: 3 additions & 2 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -53,7 +53,8 @@ unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderCo
wkb += sizeof( unsigned int );

bool hasZValue = ( wkbType == QGis::WKBLineString25D );
double x, y, z;
double x, y;
qreal z;

const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();
Expand Down Expand Up @@ -116,7 +117,7 @@ unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygon

const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();
double z = 0; // dummy variable for coordiante transform
qreal z = 0; // dummy variable for coordiante transform

const QgsRectangle& e = context.extent();
double cw = e.width() / 10; double ch = e.height() / 10;
Expand Down

0 comments on commit a7522b6

Please sign in to comment.