! \overload Returns the squared shortest distance of this vector (interpreted as a point) to the finite line segment given by \a start and \a end. \see distanceToStraightLine */
| 176 | \see distanceToStraightLine |
| 177 | */ |
| 178 | double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const |
| 179 | { |
| 180 | QCPVector2D v(end-start); |
| 181 | double vLengthSqr = v.lengthSquared(); |
| 182 | if (!qFuzzyIsNull(vLengthSqr)) |
| 183 | { |
| 184 | double mu = v.dot(*this-start)/vLengthSqr; |
| 185 | if (mu < 0) |
| 186 | return (*this-start).lengthSquared(); |
| 187 | else if (mu > 1) |
| 188 | return (*this-end).lengthSquared(); |
| 189 | else |
| 190 | return ((start + mu*v)-*this).lengthSquared(); |
| 191 | } else |
| 192 | return (*this-start).lengthSquared(); |
| 193 | } |
| 194 | |
| 195 | /*! \overload |
| 196 |
no outgoing calls
no test coverage detected