MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / distanceSquaredToLine

Method distanceSquaredToLine

qcustomplot/qcustomplot.cpp:178–193  ·  view source on GitHub ↗

! \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 */

Source from the content-addressed store, hash-verified

176 \see distanceToStraightLine
177*/
178double 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

Callers 5

rectDistanceMethod · 0.80
pointDistanceMethod · 0.80
selectTestMethod · 0.80
ohlcSelectTestMethod · 0.80
candlestickSelectTestMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected