Exemplo n.º 1
0
        private void SetupAdjacencies(TileModel model, TileRotation tileRotation, IList <AdjacentModel.Adjacency> adjacencies)
        {
            if (Config.PadTile != null)
            {
                adjacencies = AdjacencyUtils.ForcePadding(adjacencies, Parse(Config.PadTile));
            }

            if (adjacencies.Count > 0)
            {
                var adjacentModel = model as AdjacentModel;
                if (adjacentModel == null)
                {
                    throw new ConfigurationException("Setting adjacencies is only supported for the \"adjacent\" model.");
                }
                foreach (var a in adjacencies)
                {
                    adjacentModel.AddAdjacency(a);
                }

                // If there are no samples, set frequency to 1 for everything mentioned in this block
                foreach (var tile in adjacentModel.Tiles.ToList())
                {
                    adjacentModel.SetFrequency(tile, 1, tileRotation);
                }
            }
        }
Exemplo n.º 2
0
        public TileModel GetModel(DirectionSet directions, SampleSet sampleSet, TileRotation tileRotation)
        {
            var       samples     = sampleSet.Samples;
            var       modelConfig = Config.Model ?? new Adjacent();
            TileModel tileModel;

            if (modelConfig is Overlapping overlapping)
            {
                var model = new OverlappingModel(overlapping.NX, overlapping.NY, overlapping.NZ);
                foreach (var sample in samples)
                {
                    model.AddSample(sample, tileRotation);
                }
                tileModel = model;
            }
            else if (modelConfig is Adjacent adjacent)
            {
                var model = new AdjacentModel(directions);
                foreach (var sample in samples)
                {
                    model.AddSample(sample, tileRotation);
                }
                tileModel = model;
            }
            else
            {
                throw new ConfigurationException($"Unrecognized model type {modelConfig.GetType()}");
            }

            var autoAdjacencies = Config.AutoAdjacency
                ? AdjacencyUtils.GetAutoAdjacencies(sampleSet, tileRotation, Config.AutoAdjacencyTolerance)
                : new AdjacentModel.Adjacency[0];
            var manualAdjacencies = GetManualAdjacencies(sampleSet.Directions, tileRotation);

            SetupAdjacencies(tileModel, tileRotation, autoAdjacencies.Concat(manualAdjacencies).ToList());
            SetupTiles(tileModel, tileRotation);

            return(tileModel);
        }
Exemplo n.º 3
0
        private IList <AdjacentModel.Adjacency> GetManualAdjacencies(DirectionSet directions, TileRotation tileRotation)
        {
            if (Config.Adjacencies == null)
            {
                return(new AdjacentModel.Adjacency[0]);
            }

            AdjacentModel.Adjacency Convert(AdjacencyData a)
            {
                return(new AdjacentModel.Adjacency
                {
                    Src = a.Src.Select(Parse).Select(tileRotation.Canonicalize).ToArray(),
                    Dest = a.Dest.Select(Parse).Select(tileRotation.Canonicalize).ToArray(),
                    Direction = a.Direction,
                });
            }

            return(AdjacencyUtils.Rotate(
                       Config.Adjacencies.Select(Convert).ToList(),
                       tileRotation.RotationGroup,
                       directions,
                       tileRotation));
        }