[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] |
Quick calculation of the length between points
Source position: line 0
function TfpgPoint.ManhattanLength: Integer; |
const PointB: TfpgPoint |
):Integer; |
Returns the sum of the absolute values of X and Y, traditionally known as the "Manhattan length" of the vector from the origin to the point. For example:
var oldPosition: TfpgPoint; newPosition: TfpgPoint; begin newPosition := MousePosition - oldPosition; if (newPosition.ManhattanLength > 5) then begin // the mouse has moved more than 5 pixels since the oldPosition end; end;
Accuracy is traded for speed. This is a useful, and quick to calculate, approximation to the true length:
TrueLength := sqrt(power(X, 2) + power(Y, 2));
The tradition of "Manhattan length" arises because such distances apply to travelers who can only travel on a rectangular grid, like the streets of Manhattan.
For a further explanation of "Manhattan length" see the Wikipedia article on Taxicab geometry.