internal int GetNearestSegmentIndex(Vector p) { double smallest = GeometryUtils.DistanceFromSegment(Vertices[0].X, Vertices[0].Y, Vertices[1].X, Vertices[1].Y, p.X, p.Y); int smallestIndex = 0; double current; int c = Vertices.Count - 1; for (int i = 1; i < c; i++) { current = GeometryUtils.DistanceFromSegment(Vertices[i].X, Vertices[i].Y, Vertices[i + 1].X, Vertices[i + 1].Y, p.X, p.Y); if (current < smallest) { smallest = current; smallestIndex = i; } } current = GeometryUtils.DistanceFromSegment(Vertices[c].X, Vertices[c].Y, Vertices[0].X, Vertices[0].Y, p.X, p.Y); if (current < smallest) { smallestIndex = c; } return(smallestIndex); }
internal double DistanceFromPoint(Vector p) { double smallest = Math.Sqrt(Math.Pow((Vertices[0].X - p.X), 2) + Math.Pow((Vertices[0].Y - p.Y), 2)); double current; int c = Vertices.Count - 1; for (int i = 0; i < c; i++) { current = GeometryUtils.DistanceFromSegment(Vertices[i].X, Vertices[i].Y, Vertices[i + 1].X, Vertices[i + 1].Y, p.X, p.Y); if (current < smallest) { smallest = current; } } if (!IsGrass || Global.AppSettings.LevelEditor.RenderingSettings.ShowInactiveGrassEdges) { current = GeometryUtils.DistanceFromSegment(Vertices[c].X, Vertices[c].Y, Vertices[0].X, Vertices[0].Y, p.X, p.Y); if (current < smallest) { smallest = current; } } return(smallest); }
internal void InsertIntersection(Vector p, double delta) { int c = Vertices.Count - 1; for (int i = 0; i < c; i++) { if ( GeometryUtils.DistanceFromSegment(Vertices[i].X, Vertices[i].Y, Vertices[i + 1].X, Vertices[i + 1].Y, p.X, p.Y) < delta) { Insert(i + 1, p); return; } } if (GeometryUtils.DistanceFromSegment(Vertices[c].X, Vertices[c].Y, Vertices[0].X, Vertices[0].Y, p.X, p.Y) < delta) { Vertices.Add(p); return; } Utils.ShowError("Failed to add intersection!!"); }