/// <summary> /// Checks all the vertices of a polygon and against a point. /// If that point is within the radius of a vertex, then the index to that vertex is returned. /// Otherwise -1 is returned. /// </summary> /// <param name="radius">The radius the position must come within for a vertex to be selected.</param> /// <param name="position">The poisition to check against the vertices</param> /// <param name="polygon">The polygon which will have it's vertices checked. A null polygon will return -1</param> /// <returns>Index to vertex in the radius of the position or minus one if no suitable vertex can be found.</returns> private int FindSelectedVertex(Point position, ConvexPolygon polygon, int radius) { if (polygon == null) { return -1; } for (int i = 0; i < polygon.Vertices.Count; i++) { Circle circle = new Circle(polygon.Vertices[i].X, polygon.Vertices[i].Y, radius); if (circle.Intersects(position)) { return i; } } return -1; }
/// <summary> /// Checks all the vertices of a polygon and against a point. /// If that point is within the radius of a vertex, then the index to that vertex is returned. /// Otherwise -1 is returned. /// </summary> /// <param name="radius">The radius the position must come within for a vertex to be selected.</param> /// <param name="position">The poisition to check against the vertices</param> /// <param name="polygon">The polygon which will have it's vertices checked. A null polygon will return -1</param> /// <returns>Index to vertex in the radius of the position or minus one if no suitable vertex can be found.</returns> private int FindSelectedVertex(Point position, ConvexPolygon polygon, int radius) { if (polygon == null) { return(-1); } for (int i = 0; i < polygon.Vertices.Count; i++) { Circle circle = new Circle(polygon.Vertices[i].X, polygon.Vertices[i].Y, radius); if (circle.Intersects(position)) { return(i); } } return(-1); }