PDA

View Full Version : Error in QRectF::intersects



lni
11th February 2009, 02:43
When the input QRectF has a 0 width, that is, it is a line, the function simply returns "false"

If so, I hope QRectF can provide a method
bool QRectF::intersects( const QLineF& )

talk2amulya
11th February 2009, 06:43
well, why dont u derive from QRectF and write the function urself. I dont think QT guys are gonna add anything like that :)

lni
11th February 2009, 18:19
well, why dont u derive from QRectF and write the function urself. I dont think QT guys are gonna add anything like that :)

Having QRectF, QLineF, QPointF, and
QRectF::intersects( const QRectF& )
QRectF::contains( const QPointF& )
QLine::intersect( const QLineF& ) // <== why not use "intersects" to be consistent?

and it is reasonable to expect QRectF::intersects( const QLineF& ). It is definitely needed for rendering purpose.

I need to draw a polyline with over 20,000 points, it is very slow to draw them all when there is an exposure event, and I found QStyleOptionGraphicsItem::exposedRect

So I do



for ( int idx = 0; idx < totalPoints; idx++ ) {
QPointF p1 = ...
QPointF p2 = ...
If ( exposedRect.intersects( QLineF( p1, p2 ) ) { // perhaps I need to do QLineF::cutThrough( const QRectF& )?
painter->drawLine( p1, p2 );
}
}


That is, only line segment that intersects with the exposed rectangle, then I do the draw. This improves the performance tremendously. Yes, I write my own "intersects" for now. But it should be provided by Qt as it is definitely needed for fast rendering.

This bring up my other question, what does QPainter do behind the scene? Performance is very bad when trying to draw a polyline with over 10,000 points, although the exposed area may only have 20 points...

But after adding "intersetcs", it becomes much faster even though checking has to be done for all line segments...

talk2amulya
11th February 2009, 18:24
u do make a valid point, maybe u should take over this issue to trolltech or to Nokia now :) also the thing u said about consistency makes sense too