21KoRect KoRect::normalize()
const
24 if ( right() < left() ) {
25 r.m_tl.setX( right() );
26 r.m_br.setX( left() );
28 r.m_tl.setX( left() );
29 r.m_br.setX( right() );
31 if ( bottom() < top() ) {
32 r.m_tl.setY( bottom() );
36 r.m_br.setY( bottom() );
41void KoRect::setTopLeft(
const KoPoint &topleft)
46void KoRect::setBottomRight(
const KoPoint &bottomright)
51void KoRect::setTopRight(
const KoPoint &topright)
53 m_br.rx() = topright.x();
54 m_tl.ry() = topright.y();
57void KoRect::setBottomLeft(
const KoPoint &bottomleft)
59 m_tl.rx() = bottomleft.x();
60 m_br.ry() = bottomleft.y();
66 return KoPoint((left() + right()) / 2, (top() + bottom()) / 2);
69void KoRect::moveTopLeft(
const KoPoint &topleft)
71 m_br.rx() += topleft.x() - m_tl.x();
72 m_br.ry() += topleft.y() - m_tl.y();
76void KoRect::moveBottomRight(
const KoPoint &bottomright)
78 m_tl.rx() += bottomright.x() - m_br.x();
79 m_tl.ry() += bottomright.y() - m_br.y();
83void KoRect::moveTopRight(
const KoPoint &topright)
85 m_tl.rx() += topright.x() - m_br.x();
86 m_br.ry() += topright.y() - m_tl.y();
87 m_br.rx() = topright.x();
88 m_tl.ry() = topright.y();
91void KoRect::moveBottomLeft(
const KoPoint &bottomleft)
93 m_br.rx() += bottomleft.x() - m_tl.x();
94 m_tl.ry() += bottomleft.y() - m_br.y();
95 m_tl.rx() = bottomleft.x();
96 m_br.ry() = bottomleft.y();
99void KoRect::moveBy(
const double &dx,
const double &dy)
107void KoRect::setRect(
const double &x,
const double &y,
const double &width,
const double &height)
109 m_tl.setCoords( x, y );
110 m_br.setCoords( x + width, y + height );
113void KoRect::setRect(
const KoRect &rect)
119void KoRect::setCoords(
const double &x1,
const double &y1,
const double &x2,
const double &y2)
121 m_tl.setCoords( x1, y1 );
122 m_br.setCoords( x2, y2 );
125void KoRect::setSize(
const KoSize &size)
127 setWidth(size.width());
128 setHeight(size.height());
131KoSize KoRect::size()
const
133 return KoSize(width(), height());
145 if(m_tl.x() > rhs.left())
146 m_tl.setX(rhs.left());
147 if(m_tl.y() > rhs.top())
148 m_tl.setY(rhs.top());
149 if(m_br.x() < rhs.right())
150 m_br.setX(rhs.right());
151 if(m_br.y() < rhs.bottom())
152 m_br.setY(rhs.bottom());
158 if(m_tl.x() < rhs.left())
159 m_tl.setX(rhs.left());
160 if(m_tl.y() < rhs.top())
161 m_tl.setY(rhs.top());
162 if(m_br.x() > rhs.right())
163 m_br.setX(rhs.right());
164 if(m_br.y() > rhs.bottom())
165 m_br.setY(rhs.bottom());
170 return (p.x() >= m_tl.x() && p.x() <= m_br.x() && p.y() >= m_tl.y() && p.y() <= m_br.y());
174 return (x >= m_tl.x() && x <= m_br.x() && y >= m_tl.y() && y <= m_br.y());
178 return (r.left() >= m_tl.x() && r.right() <= m_br.x() && r.top() >= m_tl.y() && r.bottom() <= m_br.y());
190bool KoRect::intersects(
const KoRect &r)
const {
191 return ( TQMAX(m_tl.x(), r.left()) <= TQMIN(m_br.x(), r.right()) &&
192 TQMAX(m_tl.y(), r.top()) <= TQMIN(m_br.y(), r.bottom()) );
202 tmp.setCoords( (lhs.left() < rhs.left() ? lhs.left() : rhs.left()),
203 (lhs.top() < rhs.top() ? lhs.top() : rhs.top()),
204 (lhs.right() > rhs.right() ? lhs.right() : rhs.right()),
205 (lhs.bottom() > rhs.bottom() ? lhs.bottom() : rhs.bottom()) );
212 tmp.setCoords( (lhs.left() > rhs.left() ? lhs.left() : rhs.left()),
213 (lhs.top() > rhs.top() ? lhs.top() : rhs.top()),
214 (lhs.right() < rhs.right() ? lhs.right() : rhs.right()),
215 (lhs.bottom() < rhs.bottom() ? lhs.bottom() : rhs.bottom()) );
220 return ( lhs.topLeft()==rhs.topLeft() &&
221 lhs.bottomRight()==rhs.bottomRight() );
225 return ( lhs.topLeft()!=rhs.topLeft() ||
226 lhs.bottomRight()!=rhs.bottomRight() );
229KoRect KoRect::transform(
const TQWMatrix &m)
const
232 if(m.m12() == 0.0F && m.m21() == 0.0F)
234 result =
KoRect(topLeft().transform(m), bottomRight().transform(m));
241 for(i = 0; i < 4; i++)
242 p[i] = p[i].transform(m);
244 result.setLeft(p[0].x());
245 result.setTop(p[0].y());
246 result.setRight(p[0].x());
247 result.setBottom(p[0].y());
249 for(
int i = 1; i < 4; i++)
251 result.setLeft(TQMIN(p[i].x(), result.left()));
252 result.setTop(TQMIN(p[i].y(), result.top()));
253 result.setRight(TQMAX(p[i].x(), result.right()));
254 result.setBottom(TQMAX(p[i].y(), result.bottom()));
260KoRect KoRect::translate(
double dx,
double dy)
const
262 return KoRect(left() + dx, top() + dy, width(), height());
265TQRect KoRect::toTQRect()
const
267 return TQRect( tqRound( left() ), tqRound( top() ), tqRound( width() ), tqRound( height() ) );
271KoRect KoRect::fromTQRect(
const TQRect &rect )
273 return KoRect( rect.left(), rect.top(), rect.width(), rect.height() );
A point whose coordinates are floating-point values ( "double"s ).
A rect whose coordinates are floating-point values ( "double"s ).
bool contains(const KoPoint &p) const
Returns if the point is contained in the rect.
A size whose coordinates are floating-point values ( "double"s ).