Example #1
0
        public PathConnectWrapper(ushort endNodeID, ushort endSegmentID)
        {
            this.endSegmentID = endSegmentID;
            this.endNodeID    = endNodeID;

            HitSegmentID = FindConnactableSegment(endNodeID, endSegmentID, out HitPoint);
            //Log.Debug($"PathConnectWrapper detected segmentID={HitSegmentID}");

            if (HitSegmentID == 0)
            {
                node1   = node2 = null;
                segment = null;
                return;
            }
            Vector2 start = endNodeID.ToNode().m_position.ToCS2D();
            Vector2 dir   = (HitPoint - start).normalized;

            var         nodeInfo    = endNodeID.ToNode().Info;
            var         segmentInfo = HitSegmentID.ToSegment().Info;
            const float endWidth    = 8;//meters
            Vector2     startPoint  = start + (ControlCenter.HalfWidth + endWidth + SAFETY_NET) * dir;
            Vector2     endPoint    = HitPoint - (ControlCenter.HalfWidth + segmentInfo.m_halfWidth + SAFETY_NET) * dir;

            node1   = new NodeWrapper(startPoint, 0);
            node2   = new NodeWrapper(endPoint, 0);
            segment = new SegmentWrapper(node1, node2);
        }
Example #2
0
 public RoadBridgeWrapper(ushort segmentID, float t)
 {
     _side1 = new RoadSideWrapper(segmentID, t, leftSide: false);
     _side2 = new RoadSideWrapper(segmentID, t, leftSide: true);
     if (IsValid)
     {
         _bridge = new SegmentWrapper(_side1.node0, _side2.node0);
     }
 }
        public JunctionWrapper(ushort nodeID)
        {
            NodeID      = nodeID;
            _segList    = GetCCSegList(nodeID).ToList();
            _count      = _segList.Count;
            _corners    = new List <LWrapper>(_count);
            _overPasses = new List <SegmentWrapper>(_count - 1);
            if (_count < MIN_SEGMENT_COUNT)
            {
                Log.Debug("number of segments is less than " + MIN_SEGMENT_COUNT);
                return;
            }

            for (int i = 0; i < _count; ++i)
            {
                ushort segID1 = _segList[i], segID2 = _segList[(i + 1) % _count];
                var    corner = new LWrapper(segID1, segID2);
                //Log.Info($"created L from segments: {segID1} {segID2}");
                if (corner.Valid)
                {
                    _corners.Add(corner);
                    this.IsValid = true;
                }
            }

            if (_count < 2)
            {
                return;
            }
            for (int i = 0; i < _count; ++i)
            {
                var startNode = _corners[i].nodeL;
                var endNode   = _corners[(i + 1) % _count].nodeL;
                if (startNode != null && endNode != null)
                {
                    if (_count == 2 && i == 1)
                    {
                        continue;
                    }
                    SegmentWrapper segment = new SegmentWrapper(
                        startNode, endNode);
                    _overPasses.Add(segment);
                }
            }
        }
        public RaboutWraper(RoundaboutUtil raboutCalc, NetInfo info)
        {
            _raboutCalc = raboutCalc;
            _junctions  = raboutCalc.GetJunctions();
            int n = _junctions.Count;

            if (n < 3)
            {
                Log.Info("Roundabout has too few junctions.");
                return;
            }
            Vector2 centerPoint = raboutCalc.CalculateCenter();

            _center   = new NodeWrapper(centerPoint, ControlCenter.Elevation);
            _slices   = new List <RaboutSlice>(n);
            _segments = new List <SegmentWrapper>(n - 1);

            for (int i = 0; i < n; ++i)
            {
                var i2    = (i + 1) % n;
                var slice = new RaboutSlice(
                    _junctions[i].Main2, _junctions[i].Minor,
                    _junctions[i2].Main1, _junctions[i2].Minor,
                    raboutCalc.SegmentList,
                    _center,
                    info);
                _slices.Add(slice);
                if (slice.IsValid)
                {
                    this.IsValid = true;
                }
            }

            if (ControlCenter.RoundaboutBridgeStyle == RoundaboutBridgeStyleT.Star)
            {
                return;
            }
            if (_slices.Count == 1)
            {
                return;
            }

            // get last valid slice.
            RaboutSlice slice_prev = null;

            for (int i = _slices.Count - 1; i >= 0; --i)
            {
                if (_slices[i].IsValid)
                {
                    slice_prev = _slices[i];
                    break;
                }
            }
            if (slice_prev == null)
            {
                return;
            }

            foreach (var slice in _slices)
            {
                if (!slice.IsValid)
                {
                    continue;
                }
                if (slice_prev.IsValid)
                {
                    var segment12 = slice_prev.segment_circle2;
                    var segment21 = slice.segment_circle1;
                    if (segment12 != null && segment21 != null)
                    {
                        var segment = new SegmentWrapper(
                            segment12.EndNode, segment21.EndNode,
                            -segment12.EndDir, -segment21.EndDir);
                        _segments.Add(segment);
                    }
                }
                slice_prev = slice;
            }
        }