Example #1
0
    public static void DrawPotentialDoors(this Container2D <GenSpace> arr, StrokedAction <GenSpace> action)
    {
        DrawAction <GenSpace>    check     = Draw.CanDrawDoor();
        StrokedAction <GenSpace> findDoors = new StrokedAction <GenSpace>();

        if (action.StrokeAction != null)
        {
            findDoors.StrokeAction = (arr2, x, y) =>
            {
                if (check(arr2, x, y))
                {
                    action.StrokeAction(arr2, x, y);
                }
                return(true);
            };
        }
        if (action.UnitAction != null)
        {
            findDoors.UnitAction = (arr2, x, y) =>
            {
                if (check(arr2, x, y))
                {
                    action.UnitAction(arr2, x, y);
                }
                return(true);
            };
        }

        arr.DrawPerimeter(Draw.Not(Draw.IsType <GenSpace>(GridType.NULL)), findDoors);
    }
Example #2
0
 public StrokedAction <T> Then(StrokedAction <T> rhs)
 {
     if (rhs == null)
     {
         return(rhs);
     }
     return(new StrokedAction <T>()
     {
         UnitAction = ((DrawAction <T>)UnitAction).And(rhs.UnitAction),
         StrokeAction = ((DrawAction <T>)StrokeAction).And(rhs.StrokeAction)
     });
 }
Example #3
0
 public SquareFinder(Container2D <T> arr, int width, int height, bool tryFlipped, StrokedAction <T> tester, Bounding scope = null)
 {
     _arr        = arr;
     _width      = width;
     _height     = height;
     _tryFlipped = tryFlipped && width != height;
     _tester     = tester;
     _scope      = scope;
     if (scope == null)
     {
         _scope = arr.Bounding;
     }
 }
Example #4
0
    public List <Bounding> Find()
    {
        List <Bounding> ret = new List <Bounding>();

        if (_width >= _arr.Width || _height >= _arr.Height)
        {
            return(ret);
        }

        if (_width == 1 && _height == 1)
        {
            return(SingleFind());
        }

        // Initialize
        _x              = _scope.XMin;
        _y              = _scope.YMin;
        _lastPassedX    = int.MaxValue;
        _lastTestedX    = _scope.XMin;
        _lastTestedY    = _scope.YMin;
        xShift          = _arr.Bounding.XMin;
        _lastPassedXArr = new bool[_arr.Width];

        if (_tester.StrokeAction == null && _width > 3 && _height > 3)
        { // Just unit
            FindSkip(ret);
        }
        else if (_tester.StrokeAction != null && _tester.UnitAction != null && _width > 5 && _height > 5)
        { // Unit and stroke with optimization
            // Find non-stroke options, then test stroke
            DrawAction <T> stroke = _tester.StrokeAction;
            _tester.StrokeAction = null;
            _width  -= 2;
            _height -= 2;
            FindSkip(ret);
            _width  += 2;
            _height += 2;
            _tester.StrokeAction = stroke;
            List <Bounding> retTmp = new List <Bounding>(ret);
            ret.Clear();
            StrokedAction <T> strokeTest = new StrokedAction <T>()
            {
                StrokeAction = _tester.StrokeAction
            };
            foreach (Bounding b in retTmp)
            {
                b.Expand(1);
                if (_arr.DrawRect(b.XMin, b.XMax, b.YMin, b.YMax, strokeTest))
                {
                    ret.Add(b);
                }
            }
        }
        else
        {
            FindNormal(ret);
        }

        if (_tryFlipped && ret.Count == 0)
        { // Flip and try again
            _tryFlipped = false;
            int tmp = _width;
            _width  = _height;
            _height = tmp;
            return(Find());
        }
        return(ret);
    }