/// <summary>Creates an <c>AdjacencyRule</c> for the adjacency model</summary> public static RuleData buildRule(PatternStorage patterns, ref Map source) { var rule = new RuleData(); int nPatterns = patterns.len; rule.nPatterns = nPatterns; { // do not count symmetric combinations int nCombinations = (nPatterns + 1) * (nPatterns) / 2; rule.cache = new Grid2D <bool>(4, nCombinations); } for (int from = 0; from < nPatterns; from++) { for (int to = from; to < nPatterns; to++) { for (int d = 0; d < 4; d++) { var dir = (Dir4)d; bool canBeAdjacenct = AdjacencyModel.testCompatibility(from, dir, to, patterns, source); rule.cache.add(canBeAdjacenct); } } } return(rule); }
public static WfcAdjacency create(ref Map source, int N, Vec2i outputSize) { if (N < 2) { throw new System.ArgumentException($"given N = {N}; it must be bigger than one"); } var model = AdjacencyModel.create(ref source, N, outputSize); var gridSize = outputSize / N; var state = new State(gridSize.x, gridSize.y, model.patterns, ref model.rule); return(new WfcAdjacency(model, state, N)); }
/// <summary>`source` size must be dividable by `N`</summary> public static Model create(ref Map source, int N, Vec2i outputSize) { if (outputSize.x % N != 0 || outputSize.y % N != 0) { throw new System.Exception($"output size {outputSize} must be dividable with N={N}"); } var gridSize = outputSize / N; var patterns = RuleData.extractEveryChunk(ref source, N, PatternUtil.variations); var rule = AdjacencyModel.buildRule(patterns, ref source); return(new Model(gridSize, patterns, rule)); }