/// <summary> /// 绘制地铁站点间的线路。 /// </summary> /// <param name="g">绘图图面。</param> /// <param name="link">地铁站点间的线路。</param> private void PaintLink(Graphics g, MetroLink link) { Point pt1 = new Point(link.From.X, link.From.Y); Point pt2 = new Point(link.To.X, link.To.Y); using (Pen pen = new Pen(link.Line.Color, 5)) { pen.LineJoin = LineJoin.Round; if (link.Flag == 0) {//单线 g.DrawLine(pen, pt1, pt2); } else if (link.Flag > 0) {//双线并轨(如果是同向,则Flag分别为1和2,否则都为1) float scale = (pen.Width / 2) / Distance(pt1, pt2); float angle = (float)(Math.PI / 2); if (link.Flag == 2) { angle *= -1; } //平移线段 var pt3 = Rotate(pt2, pt1, angle, scale); var pt4 = Rotate(pt1, pt2, -angle, scale); g.DrawLine(pen, pt3, pt4); } } }
/// <summary> /// 最佳一条新的Link,并返回一条新的路线。 /// </summary> /// <param name="link"></param> /// <returns></returns> /// <exception cref="ArgumentNullException">如果link为空引用,则跑出该异常。</exception> public MetroPath Append(MetroLink link) { if (link == null) throw new ArgumentNullException("link"); MetroPath newPath = new MetroPath(); newPath.Links.AddRange(this.Links); newPath.Links.Add(link); return newPath; }
/// <summary> /// 最佳一条新的Link,并返回一条新的路线。 /// </summary> /// <param name="link"></param> /// <returns></returns> /// <exception cref="ArgumentNullException">如果link为空引用,则跑出该异常。</exception> public MetroPath Append(MetroLink link) { if (link == null) { throw new ArgumentNullException("link"); } MetroPath newPath = new MetroPath(); newPath.Links.AddRange(this.Links); newPath.Links.Add(link); return(newPath); }
/// <summary> /// 绘制地铁站点间的线路。 /// </summary> /// <param name="g">绘图图面。</param> /// <param name="link">地铁站点间的线路。</param> private void PaintLink(Graphics g, MetroLink link) { Point pt1 = new Point(link.From.X, link.From.Y); Point pt2 = new Point(link.To.X, link.To.Y); using (Pen pen = new Pen(link.Line.Color, 5)) { pen.LineJoin = LineJoin.Round; if (link.Flag == 0) {//单线 g.DrawLine(pen, pt1, pt2); } else if (link.Flag > 0) {//双线并轨(如果是同向,则Flag分别为1和2,否则都为1) float scale = (pen.Width / 2) / Distance(pt1, pt2); float angle = (float)(Math.PI / 2); if (link.Flag == 2) angle *= -1; var pt3 = Rotate(pt2, pt1, angle, scale); var pt4 = Rotate(pt1, pt2, -angle, scale); g.DrawLine(pen, pt3, pt4); } } }