/// <summary> /// Snaps the point specified in endpoint of line to another line if within snapradius /// </summary> protected void SnapLineEnd(TrackWriter trk, GameLine line, Vector2d endpoint) { var ignore = new int[] { line.ID }; GetSnapPoint( trk, line.Position, line.Position2, endpoint, ignore, out var snap, line is StandardLine); if (snap == endpoint) { return; } if (line.Position == endpoint) { // don't snap to the same point. if (line.Position2 != snap) { trk.MoveLine(line, snap, line.Position2); } } else if (line.Position2 == endpoint) { // don't snap to the same point. if (line.Position != snap) { trk.MoveLine(line, line.Position, snap); } } }
/// <summary> /// Snaps the point specified in endpoint of line to another line if within snapradius /// </summary> protected void SnapLineEnd(TrackWriter trk, GameLine line, Vector2d endpoint) { var lines = LineEndsInRadius(trk, endpoint, SnapRadius); for (int i = 0; i < lines.Length; i++) { var curr = lines[i]; if (curr != line) { if (line is StandardLine && curr is SceneryLine) { continue;//phys lines dont wanna snap to scenery } var snap = Utility.CloserPoint(endpoint, curr.Position, curr.Position2); if (line.Position == endpoint) { // don't snap to the same point. if (line.Position2 != snap) { trk.MoveLine(line, snap, line.Position2); } } else if (line.Position2 == endpoint) { // don't snap to the same point. if (line.Position != snap) { trk.MoveLine(line, line.Position, snap); } } else { throw new Exception("Endpoint does not match line position in snap. It's not one of the ends of the line."); } break; } } }