NearestPoint Method [IInkStrokeDisp Interface]

NearestPoint Method [IInkStrokeDisp Interface]

Finds the location on the stroke nearest to a known point and returns the distance that point is from the stroke. Everything is in ink space coordinates.

Declaration

[C++]

HRESULT NearestPoint(
    [in] long X,
    [in] long Y,
    [in, out, optional, defaultvalue(0)] float *distance,
    [out, retval] float *Point
);

[Microsoft® Visual Basic® 6.0]

Public Function NearestPoint( _
    X As Long, _
    Y As Long, _
    [Distance As Single] _
) As Single

Parameters

X

[in] The x-position in ink space of the point to test.

Y

[in] The y-position in ink space of the point to test.

distance

[in] The distance from the point to the stroke. This parameter can be NULL (in Visual Basic 6.0, vbNull, which must be specified, not omitted, if using late binding).

Point

[out] Returns the floating point index value that represents the closest location on the stroke.

A floating point index is a float value that represents a location somewhere between two points in the stroke. As examples, if 0.0 is the first point in the stroke and 1.0 is the second point in the stroke, 0.5 is halfway between the first and second points. Similarly, a floating point index value of 37.25 represents a location that is 25 percent along the line between points 37 and 38 of the stroke.

Return Value

HRESULT value Description
S_OK Success.
E_POINTER A parameter contained an invalid pointer.
E_FAIL An unspecified error occurred.
E_INK_EXCEPTION An exception occurred inside the method.

Remarks

The distance parameter describes the distance from the point to the envelope of the stroke. This is the distance between the two points minus half the width of the stroke.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example shows how to find the location of the nearest point on the IInkStrokeDisp, theStroke to the point (X, Y) and also get the distance in ink space between the point and the stroke in theDistance.

Dim theFIndex As Single
Dim theDistance As Single
theFIndex = theStroke.NearestPoint(X, Y, theDistance)

Applies To