Skip to content

Conversation

@LokiMidgard
Copy link

I have zero expiriance with Haxe, so maybe it dose something different to what I think, but to me it seemse to calculate the distance to the first vertex, not the shortest distance to any vertex.

// This function returns minimal distance from any of the vertices
// to a point, not real distance from the polygon
public function distance( p:Point ):Float {
var v0 = this[0];
var d = Point.distance( v0, p );
for (i in 1...this.length) {
var v1 = this[i];
var d1 = Point.distance( v1, p );
if (d1 < d) v0 = v1;
}
return d;
}

In the beginning d gets calculated with the first vertex, but never updated after that and then returned. Only v0 is changed, but never readed.

feel free to do what ever you want with this :)

Fix distance calculation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant