public Vector2 closestPoint(Vector2 v) { Vector2 ret = new Vector2(0f, 0f); float distance = float.MaxValue, current = float.MaxValue; LineHandler tmp = lines[0]; foreach (LineHandler handler in lines) { foreach (Vector2 collisions in handler.contactPoints(v)) { current = Vector2.Distance(v, collisions); if (current < distance) { distance = current; ret = collisions; tmp = handler; } } } bool contains = tmp.contains(ret); return(ret); }