private static UseCtorToCreateControl<RoadConnection> CreateNewCommand( RoadConnection control ) { return Actions.CreateControl( control.Id, () => new RoadConnection( Is.Ioc<Factories.Factories>(), Is.Const( control.Location ) ) ); }
public void SetUp() { this._factories = IOC.GetService<Factories>(); this._connectionCommand = new ConnectRoadConnectionWithRoadConnection(); this._firstRoadConnection = new RoadConnection(_factories, new Vector2(0, 0), null); this._secondRoadConnection = new RoadConnection(_factories, new Vector2(0, 2), null); }
public void ConnectWith(RoadNode node, Direction dir) { connections[dir] = new RoadConnection() { from = this, to = node }; }
public TwoRoadJunctionConnectedByRoadLaneWithRoadConnectionInMiddle() { var factories = IOC.GetService<Factories>(); this.FirstRoadJunction = new RoadJunctionBlock( factories, Vector2.Zero, null ); this.SecondRoadJunction = new RoadJunctionBlock( factories, new Vector2( 2.0f, 0 ), null ); this.FirstRoadLaneBlock = new RoadLaneBlock( factories, null ); this.SecondRoadLaneBlock = new RoadLaneBlock( factories, null ); this.RoadConnection = new RoadConnection( factories, new Vector2( 1.0f, 0.0f ), null ); }
private static void AddUnique(List <RoadConnection> origin, List <SplineComputer> list) { foreach (var item in list) { if (origin.All(rc => rc.GetconnectedRoad() != item)) { var roadConnection = new RoadConnection(item); origin.Add(roadConnection); } } }
private IEnumerable<IAction> Convert( RoadConnection control ) { yield return CreateNewCommand( control ); yield return Actions.Call<RoadConnection>( control.Id, () => control.Connector.ConnectBeginWith( Find.In( control.Connector.PreviousConnectedEdge.Parent ).Property( control.Connector.PreviousConnectedEdge ) ) ); yield return Actions.Call<RoadConnection>( control.Id, () => control.Connector.ConnectEndWith( Find.In( control.Connector.NextConnectedEdge.Parent ).Property( control.Connector.NextConnectedEdge ) ) ); // yield return base.BuildRoutes( control ); }
public RoadConnectionConnector( RoadConnection owner ) { this._owner = owner; this._helper = new ConnectEdgesHelper( owner.Edge, owner ); }
public bool ConnectRoad() { foreach (var departRoad in roads) { foreach (var arrivRoad in roads) { if (departRoad != arrivRoad) { Vector3 departDir; Vector3 departOffsetDir; if (departRoad.GetPoints().Last().position == this.GetPosition()) { int lastIndex = departRoad.GetPoints().Length - 1; departDir = departRoad.GetPoint(lastIndex).position - departRoad.GetPoint(lastIndex - 1).position; departOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * departDir; } else { departDir = departRoad.GetPoint(0).position - departRoad.GetPoint(1).position; departOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * departDir; } Vector3 arrivDir; Vector3 arrivOffsetDir; if (arrivRoad.GetPoints().Last().position == GetPosition()) { int lastIndex = arrivRoad.GetPoints().Length - 1; arrivDir = arrivRoad.GetPoint(lastIndex - 1).position - arrivRoad.GetPoint(lastIndex).position; arrivOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * arrivDir; } else { arrivDir = arrivRoad.GetPoint(1).position - arrivRoad.GetPoint(0).position; arrivOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * arrivDir; } float depart_divider = 0; float arriv_divider = 0; switch (departRoad.roadLane) { case CreatePathManager.ROADLANE.RL05: depart_divider = 1.5f; break; case CreatePathManager.ROADLANE.RL1: depart_divider = 3f; break; case CreatePathManager.ROADLANE.RL2: depart_divider = 3f; break; } switch (arrivRoad.roadLane) { case CreatePathManager.ROADLANE.RL05: arriv_divider = 1.5f; break; case CreatePathManager.ROADLANE.RL1: arriv_divider = 3f; break; case CreatePathManager.ROADLANE.RL2: arriv_divider = 3f; break; } var per_depart = departRoad.Project(GetPosition() - departDir / depart_divider).percent; var departPoint = departRoad.EvaluatePosition(per_depart); var per_arriv = arrivRoad.Project(GetPosition() + arrivDir / arriv_divider).percent; var arrivPoint = arrivRoad.EvaluatePosition(per_arriv); // If failed to get Point Value, Re-try if (Vector3.Distance(departPoint, arrivPoint) >= 20) { ConnectRoad(); return(false); } // Normalize Offset Vectors departOffsetDir.Normalize(); arrivOffsetDir.Normalize(); // Offset List var departOffsetList = new List <float>(); var arrivOffsetList = new List <float>(); switch (departRoad.roadLane) { case CreatePathManager.ROADLANE.RL05: departOffsetList.Add(road_offset[0]); break; case CreatePathManager.ROADLANE.RL1: departOffsetList.Add(road_offset[1]); break; case CreatePathManager.ROADLANE.RL2: departOffsetList.Add(road_offset[1]); departOffsetList.Add(road_offset[2]); break; } switch (arrivRoad.roadLane) { case CreatePathManager.ROADLANE.RL05: arrivOffsetList.Add(road_offset[0]); break; case CreatePathManager.ROADLANE.RL1: arrivOffsetList.Add(road_offset[1]); break; case CreatePathManager.ROADLANE.RL2: arrivOffsetList.Add(road_offset[1]); arrivOffsetList.Add(road_offset[2]); break; } foreach (var dRightOffset in departOffsetList) { foreach (var aRightOffset in arrivOffsetList) { var start_offset = road_offset.FirstOrDefault(x => x.Value == dRightOffset).Key; var end_offset = road_offset.FirstOrDefault(x => x.Value == aRightOffset).Key; // Set Point Position by Offset var departPointOA = departPoint + departOffsetDir * dRightOffset; var arrivPointOA = arrivPoint + arrivOffsetDir * aRightOffset; // Calc Inter Point Vector3 interPoint; if (CreatePathManager.isVectorParallel(departDir, arrivDir)) { interPoint = (departPointOA + arrivPointOA) / 2; } else { LineLineIntersection(out interPoint, departPointOA, departDir, arrivPointOA, -arrivDir); } if (Vector3.Distance(departPointOA, arrivPointOA) >= 20 || Vector3.Distance(departPointOA, interPoint) >= 20 || Vector3.Distance(interPoint, arrivPointOA) >= 20) { ConnectRoad(); return(false); } var connectingSpline = pathManager.InsSpline(GetPosition()); connectingSpline.name = departRoad.name + " - " + arrivRoad.name + " / " + start_offset + " - " + end_offset; // Spawn Depart Point connectingSpline.SetPointNormal(0, CreatePathManager.def_normal); connectingSpline.SetPointSize(0, 1); connectingSpline.SetPointPosition(0, departPointOA); // Spawn Inter Point connectingSpline.SetPointNormal(1, CreatePathManager.def_normal); connectingSpline.SetPointSize(1, 1); connectingSpline.SetPointPosition(1, interPoint); // Spawn Arriv Point connectingSpline.SetPointNormal(2, CreatePathManager.def_normal); connectingSpline.SetPointSize(2, 1); connectingSpline.SetPointPosition(2, arrivPointOA); var roadConnection = departRoad.roadConnectionList.FirstOrDefault(rc => rc.GetconnectedRoad() == arrivRoad); if (roadConnection != null) { roadConnection.AddConnector(connectingSpline, start_offset, end_offset); } else { var rc = new RoadConnection(arrivRoad); rc.AddConnector(connectingSpline, start_offset, end_offset); departRoad.roadConnectionList.Add(rc); } } } } } } return(true); }
public LaneCorner( RoadConnection control, Func<LaneCorner, IRoadInformation> conductorFactory ) : base( control ) { Contract.Requires( control != null ); Contract.Requires( conductorFactory != null ); Contract.Ensures( this.Information != null ); this.LaneCornerBuild = control; this._roadInformation = conductorFactory( this ); }