コード例 #1
0
ファイル: OverlappingModel.cs プロジェクト: toyboot4e/wfc.cs
        /// <summary>Used to create cache for the overlapping model</summary>
        public static bool testCompatibility(int from, Dir4 dir, int to, PatternStorage patterns, Map source)
        {
            int N           = patterns.N; // patterns have size of NxN
            var fromPattern = patterns[from];
            var toPattern   = patterns[to];

            // TODO: use row/col vector for performance
            for (int row = 0; row < N - 1; row++)
            {
                for (int col = 0; col < N; col++)
                {
                    // Now, consider a concrete situation: `from` is down and `to` is up (direction = North)
                    // get local positions in each pattern
                    var downLocal = new Vec2i(col, row);
                    var upLocal   = new Vec2i(col, row + 1);
                    // apply the direction
                    downLocal = dir.applyAsRotation(downLocal, N);
                    upLocal   = dir.applyAsRotation(upLocal, N);
                    // convert them (local positions) into global positions (position in the source)
                    var downGlobal = fromPattern.localPosToSourcePos(downLocal, N);
                    var upGlobal   = toPattern.localPosToSourcePos(upLocal, N);
                    // test the equaility
                    if (source[downGlobal.x, downGlobal.y] != source[upGlobal.x, upGlobal.y])
                    {
                        return(false);
                    }
                }
            }

            // if all of the tiles are same, that's a compatible combination
            return(true);
        }
コード例 #2
0
ファイル: AdjacencyModel.cs プロジェクト: toyboot4e/wfc.cs
        /// <summary>Used to create cache for the overlapping model</summary>
        public static bool testCompatibility(int from, Dir4 dir, int to, PatternStorage patterns, Map source)
        {
            int N           = patterns.N; // patterns have size of NxN
            var fromPattern = patterns[from];
            var toPattern   = patterns[to];
            // TODO: use row/col vector for performance

            int  row         = 0;
            bool anyExitDown = false;
            bool anyExitUp   = false;

            for (int col = 0; col < N; col++)
            {
                // Now, consider a concrete situation: `from` is down and `to` is up (direction = North)
                // get local positions in each pattern
                var downLocal = new Vec2i(col, row);
                var upLocal   = new Vec2i(col, row + 1);
                // apply the direction
                downLocal = dir.applyAsRotation(downLocal, N);
                upLocal   = dir.applyAsRotation(upLocal, N);
                // convert them (local positions) into global positions (position in the source)
                var downGlobal = fromPattern.localPosToSourcePos(downLocal, N);
                var upGlobal   = toPattern.localPosToSourcePos(upLocal, N);
                // check compatibilities
                bool down = source[downGlobal.x, downGlobal.y] == Tile.Floor;
                bool up   = source[downGlobal.x, downGlobal.y] == Tile.Floor;

                if (down && up)
                {
                    return(true);
                }
                anyExitDown &= down;
                anyExitUp   &= up;
            }

            // if one of them has no exits, we enable the pattern
            return(!anyExitDown && !anyExitUp);
        }