Consists of 2 points
コード例 #1
0
ファイル: RoadBuilder.cs プロジェクト: TobieD/City-Generator
        private Line CreateIntersectedLine(Line newLine,Point ip, ref bool flipped)
        {
            var start = newLine.Start;
            var end = newLine.End;

            //Check if the new line will not be too small
            //if it is too small switch the start point with the previous end point
            var totalDistance = MathHelpers.DistanceBetweenPoints(start, end);
            var newDistance = MathHelpers.DistanceBetweenPoints(start, ip);

            //Create the new line
            //swap occurs when the new distance is smaller than 1/3 of the original distance
            flipped = newDistance < (totalDistance*0.33);
            var line = flipped? new Line(ip,end) : new Line(start, ip);

            return line;
        }
コード例 #2
0
ファイル: RoadBuilder.cs プロジェクト: TobieD/City-Generator
        private void HandlePossibleRoadIntersections(Line line, Road startLine, Road endLine,List<Road> borders,List<Road> innerRoads )
        {
            bool flipped = false;

            //check for possible intersection,
            //if an intersection happens the end point becomes the point of intersection
            //has to be reverse because otherwise the lines will intersect with the edges
            for (var i = 0; i < innerRoads.Count; i++)
            {
                var l = innerRoads[i];

                //if the line intersects
                if (!line.IntersectsWith(l)) continue;

                //find the intersection point
                bool parallel = false;
                var ip = line.FindIntersectionPoint(l, ref parallel);

                //parrallel lines don't intersect so ignore
                if (parallel) continue;

                //Create the new line from the intersection
                line = CreateIntersectedLine(line, ip, ref flipped);

                //Split the line that is intersected with in 2 new lines
                if (flipped)
                {
                    startLine = innerRoads[i];
                }
                else
                {
                    endLine = innerRoads[i];
                }

                //stop at the first intersection
                break;
            }

            //Because of the new line the start and end line will have to be split in 2 new lines
            //the total of new lines will be 3

            //Adjust the borders
            borders.Remove(startLine);
            borders.Remove(endLine);

            //create the split lines
            borders.Add(new Road(startLine.Start,line.Start));
            borders.Add(new Road(line.Start, startLine.End));

            borders.Add( new Road(endLine.Start, line.End));
            borders.Add(new Road(line.End, endLine.End));

            //Add the new road to the inner roads
            innerRoads.Add(Road.FromLine(line));

            innerRoads.Remove(startLine);
            innerRoads.Remove(endLine);
        }
コード例 #3
0
ファイル: RoadBuilder.cs プロジェクト: TobieD/City-Generator
        private SplitLine SplitLine(Line line, Point ip)
        {
            var start = line.Start;
            var end = line.End;

            return new SplitLine(new Line(start,ip),new Line(ip,end));
        }
コード例 #4
0
        public static Road FromLine(Line l)
        {
            var r = new Road(l.Start, l.End)
            {
                CellLeft = l.CellLeft,
                CellRight = l.CellRight
            };

            return r;
        }