public void CreateLine() { var action = new CreateLineAction(storage, listener); TailLine = action.Act(); Actions.AddLast(action); }
public IEnumerator AngleZeroWithZeroLengthEdge() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p = rn.BuildStation(); yield return(null); var e12 = rn.Extend(new Vector3(0f, 0f)); yield return(null); var e23 = e12.To.Extend(new Vector3(0f, 0f)); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept = new DeptTask(utils.storage, utils.listener, l, p); var mv12 = new EdgeTask(utils.storage, utils.listener, l, e12, dept); Assert.AreEqual(mv12.SignedAngle(e23), 0f); }
public IEnumerator Angle() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(-1f, 0f)); yield return(null); var p = rn.BuildStation(); yield return(null); var e12 = rn.Extend(new Vector3(0f, 0f)); yield return(null); var e23 = e12.To.Extend(new Vector3(1, Mathf.Sqrt(3))); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept = new DeptTask(utils.storage, utils.listener, l, p); var mv12 = new EdgeTask(utils.storage, utils.listener, l, e12, dept); // mv12 (x軸) から e23 (1, √3) は 240° 回転した位置に見える (左向き正) Assert.AreEqual(-120f, mv12.SignedAngle(e23), utils.DELTA); }
public IEnumerator AngleErrorNonNeighbor() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(0f, 0f)); var rnX = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p = rn.BuildStation(); yield return(null); var e12 = rn.Extend(new Vector3(1f, 1f)); var eX = rnX.Extend(new Vector3(1f, 1f)); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept = new DeptTask(utils.storage, utils.listener, l, p); var move = new EdgeTask(utils.storage, utils.listener, l, e12, dept); yield return(null); Assert.Throws <ArgumentException>(() => move.SignedAngle(eX)); }
public IEnumerator AngleErrorWhenAllTaskZeroLength() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn.BuildStation(); yield return(null); var e12 = rn.Extend(new Vector3(0f, 0f)); yield return(null); var rn2 = e12.To; var p2 = rn2.BuildStation(); yield return(null); var e23 = rn2.Extend(new Vector3(0f, 0f)); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept1 = new DeptTask(utils.storage, utils.listener, l, p1); dept1.InsertEdge(e12); var dept2 = dept1.Next.Next; Assert.Throws <ArgumentException>(() => dept2.SignedAngle(e23)); }
public IEnumerator InsertPlatformErrorUnNeighbored() { yield return(null); var rn1 = utils.factory.NewRailNode(new Vector3(0f, 0f)); var rnX = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn1.BuildStation(); var pX = rnX.BuildStation(); yield return(null); var e12 = rn1.Extend(new Vector3(1f, 1f)); yield return(null); var rn2 = e12.To; var l = new RailLine(utils.storage, utils.listener); l.StartLine(p1); var dept1 = l.Top; dept1.InsertEdge(e12); var mv12 = dept1.Next; Assert.Throws <ArgumentException>(() => mv12.InsertPlatform(pX)); }
public IEnumerator InsertEdgeToStation() { yield return(null); var rn1 = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn1.BuildStation(); yield return(null); var e12 = rn1.Extend(new Vector3(1f, 1f)); yield return(null); var e21 = e12.Reverse; var rn2 = e12.To; var p2 = rn2.BuildStation(); yield return(null); var l = new RailLine(utils.storage, utils.listener); l.StartLine(p1); var dept1 = l.Top; // rn1 -> [dept1] -> rn1 -> [mv12] -> rn2 -> [dept2] -> [mv21] -> rn1 dept1.InsertEdge(e12); var mv12 = dept1.Next; Assert.IsInstanceOf(typeof(EdgeTask), mv12); Assert.AreSame(l, mv12.Parent); Assert.AreSame(e12, (mv12 as EdgeTask).Edge); Assert.AreSame(rn1, mv12.Departure); Assert.AreSame(rn2, mv12.Destination); Assert.AreEqual(e12.Arrow.magnitude, mv12.Length, utils.DELTA); Assert.AreSame(mv12, dept1.Next); Assert.AreSame(dept1, mv12.Prev); var dept2 = mv12.Next; Assert.IsInstanceOf(typeof(DeptTask), dept2); Assert.AreSame(p2, (dept2 as DeptTask).Stay); Assert.AreSame(rn2, dept2.Departure); Assert.AreSame(rn2, dept2.Destination); Assert.AreSame(dept2, mv12.Next); Assert.AreSame(mv12, dept2.Prev); var mv21 = dept2.Next; Assert.AreSame(l, mv21.Parent); Assert.AreSame(e21, (mv21 as EdgeTask).Edge); Assert.AreSame(rn2, mv21.Departure); Assert.AreSame(rn1, mv21.Destination); Assert.AreSame(mv21, dept2.Next); Assert.AreSame(dept2, mv21.Prev); Assert.AreSame(dept1, mv21.Next); Assert.AreSame(mv21, dept1.Prev); }
public IEnumerator InsertEdgeToNonStationEdge() { yield return(null); var rn1 = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn1.BuildStation(); yield return(null); var e12 = rn1.Extend(new Vector3(1f, 1f)); yield return(null); var e21 = e12.Reverse; var rn2 = e12.To; var e23 = rn2.Extend(new Vector3(2f, 2f)); yield return(null); var rn3 = e23.To; var e32 = e23.Reverse; var l = new RailLine(utils.storage, utils.listener); l.StartLine(p1); var dept1 = l.Top; // 1. rn1 -> [e12] -> rn2 // 2. rn1 -> [e12] -> rn2 -> [e23] -> rn3 dept1.InsertEdge(e12); var mv12 = dept1.Next; mv12.InsertEdge(e23); var mv23 = mv12.Next; Assert.IsInstanceOf(typeof(EdgeTask), mv23); Assert.AreSame(l, mv23.Parent); Assert.AreSame(e23, (mv23 as EdgeTask).Edge); Assert.AreSame(rn2, mv23.Departure); Assert.AreSame(rn3, mv23.Destination); Assert.AreEqual(e23.Arrow.magnitude, mv23.Length, utils.DELTA); Assert.AreSame(mv23, mv12.Next); Assert.AreSame(mv12, mv23.Prev); var mv32 = mv23.Next; Assert.AreSame(l, mv32.Parent); Assert.AreSame(e32, (mv32 as EdgeTask).Edge); Assert.AreSame(rn3, mv32.Departure); Assert.AreSame(rn2, mv32.Destination); Assert.AreSame(mv32, mv23.Next); Assert.AreSame(mv23, mv32.Prev); Assert.AreSame(mv32, mv32.Next.Prev); }
public DeptTask(ModelStorage db, ModelListener lis, RailLine l, Platform p, LineTask lt) : base(db, lis, l, lt) { Stay = p; Stay.Depts.AddLast(this); db.Add(this); Queue = new LinkedList <Human>(); router = new RouterImpl(this); listener.Fire(EventType.CREATED, this); }
public IEnumerator InsertPlatform() { yield return(null); var rn1 = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn1.BuildStation(); yield return(null); var e12 = rn1.Extend(new Vector3(1f, 1f)); yield return(null); var e21 = e12.Reverse; var rn2 = e12.To; var l = new RailLine(utils.storage, utils.listener); l.StartLine(p1); var dept1 = l.Top; dept1.InsertEdge(e12); var mv12 = dept1.Next; var mv21 = mv12.Next; var p2 = rn2.BuildStation(); yield return(null); mv12.InsertPlatform(p2); var dept2 = mv12.Next; Assert.IsInstanceOf(typeof(DeptTask), dept2); Assert.AreSame(p2, (dept2 as DeptTask).Stay); Assert.AreSame(rn2, dept2.Departure); Assert.AreSame(rn2, dept2.Destination); Assert.AreSame(dept2, mv12.Next); Assert.AreSame(mv12, dept2.Prev); Assert.AreSame(mv21, dept2.Next); Assert.AreSame(dept2, mv21.Prev); }
public IEnumerator InsertPlatformErrorDuplicated() { yield return(null); var rn1 = utils.factory.NewRailNode(new Vector3(0f, 0f)); var rnX = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p1 = rn1.BuildStation(); var pX = rnX.BuildStation(); yield return(null); var l = new RailLine(utils.storage, utils.listener); l.StartLine(p1); var dept = l.Top; Assert.Throws <ArgumentException>(() => dept.InsertPlatform(pX)); }
public IEnumerator AngleErrorOnlyDeptTask() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(0f, 0f)); yield return(null); var p = rn.BuildStation(); yield return(null); var re = rn.Extend(new Vector3(1f, 1f)); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept = new DeptTask(utils.storage, utils.listener, l, p); Assert.True(dept.IsNeighbor(re)); Assert.Throws <ArgumentException>(() => dept.SignedAngle(re)); }
public IEnumerator FirstDeparture() { yield return(null); var rn = utils.factory.NewRailNode(new Vector3(1f, 2f, 3f)); yield return(null); var p = rn.BuildStation(); yield return(null); var l = new RailLine(utils.storage, utils.listener); var dept = new DeptTask(utils.storage, utils.listener, l, p); Assert.AreSame(p, dept.Stay); Assert.AreSame(l, dept.Parent); Assert.AreSame(dept, dept.Prev); Assert.AreSame(dept, dept.Next); Assert.AreSame(rn, dept.Departure); Assert.AreSame(rn, dept.Destination); Assert.AreEqual(0, dept.Length); }
public InsertPlatformAction(RailLine l) { line = l; }
public StartLineAction(RailLine l) { line = l; }
public InsertEdgeAction(RailLine l) { line = l; }
private float Payment(float length, RailLine l) { return(length / Mathf.Sqrt(l.Length) * PayRatio); }
public RailLine Act() { l = new RailLine(storage, listener); return(l); }
public EdgeTask(ModelStorage db, ModelListener lis, RailLine l, RailEdge re, LineTask lt) : base(db, lis, l, lt) { Edge = re; db.Add(this); listener.Fire(EventType.CREATED, this); }
public LineTask(ModelStorage db, ModelListener lis, RailLine line, LineTask lt) : this(db, lis) { Parent = line; Prev = lt; Prev.Next = this; }
public CreateLineAction(ModelStorage db, ModelListener lis, RailLine line, RollbackFn fn) : this(db, lis) { prevLine = line; rollback = fn; }