/* * Copyright (c) 2005-2006 Erik Tigerholm * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization; namespace OpenTraffic.Model.Graph { [Serializable] public class GraphEdge : IGraphEdge where TV : Vertex { [XmlElement(ElementName = "Name")] public string Name { get { return name; } set { name = value; } } [XmlElement(ElementName = "Description")] public string Description { get { return description; } set { description = value; } } [XmlIgnore] public TV Source { get; set; } [XmlIgnore] public TV Target { get; set; } [XmlIgnore] public Vertex SourceVertex { get { return Source; } } [XmlIgnore] public Vertex TargetVertex { get { return Target; } } [XmlIgnore] public int Id { get { return id; } set { id = value; } } public List Shape { get { return shape; } // set { shape = value; } } private List shape; private int id; private string name; private string description; public string DisplayString { get { return this.ToString(); } } public GraphEdge() { } public GraphEdge(int id, TV source, TV target, string name) : this(id, source, target, name, "") { } public GraphEdge(int id, TV source, TV target, string name, string description) { this.id = id; this.Source = source; this.Target = target; this.name = name; this.shape = new List(); this.description = description; } public virtual void GenerateShape(int nvert) { GenerateShape(nvert, 15); } public void GenerateShape(int nvert, float r) { double dx = Target.X - Source.X; double dy = Target.Y - Source.Y; double d = Math.Sqrt(dx * dx + dy * dy); shape.Clear(); for (int i = 0; i < nvert; i++) { float s = (i + 1) / (float)(nvert + 1); shape.Add(new GraphCoordinate((float)(Source.X + dx * s - r * Math.Sin(s * Math.PI) * dy / d), (float)(Source.Y + dy * s + r * Math.Sin(s * Math.PI) * dx / d))); } } } }