src/corelib/tools/qline.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   572 qreal QLineF::angle() const
   572 qreal QLineF::angle() const
   573 {
   573 {
   574     const qreal dx = pt2.x() - pt1.x();
   574     const qreal dx = pt2.x() - pt1.x();
   575     const qreal dy = pt2.y() - pt1.y();
   575     const qreal dy = pt2.y() - pt1.y();
   576 
   576 
   577     const qreal theta = atan2(-dy, dx) * 360.0 / M_2PI;
   577     const qreal theta = qAtan2(-dy, dx) * 360.0 / M_2PI;
   578 
   578 
   579     const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
   579     const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
   580 
   580 
   581     if (qFuzzyCompare(theta_normalized, qreal(360)))
   581     if (qFuzzyCompare(theta_normalized, qreal(360)))
   582         return qreal(0);
   582         return qreal(0);
   812     if (isNull() || l.isNull())
   812     if (isNull() || l.isNull())
   813         return 0;
   813         return 0;
   814     qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
   814     qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
   815     qreal rad = 0;
   815     qreal rad = 0;
   816     // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
   816     // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
   817     if (cos_line >= -1.0 && cos_line <= 1.0) rad = acos( cos_line );
   817     if (cos_line >= -1.0 && cos_line <= 1.0) rad = qAcos( cos_line );
   818     return rad * 360 / M_2PI;
   818     return rad * 360 / M_2PI;
   819 }
   819 }
   820 
   820 
   821 
   821 
   822 #ifndef QT_NO_DEBUG_STREAM
   822 #ifndef QT_NO_DEBUG_STREAM