- rationalisation of transform functions in qgsmaptopixel.h

- improvement in code flow when trimming is necessary in qgsvectorlayer.cpp


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@3187 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
g_j_m 2005-04-19 05:59:20 +00:00
parent c798699029
commit 61cfe03260
3 changed files with 27 additions and 38 deletions

View File

@ -119,16 +119,16 @@ inline void QgsClipper::trimFeature(std::vector<double>& x,
std::vector<double> tmpY;
trimFeatureToBoundary(x, y, tmpX, tmpY, Xmax, shapeOpen);
x.resize(0);
y.resize(0);
x.clear();
y.clear();
trimFeatureToBoundary(tmpX, tmpY, x, y, Ymax, shapeOpen);
tmpX.resize(0);
tmpY.resize(0);
tmpX.clear();
tmpY.clear();
trimFeatureToBoundary(x, y, tmpX, tmpY, Xmin, shapeOpen);
x.resize(0);
y.resize(0);
x.clear();
y.clear();
trimFeatureToBoundary(tmpX, tmpY, x, y, Ymin, shapeOpen);
}

View File

@ -125,25 +125,29 @@ inline QgsMapToPixel::QgsMapToPixel(double mupp,
inline QgsMapToPixel::~QgsMapToPixel()
{
}
inline QgsPoint QgsMapToPixel::transform(double x, double y)
{
return (transform(QgsPoint(x, y)));
transformInPlace(x,y);
return QgsPoint(x,y);
}
inline QgsPoint QgsMapToPixel::transform(const QgsPoint& p)
{
// transform x
double dx = (p.x() - xMin) / mapUnitsPerPixel;
double dy = yMax - ((p.y() - yMin)) / mapUnitsPerPixel;
// double dy = (yMax - (p.y() - yMin))/mapUnitsPerPixel;
double dx = p.x();
double dy = p.y();
transformInPlace(dx, dy);
//std::cerr << "Point to pixel...X : " << p.x() << "-->" << dx << ", Y: " << p.y() << " -->" << dy << std::endl;
return QgsPoint(dx, dy);
}
inline void QgsMapToPixel::transform(QgsPoint* p)
{
double x = ((p->x()-xMin)/mapUnitsPerPixel);
double y = (yMax-((p->y() - yMin)) / mapUnitsPerPixel);
double x = p->x();
double y = p->y();
transformInPlace(x, y);
#ifdef QGISDEBUG
//std::cerr << "Point to pixel...X : " << p->x() << "-->" << x << ", Y: " << p->y() << " -->" << y << std::endl;
#endif

View File

@ -414,7 +414,6 @@ unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
#if defined(Q_WS_X11)
// Work around a +/- 32768 limitation on coordinates in X11
bool needToTrim = false;
// Look through the x and y coordinates and see if there are any
// that need trimming. If one is found, there's no need to look at
@ -423,16 +422,10 @@ unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
if (std::abs(x[i]) > QgsClipper::maxX ||
std::abs(y[i]) > QgsClipper::maxY)
{
needToTrim = true;
QgsClipper::trimFeature(x, y, true); // true = polyline
nPoints = x.size(); // trimming may change nPoints.
break;
}
if (needToTrim)
{
QgsClipper::trimFeature(x, y, true); // true = polyline
nPoints = x.size(); // trimming may change nPoints.
}
#endif
// Cast points to int and put into the appropriate storage for the
@ -512,7 +505,6 @@ unsigned char* QgsVectorLayer::drawPolygon(unsigned char* feature,
#if defined(Q_WS_X11)
// Work around a +/- 32768 limitation on coordinates in X11
bool needToTrim = false;
// Look through the x and y coordinates and see if there are any
// that need trimming. If one is found, there's no need to look at
@ -521,24 +513,17 @@ unsigned char* QgsVectorLayer::drawPolygon(unsigned char* feature,
if (std::abs(ring->first[i]) > QgsClipper::maxX ||
std::abs(ring->second[i]) > QgsClipper::maxY)
{
needToTrim = true;
break;
}
if (needToTrim)
QgsClipper::trimFeature(ring->first, ring->second, false);
QgsClipper::trimFeature(ring->first, ring->second, false);
/*
#ifdef QGISDEBUG
if (needToTrim)
{
std::cerr << "Trimmed points (" << ring->first.size() << ")\n";
for (int i = 0; i < ring->first.size(); ++i)
std::cerr << i << ": " << ring->first[i]
<< ", " << ring->second[i] << '\n';
}
std::cerr << "Trimmed points (" << ring->first.size() << ")\n";
for (int i = 0; i < ring->first.size(); ++i)
std::cerr << i << ": " << ring->first[i]
<< ", " << ring->second[i] << '\n';
#endif
*/
break;
}
#endif
@ -763,7 +748,7 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
}
}
// std::cerr << "Time to draw was " << t.elapsed() << '\n';
//std::cerr << "Time to draw was " << t.elapsed() << '\n';
//also draw the not yet commited features
std::list<QgsFeature*>::iterator it = mAddedFeatures.begin();