public StationAreaItem AddPointArea(MSTSCoord coord, double snapDist, MSTSBase tileBase) { PointF found = new PointF(0, 0); double dist = -1, closestDist = double.PositiveInfinity; int i; int closestI = -1; PointF closest; StationAreaItem newPoint = new StationAreaItem(TypeEditor.ROUTECONFIG, this); if (areaCompleted) { StationAreaItem p1; StationAreaItem p2; for (i = 0; i < stationArea.Count - 1; i++) { p1 = stationArea[i]; p2 = stationArea[i + 1]; dist = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), new AESegment(p1.Coord.ConvertToPointF(), p2.Coord.ConvertToPointF()), out found); if (dist >= 0 && dist < snapDist && dist < closestDist) { closestDist = dist; closestI = i + 1; closest = found; } dist = -1; } p1 = stationArea[stationArea.Count - 1]; p2 = stationArea[0]; dist = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), new AESegment(p1.Coord.ConvertToPointF(), p2.Coord.ConvertToPointF()), out closest); if (dist >= 0 && dist < snapDist && dist < closestDist) { closestDist = dist; closestI = 0; closest = found; } if (closestDist < double.PositiveInfinity) { coord = tileBase.getMstsCoord(closest); newPoint.configCoord(coord); newPoint.toggleSelected(); stationArea.Insert(closestI, newPoint); } else { return(null); } } else { // Until area complete, we only add new point at the end newPoint.configCoord(coord); newPoint.toggleSelected(); stationArea.Add(newPoint); } return(newPoint); }
public void setStartAngle(PointF p1, PointF p3, PointF p2) { PointF center = Centre.ConvertToPointF(); float dx1 = p1.X - center.X; float dy1 = p1.Y - center.Y; float dx2 = p3.X - center.X; float dy2 = p3.Y - center.Y; double dx3 = p2.X - center.X; double dy3 = p2.Y - center.Y; Vector2 vector1 = new Vector2(dx1, dy1); Vector2 vector2 = new Vector2(dx2, dy2); double distBetween; Vector2.Distance(ref vector1, ref vector2, out distBetween); double atan1 = Math.Atan2(dy1, dx1); double atan2 = Math.Atan2(dy2, dx2); double atan3 = 0; atan3 = atan2 - atan1; while (atan3 > Math.PI) { atan3 -= Math.PI; } while (atan3 < -Math.PI) { atan3 += Math.PI; } if (Math.Abs(atan3) > (Math.PI / 2)) { atan3 = Math.PI - Math.Abs(atan3); } angleTot = atan3; double interm = 2; step = (int)Math.Floor(Math.Abs(distBetween) / interm) + 1; startAngle = atan1; }
public GlobalItem UpdateItem(GlobalItem item, MSTSCoord coord, bool controlKey, bool forceConnector) { PointF closest = new PointF(0f, 0f); StationItem parent = null; StationAreaItem item3 = null; PointF tf2 = new PointF(0f, 0f); double snapSize = Viewer.snapSize; double num2 = -1.0; double positiveInfinity = double.PositiveInfinity; PointF tf3 = coord.ConvertToPointF(); if (item.GetType() == typeof(StationAreaItem)) { item3 = (StationAreaItem)item; parent = item3.parent; if (parent == null) { return(null); } } else { if (typeof(StationItem) == item.GetType()) { parent = (StationItem)item; foreach (StationAreaItem item4 in parent.stationArea) { StationAreaItem item5 = parent.getNextArea(item4); num2 = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), new AESegment(item4.Location, item5.Location), out closest); if ((num2 < snapSize) && (num2 < positiveInfinity)) { positiveInfinity = num2; item3 = item4; } } parent.Update(coord); return(parent); } if (!item.IsLineSnap()) { item.Update(coord); return(item); } } TrackSegment segment = null; int associateNodeIdx = 0; foreach (TrackSegment segment2 in aeItems.getSegments()) { segment2.unsetSnap(); num2 = DrawUtility.FindDistanceToSegment(coord.ConvertToPointF(), segment2, out closest); if ((num2 < snapSize) && (num2 < positiveInfinity)) { positiveInfinity = num2; segment = segment2; segment.setSnap(); tf2 = closest; associateNodeIdx = segment.associateNodeIdx; } } if (segment != null) { segment.setSnap(); } if ((!item.IsLineSnap() || (segment != null)) || controlKey) { item3.Update(coord); } return(parent); }