ProximityResult from GeometryEngine.nearestCoordinate

Can someone help me understand the what the GeometryEngine.nearestCoordinate returns? I'm wondering if there is a bug in Runtime v100.1, as I'm seeing different results between a Polyline and a Polygon.

It returns a ProximityResult, which has a pointIndex. What exactly is that pointIndex supposed to be?

I made a basic polyline. I then click along the edges. The pointIndex seems to be the index of the lower vertex of that segment. e.g. if I click between vertices 0 and 1 I get a pointIndex of 0. If I click between vertices 2 and 3 I get 2. And so on.

I tried making a basic square polygon, and then started clicking along the edge. Obviously the polygon has 4 vertices, numbering 0-3. Clicking between 0-1 returns a pointIndex of 0. But as I move along from 1-2, it randomly alternates between returning 1 and 0. Again, as I move between 2-3, it randomly returns sometimes 2 and sometimes 0. And so on.

I have pasted below a very basic sample app. Is there someone that can test this, and confirm is this is either a bug, or whether I'm misunderstanding how the method works?

As a further comment as I try to understand the nearestCoordinate method, I notice that if you pass in a geometry and a point that happens to be exactly one of the vertex points, then it always seems to return a pointIndex of 0.

for example, in the following code, the first console log always returns zero, even though the index is clearly 2, which the second console log correctly returns.