示例#1
0
        /// <summary>
        /// Expands each plate one pixel in every direction until no point outside of all plates exists.
        /// </summary>
        private void ExpandPlates()
        {
            Queue <OverlapPoint> borderPoints = new Queue <OverlapPoint>();

            for (int i = 0; i < Plates.Length; i++)
            {
                for (int j = 0; j < Plates[i].PlatePoints.Count; j++)
                {
                    SimplePoint[] newPoints = new SimplePoint[4];
                    Plates[i].PlatePoints[j].FindLeftRightPoints(out newPoints[0], out newPoints[1]);
                    Plates[i].PlatePoints[j].FindAboveBelowPoints(out newPoints[2], out newPoints[3]);
                    for (int k = 0; k < 4; k++)
                    {
                        if (!ActivePoints[newPoints[k].X, newPoints[k].Y])
                        {
                            borderPoints.Enqueue(new OverlapPoint(newPoints[k], i));
                        }
                    }
                }
            }
            while (borderPoints.Count != 0)
            {
                OverlapPoint borderPoint = borderPoints.Dequeue();
                if (!ActivePoints[borderPoint.X, borderPoint.Y])
                {
                    ActivePoints[borderPoint.X, borderPoint.Y] = true;
                    SimplePoint oldPoint = new SimplePoint(borderPoint.X, borderPoint.Y);
                    Plates[borderPoint.plateIndex[0]].PlatePoints.Add(new PlatePoint(oldPoint));
                    SimplePoint[] newPointsP = new SimplePoint[4];
                    oldPoint.FindLeftRightPoints(out newPointsP[0], out newPointsP[1]);
                    oldPoint.FindAboveBelowPoints(out newPointsP[2], out newPointsP[3]);
                    for (int k = 0; k < 4; k++)
                    {
                        if (!ActivePoints[newPointsP[k].X, newPointsP[k].Y])
                        {
                            OverlapPoint newPoint = new OverlapPoint(newPointsP[k], borderPoint.plateIndex[0]);
                            borderPoints.Enqueue(newPoint);
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Scans for all points in <see cref="ActivePoints"/> that are set to true and are
        /// contiguously adjacent to the given point and adds them to <see cref="temporaryPlate"/>,
        /// setting the <see cref="ActivePoints"/> to false in the process.
        /// </summary>
        /// <param name="startingPoint">Starting point to check neighbors.</param>
        private void CheckNeighbor(SimplePoint startingPoint)
        {
            Stack <SimplePoint> pointStack = new Stack <SimplePoint>();

            ActivePoints[startingPoint.X, startingPoint.Y] = false;
            pointStack.Push(startingPoint);
            while (pointStack.Count != 0)
            {
                SimplePoint point = pointStack.Pop();
                temporaryPlate.PlatePoints.Add(new PlatePoint(point));
                SimplePoint[] newPoints = new SimplePoint[4];
                point.FindLeftRightPoints(out newPoints[0], out newPoints[1]);
                point.FindAboveBelowPoints(out newPoints[2], out newPoints[3]);
                for (int i = 0; i < 4; i++)
                {
                    if (ActivePoints[newPoints[i].X, newPoints[i].Y])
                    {
                        ActivePoints[newPoints[i].X, newPoints[i].Y] = false;
                        pointStack.Push(newPoints[i]);
                    }
                }
            }
        }
 /// <summary>
 /// Determines the points left and right of this point, including wrap-arounds.
 /// </summary>
 /// <param name="leftPoint">The point to the left of this point.</param>
 /// <param name="rightPoint">The point to the right of this point.</param>
 public void FindLeftRightPoints(out SimplePoint leftPoint, out SimplePoint rightPoint)
 {
     _position.FindLeftRightPoints(out leftPoint, out rightPoint);
 }