- 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; std::vector<double> tmpY;
trimFeatureToBoundary(x, y, tmpX, tmpY, Xmax, shapeOpen); trimFeatureToBoundary(x, y, tmpX, tmpY, Xmax, shapeOpen);
x.resize(0); x.clear();
y.resize(0); y.clear();
trimFeatureToBoundary(tmpX, tmpY, x, y, Ymax, shapeOpen); trimFeatureToBoundary(tmpX, tmpY, x, y, Ymax, shapeOpen);
tmpX.resize(0); tmpX.clear();
tmpY.resize(0); tmpY.clear();
trimFeatureToBoundary(x, y, tmpX, tmpY, Xmin, shapeOpen); trimFeatureToBoundary(x, y, tmpX, tmpY, Xmin, shapeOpen);
x.resize(0); x.clear();
y.resize(0); y.clear();
trimFeatureToBoundary(tmpX, tmpY, x, y, Ymin, shapeOpen); trimFeatureToBoundary(tmpX, tmpY, x, y, Ymin, shapeOpen);
} }

View File

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

View File

@ -414,7 +414,6 @@ unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
#if defined(Q_WS_X11) #if defined(Q_WS_X11)
// Work around a +/- 32768 limitation on coordinates in 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 // 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 // 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 || if (std::abs(x[i]) > QgsClipper::maxX ||
std::abs(y[i]) > QgsClipper::maxY) std::abs(y[i]) > QgsClipper::maxY)
{ {
needToTrim = true; QgsClipper::trimFeature(x, y, true); // true = polyline
nPoints = x.size(); // trimming may change nPoints.
break; break;
} }
if (needToTrim)
{
QgsClipper::trimFeature(x, y, true); // true = polyline
nPoints = x.size(); // trimming may change nPoints.
}
#endif #endif
// Cast points to int and put into the appropriate storage for the // 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) #if defined(Q_WS_X11)
// Work around a +/- 32768 limitation on coordinates in 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 // 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 // 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 || if (std::abs(ring->first[i]) > QgsClipper::maxX ||
std::abs(ring->second[i]) > QgsClipper::maxY) std::abs(ring->second[i]) > QgsClipper::maxY)
{ {
needToTrim = true; QgsClipper::trimFeature(ring->first, ring->second, false);
break;
}
if (needToTrim)
QgsClipper::trimFeature(ring->first, ring->second, false);
/* /*
#ifdef QGISDEBUG #ifdef QGISDEBUG
if (needToTrim) std::cerr << "Trimmed points (" << ring->first.size() << ")\n";
{ for (int i = 0; i < ring->first.size(); ++i)
std::cerr << "Trimmed points (" << ring->first.size() << ")\n"; std::cerr << i << ": " << ring->first[i]
for (int i = 0; i < ring->first.size(); ++i) << ", " << ring->second[i] << '\n';
std::cerr << i << ": " << ring->first[i]
<< ", " << ring->second[i] << '\n';
}
#endif #endif
*/ */
break;
}
#endif #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 //also draw the not yet commited features
std::list<QgsFeature*>::iterator it = mAddedFeatures.begin(); std::list<QgsFeature*>::iterator it = mAddedFeatures.begin();