예제 #1
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="outline"></param>
        /// <param name="penWidth"></param>
        protected override void DrawRoom(GridPolygon polygon, List <Tuple <IntVector2, bool> > outline, float penWidth)
        {
            // Draw polygon
            data.Append($"    <polygon points=\"");

            foreach (var point in polygon.GetPoints())
            {
                data.Append($"{point.X},{point.Y} ");
            }

            data.Append($"\" style=\"fill:rgb(211,211,211);stroke:rgb(211,211,211)\" />");
            data.AppendLine();

            // Draw path
            data.Append($"    <path d=\"");

            var lastPoint = outline[outline.Count - 1].Item1;

            data.Append($"M {lastPoint.X} {lastPoint.Y} ");

            foreach (var pair in outline)
            {
                var point = pair.Item1;

                data.Append(pair.Item2 ? $"L {point.X} {point.Y} " : $"M {point.X} {point.Y} ");
            }

            data.Append($"\" fill=\"none\" stroke=\"black\" stroke-linecap=\"square\" stroke-width=\"{penWidth}\" />");
            data.AppendLine();
        }
        protected override void DrawRoom(GridPolygon polygon, List <Tuple <IntVector2, bool> > outline, float penWidth)
        {
            var polyPoints = polygon.GetPoints().Select(point => new Point(point.X, point.Y)).ToList();

            graphics.FillPolygon(Brushes.LightGray, polyPoints.ToArray());

            var lastPoint = outline[outline.Count - 1].Item1;
            var pen       = new Pen(Color.Black, penWidth)
            {
                EndCap   = LineCap.Flat,
                StartCap = LineCap.Flat
            };

            foreach (var pair in outline)
            {
                var point = pair.Item1;

                if (pair.Item2)
                {
                    graphics.DrawLine(pen, lastPoint.X, lastPoint.Y, point.X, point.Y);
                }

                lastPoint = point;
            }
        }
예제 #3
0
        /// <inheritdoc />
        protected override void DrawRoom(GridPolygon polygon, List <Tuple <IntVector2, bool> > outline, float penWidth)
        {
            var polyPoints = polygon.GetPoints().Select(point => new Point(point.X, point.Y)).ToList();
            var offset     = polygon.BoundingRectangle.A;

            innerBrush.TranslateTransform(offset.X, offset.Y);
            graphics.FillPolygon(innerBrush, polyPoints.ToArray());
            innerBrush.ResetTransform();

            var lastPoint = outline[outline.Count - 1].Item1;

            foreach (var pair in outline)
            {
                var point = pair.Item1;

                if (pair.Item2)
                {
                    graphics.DrawLine(outlinePen, lastPoint.X, lastPoint.Y, point.X, point.Y);
                }

                lastPoint = point;
            }
        }
        /// <inheritdoc />
        public List <GridRectangle> GetPartitions(GridPolygon polygon)
        {
            IList <IntVector2> points = polygon.GetPoints();

            var vertices = new List <Vertex>();

            var prev = points[points.Count - 3];
            var curr = points[points.Count - 2];
            var next = points[points.Count - 1];

            // Process vertices
            for (var i = 0; i < points.Count; i++)
            {
                prev = curr;
                curr = next;
                next = points[i];
                bool concave;

                if (prev.X == curr.X)
                {
                    if (curr.X == next.X)
                    {
                        throw new InvalidOperationException("Should not happen as polygons must be normalized");
                    }

                    var dir0 = prev.Y < curr.Y;
                    var dir1 = curr.X > next.X;

                    concave = dir0 == dir1;
                }
                else
                {
                    if (next.Y == curr.Y)
                    {
                        throw new InvalidOperationException("Should not happen as polygons must be normalized");
                    }

                    var dir0 = prev.X < curr.X;
                    var dir1 = curr.Y > next.Y;

                    concave = dir0 != dir1;
                }

                var vertex = new Vertex(curr, i - 1, concave);
                vertices.Add(vertex);
            }

            // Build interval trees for segments
            var horizontalSegments = new List <Segment>();
            var verticalSegments   = new List <Segment>();

            for (var i = 0; i < vertices.Count; i++)
            {
                var from = vertices[i];
                var to   = vertices[(i + 1) % vertices.Count];

                if (from.Point.X == to.Point.X)
                {
                    verticalSegments.Add(new Segment(from, to, false));
                }
                else
                {
                    horizontalSegments.Add(new Segment(from, to, true));
                }

                from.Next = to;
                to.Prev   = from;
            }

            var horizontalTree = new RangeTree <int, Segment>(horizontalSegments, new SegmentComparer());
            var verticalTree   = new RangeTree <int, Segment>(verticalSegments, new SegmentComparer());

            //Find horizontal and vertical diagonals
            var horizontalDiagonals = GetDiagonals(vertices, verticalTree, false);
            var verticalDiagonals   = GetDiagonals(vertices, horizontalTree, true);

            //Find all splitting edges
            if (horizontalDiagonals.Count != 0)
            {
                var splitters = FindSplitters(horizontalDiagonals, verticalDiagonals);

                foreach (var splitter in splitters)
                {
                    SplitSegment(splitter);
                }
            }

            //Split all concave vertices
            SplitConvave(vertices);

            var rectangles = FindRegions(vertices);

            return(rectangles);
        }
예제 #5
0
 public Polygon2D(GridPolygon polygon)
 {
     points      = polygon.GetPoints().Select(x => (Vector2Int)x.ToUnityIntVector3()).ToList();
     gridPolygon = polygon;
 }
 public RoomDescription(GridPolygon shape, IDoorMode doorsMode)
 {
     Shape     = new GridPolygon(shape.GetPoints());
     DoorsMode = doorsMode;
 }