예제 #1
0
    public void CreateLine()
    {
        var action = new CreateLineAction(storage, listener);

        TailLine = action.Act();
        Actions.AddLast(action);
    }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
 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);
 }
예제 #10
0
        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);
        }
예제 #11
0
        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));
        }
예제 #12
0
        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));
        }
예제 #13
0
        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);
        }
예제 #14
0
 public InsertPlatformAction(RailLine l)
 {
     line = l;
 }
예제 #15
0
 public StartLineAction(RailLine l)
 {
     line = l;
 }
예제 #16
0
 public InsertEdgeAction(RailLine l)
 {
     line = l;
 }
예제 #17
0
 private float Payment(float length, RailLine l)
 {
     return(length / Mathf.Sqrt(l.Length) * PayRatio);
 }
예제 #18
0
 public RailLine Act()
 {
     l = new RailLine(storage, listener);
     return(l);
 }
예제 #19
0
 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);
 }
예제 #20
0
 public LineTask(ModelStorage db, ModelListener lis, RailLine line, LineTask lt) : this(db, lis)
 {
     Parent    = line;
     Prev      = lt;
     Prev.Next = this;
 }
예제 #21
0
 public CreateLineAction(ModelStorage db, ModelListener lis, RailLine line, RollbackFn fn) : this(db, lis)
 {
     prevLine = line;
     rollback = fn;
 }