/** * Does spike-reduction on the given point-array's stack-top. * * Spikes are path segments of which one goes forward, and the sucessor * goes backward on the predecessor's segment: * * 2 0 1 * x------x<-----x * (0 is stack-top in point-array) * * This will be reduced to * 1 0 * x------x * * Preconditions: * - No other spikes exist in the whole point-array except at most * one at the end * - No two succeeding points are ever equal * - For each two succeeding points either p1.x == p2.x or p1.y == p2.y holds * true * - No such spike exists where 2 is situated between 0 and 1. * * Postcondition: * - No spikes exist in the whole point-array * * If no spike is found, the point-array is left unchanged. * @return \c true if an actual reduction was done */ inline static bool reduceSpike(QValueVector< QPoint > &pointArray) { if(pointArray.size() < 3) return false; QValueVector< QPoint >::Iterator it = pointArray.end(); QPoint p0 = *--it; QPoint p1 = *--it; QPoint p2 = *--it; bool elide = false; if((p0.x() == p1.x() && p1.x() == p2.x() && ((p1.y() < p0.y() && p0.y() < p2.y()) || (p2.y() < p0.y() && p0.y() < p1.y()) || (p1.y() < p2.y() && p2.y() < p0.y()) || (p0.y() < p2.y() && p2.y() < p1.y()) || (elide = p2.y() == p0.y() && p0.y() < p1.y()) || (elide = p1.y() < p0.y() && p0.y() == p2.y()))) || (p0.y() == p1.y() && p1.y() == p2.y() && ((p1.x() < p0.x() && p0.x() < p2.x()) || (p2.x() < p0.x() && p0.x() < p1.x()) || (p1.x() < p2.x() && p2.x() < p0.x()) || (p0.x() < p2.x() && p2.x() < p1.x()) || (elide = p2.x() == p0.x() && p0.x() < p1.x()) || (elide = p1.x() < p0.x() && p0.x() == p2.x())))) { // kdDebug(6040) << "spikered p2" << (elide ? " (elide)" : "") << ": " << p2 << " p1: " << p1 << " p0: " << p0 << endl; pointArray.pop_back(); pointArray.pop_back(); if(!elide) pointArray.push_back(p0); return true; } return false; }
/** * Reduces segment separators. * * A segment separator separates a segment into two segments, thus causing * two adjacent segment with the same orientation. * * 2 1 0 * x-------x---->x * (0 means stack-top) * * Here, 1 is a segment separator. As segment separators not only make * the line drawing algorithm inefficient, but also make the spike-reduction * fail, they must be eliminated: * * 1 0 * x------------>x * * Preconditions: * - No other segment separators exist in the whole point-array except * at most one at the end * - No two succeeding points are ever equal * - For each two succeeding points either p1.x == p2.x or p1.y == p2.y holds * true * - No such spike exists where 2 is situated between 0 and 1. * * Postcondition: * - No segment separators exist in the whole point-array * * If no segment separator is found at the end of the point-array, it is * left unchanged. * @return \c true if a segment separator was actually reduced. */ inline static bool reduceSegmentSeparator(QValueVector< QPoint > &pointArray) { if(pointArray.size() < 3) return false; QValueVector< QPoint >::Iterator it = pointArray.end(); QPoint p0 = *--it; QPoint p1 = *--it; QPoint p2 = *--it; // kdDebug(6040) << "checking p2: " << p2 << " p1: " << p1 << " p0: " << p0 << endl; if((p0.x() == p1.x() && p1.x() == p2.x() && ((p2.y() < p1.y() && p1.y() < p0.y()) || (p0.y() < p1.y() && p1.y() < p2.y()))) || (p0.y() == p1.y() && p1.y() == p2.y() && ((p2.x() < p1.x() && p1.x() < p0.x()) || (p0.x() < p1.x() && p1.x() < p2.x())))) { // kdDebug(6040) << "segred p2: " << p2 << " p1: " << p1 << " p0: " << p0 << endl; pointArray.pop_back(); pointArray.pop_back(); pointArray.push_back(p0); return true; } return false; }
void load( const QString& filename ) { QFile file( filename ); if ( !file.open( IO_ReadOnly ) ) { Console::instance()->send( tr( "Unable to open %1!\n" ).arg( filename ) ); return; } filenames.push_back( filename ); QXmlInputSource input( &file ); QXmlSimpleReader reader; reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); reader.setContentHandler( this ); reader.setErrorHandler( this ); reader.parse( &input, false ); filenames.pop_back(); }
bool endDocument() { levels.pop_back(); locators.pop(); return true; }