QRectF GraphicsLine

:: boundingRect () const {

//Q3PointArray p(poly);

int xi = int(x());

int yi = int(y());

int pw = 1;//pen().width();

int dx = (x1-x2);

if( dx<0)

dx= -dx;

\\ int dy = y1-y2;

if(dy<0)

dy=-dy;

pw = pw*4/3+2; // approx pw*sqrt(2)

int px = x1<x2 ? -pw : pw ;

int py = y1<y2 ? -pw : pw ;

if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {

// steep

if ( px == py ) {

p

[0] = QPoint(x1

+xi ,y1

+yi

+py

);

p

[1] = QPoint(x2

+xi

-px,y2

+yi

);

p

[2] = QPoint(x2

+xi ,y2

+yi

-py

);

p

[3] = QPoint(x1

+xi

+px,y1

+yi

);

} else {

p

[0] = QPoint(x1

+xi

+px,y1

+yi

);

p

[1] = QPoint(x2

+xi ,y2

+yi

-py

);

p

[2] = QPoint(x2

+xi

-px,y2

+yi

);

p

[3] = QPoint(x1

+xi ,y1

+yi

+py

);

}

} else if ( dx > dy ) {

// horizontal

p

[0] = QPoint(x1

+xi

+px,y1

+yi

+py

);

p

[1] = QPoint(x2

+xi

-px,y2

+yi

+py

);

p

[2] = QPoint(x2

+xi

-px,y2

+yi

-py

);

p

[3] = QPoint(x1

+xi

+px,y1

+yi

-py

);

} else {

// vertical

p

[0] = QPoint(x1

+xi

+px,y1

+yi

+py

);

p

[1] = QPoint(x2

+xi

+px,y2

+yi

-py

);

p

[2] = QPoint(x2

+xi

-px,y2

+yi

-py

);

p

[3] = QPoint(x1

+xi

-px,y1

+yi

+py

);

}

return p.boundingRect();

QRectF GraphicsLine:: boundingRect () const
{
QPolygon p(4);
//Q3PointArray p(poly);
int xi = int(x());
int yi = int(y());
int pw = 1;//pen().width();
int dx = (x1-x2);
if( dx<0)
dx= -dx;
\\ int dy = y1-y2;
if(dy<0)
dy=-dy;
pw = pw*4/3+2; // approx pw*sqrt(2)
int px = x1<x2 ? -pw : pw ;
int py = y1<y2 ? -pw : pw ;
if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {
// steep
if ( px == py ) {
p[0] = QPoint(x1+xi ,y1+yi+py);
p[1] = QPoint(x2+xi-px,y2+yi );
p[2] = QPoint(x2+xi ,y2+yi-py);
p[3] = QPoint(x1+xi+px,y1+yi );
} else {
p[0] = QPoint(x1+xi+px,y1+yi );
p[1] = QPoint(x2+xi ,y2+yi-py);
p[2] = QPoint(x2+xi-px,y2+yi );
p[3] = QPoint(x1+xi ,y1+yi+py);
}
} else if ( dx > dy ) {
// horizontal
p[0] = QPoint(x1+xi+px,y1+yi+py);
p[1] = QPoint(x2+xi-px,y2+yi+py);
p[2] = QPoint(x2+xi-px,y2+yi-py);
p[3] = QPoint(x1+xi+px,y1+yi-py);
} else {
// vertical
p[0] = QPoint(x1+xi+px,y1+yi+py);
p[1] = QPoint(x2+xi+px,y2+yi-py);
p[2] = QPoint(x2+xi-px,y2+yi-py);
p[3] = QPoint(x1+xi-px,y1+yi+py);
}
return p.boundingRect();

*To copy to clipboard, switch view to plain text mode *

## Bookmarks