Пример #1
0
        public void CheckRouteOffsets()
        {
            var network           = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100));
            var branch            = network.Branches[0];
            var networkLocation0  = new NetworkLocation(branch, 0);
            var networkLocation10 = new NetworkLocation(branch, 10);
            var networkLocation20 = new NetworkLocation(branch, 20);
            var networkLocation30 = new NetworkLocation(branch, 30);
            var networkLocation40 = new NetworkLocation(branch, 40);

            branch.BranchFeatures.Add(networkLocation0);
            branch.BranchFeatures.Add(networkLocation10);
            branch.BranchFeatures.Add(networkLocation20);
            branch.BranchFeatures.Add(networkLocation30);
            branch.BranchFeatures.Add(networkLocation40);

            var route = RouteHelper.CreateRoute(
                new[] { new NetworkLocation(branch, 5), new NetworkLocation(branch, 35) });
            var route2 = RouteHelper.CreateRoute(
                new[] { new NetworkLocation(branch, 35), new NetworkLocation(branch, 5) });

            Assert.AreEqual(-1, RouteHelper.GetRouteOffset(route, networkLocation0));
            Assert.AreEqual(5, RouteHelper.GetRouteOffset(route, networkLocation10));
            Assert.AreEqual(15, RouteHelper.GetRouteOffset(route, networkLocation20));
            Assert.AreEqual(25, RouteHelper.GetRouteOffset(route, networkLocation30));
            Assert.AreEqual(-1, RouteHelper.GetRouteOffset(route, networkLocation40));

            Assert.AreEqual(-1, RouteHelper.GetRouteOffset(route2, networkLocation0));
            Assert.AreEqual(25, RouteHelper.GetRouteOffset(route2, networkLocation10));
            Assert.AreEqual(15, RouteHelper.GetRouteOffset(route2, networkLocation20));
            Assert.AreEqual(5, RouteHelper.GetRouteOffset(route2, networkLocation30));
            Assert.AreEqual(-1, RouteHelper.GetRouteOffset(route2, networkLocation40));
        }
Пример #2
0
        public void GetRouteOffsetCustomLength()
        {
            var network = CreateThreeNodesNetwork();

            network.Branches[0].IsLengthCustom = true;
            network.Branches[0].Length        *= 2;
            network.Branches[1].IsLengthCustom = true;
            network.Branches[1].Length        *= 3;

            var networkLocation = new NetworkLocation(network.Branches[1], 30);

            NetworkHelper.AddBranchFeatureToBranch(networkLocation, network.Branches[1], 30);

            var route = new Route
            {
                Network = network,
            };

            //route going back to branch 0
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 110.0));
            Assert.AreEqual(225.0, RouteHelper.GetRouteOffset(route, networkLocation));
        }