コード例 #1
0
        public static void Build <T>(List <Segment> segments, int mask, float samplingStep, int strokeSize, BrushFunction <T> brushFunction, int mapSize, WorldToMapCoords worldToMapCoords, T[,] map)
        {
            Stroke stroke = new Stroke();

            stroke.halfSize  = Mathf.CeilToInt(strokeSize * 0.5f);
            stroke.halfSize2 = stroke.halfSize * stroke.halfSize;
            HashSet <Segment> visited = new HashSet <Segment>();

            foreach (var segment in segments)
            {
                RoadNetworkTraversal.PreOrder(segment, (s0) =>
                {
                    stroke.segment          = s0;
                    stroke.segmentDirection = (s0.End - s0.Start) / s0.Length;
                    int numSteps            = Mathf.CeilToInt(s0.Length / samplingStep);
                    var segmentStep         = 1.0f / numSteps;
                    var positionIncrement   = s0.Length / numSteps * stroke.segmentDirection;
                    stroke.segmentStep      = 0;
                    stroke.segmentCoords    = s0.Start;
                    int x, y;
                    for (int step = 0; step < numSteps; step++, stroke.segmentCoords += positionIncrement, stroke.segmentStep += segmentStep)
                    {
                        if (!worldToMapCoords(stroke.segmentCoords.x, stroke.segmentCoords.y, out x, out y))
                        {
                            break;
                        }
                        stroke.x = x;
                        stroke.y = y;
                        brushFunction(stroke, mapSize, map);
                    }
                    return(true);
                }, mask, ref visited);
            }
        }
コード例 #2
0
        public static IRoadNetworkGeometry Build(
            float scale,
            float highwayWidth,
            float streetWidth,
            float lengthStep,
            List <Segment> segments,
            int mask = 0)
        {
            Context           context = new Context(scale, highwayWidth, streetWidth, lengthStep);
            HashSet <Segment> visited = new HashSet <Segment>();

            foreach (var segment in segments)
            {
                RoadNetworkTraversal.PreOrder(segment, ref context, SegmentCrossingVisitor, mask, ref visited);
            }
            visited.Clear();
            foreach (var segment in segments)
            {
                RoadNetworkTraversal.PreOrder <Context, UserData>(null, segment, ref context, null, SegmentVisistor, mask, ref visited);
            }
            return(context);
        }