Beispiel #1
0
 public static IEnumerable <ITopoArray <Tile> > GetRotatedSamples(
     ITopoArray <Tile> sample,
     int rotationalSymmetry,
     bool reflectionalSymmetry,
     TileRotation tileRotation = null)
 {
     if (sample.Topology.Directions.Type == DirectionsType.Hexagonal2d)
     {
         var reflections = reflectionalSymmetry ? 2 : 1;
         for (var r = 0; r < reflections; r++)
         {
             for (var i = 0; i < 6; i += (6 / rotationalSymmetry))
             {
                 yield return(TopoArrayUtils.HexRotate(sample, i, r > 0, tileRotation));
             }
         }
     }
     else
     {
         var reflections = reflectionalSymmetry ? 2 : 1;
         for (var r = 0; r < reflections; r++)
         {
             for (var i = 0; i < 4; i += (4 / rotationalSymmetry))
             {
                 yield return(TopoArrayUtils.Rotate(sample, i, r > 0, tileRotation));
             }
         }
     }
 }
        public static IEnumerable<ITopoArray<Tile>> GetRotatedSamples(
            ITopoArray<Tile> sample,
            TileRotation tileRotation = null)
        {
            tileRotation = tileRotation ?? new TileRotation();

            foreach (var rotation in tileRotation.RotationGroup)
            {
                yield return TopoArrayUtils.Rotate(sample, rotation, tileRotation);
            }
        }
        public static IEnumerable <ITopoArray <Tile> > GetRotatedSamples(
            ITopoArray <Tile> sample,
            TileRotation tileRotation = null)
        {
            tileRotation = tileRotation ?? new TileRotation();

            foreach (var rotation in tileRotation.RotationGroup)
            {
                if (sample.Topology.Directions.Type == DirectionsType.Hexagonal2d)
                {
                    yield return(TopoArrayUtils.HexRotate(sample, rotation, tileRotation));
                }
                else
                {
                    yield return(TopoArrayUtils.Rotate(sample, rotation, tileRotation));
                }
            }
        }
        private static ITopoArray <V> GetSubTile <V>(Tile tile, IDictionary <Tile, ITopoArray <V> > subTiles)
        {
            if (subTiles.TryGetValue(tile, out var result))
            {
                return(result);
            }

            if (tile.Value is RotatedTile rt)
            {
                if (!subTiles.TryGetValue(rt.Tile, out var subTile))
                {
                    return(null);
                }
                result = TopoArrayUtils.Rotate(subTile, rt.Rotation);
                return(subTiles[tile] = result);
            }

            return(null);
        }
Beispiel #5
0
        public void TestRotate()
        {
            var a = new int[2, 2];

            a[0, 0] = 1; a[1, 0] = 2;
            a[0, 1] = 3; a[1, 1] = 4;

            var ta = TopoArray.Create(a, new Topology(2, 2, false));

            var r1 = TopoArrayUtils.Rotate(ta, new Rotation(3 * 90));

            Assert.AreEqual(2, r1.Get(0, 0)); Assert.AreEqual(4, r1.Get(1, 0));
            Assert.AreEqual(1, r1.Get(0, 1)); Assert.AreEqual(3, r1.Get(1, 1));

            var r3 = TopoArrayUtils.Rotate(ta, new Rotation(1 * 90));

            Assert.AreEqual(3, r3.Get(0, 0)); Assert.AreEqual(1, r3.Get(1, 0));
            Assert.AreEqual(4, r3.Get(0, 1)); Assert.AreEqual(2, r3.Get(1, 1));

            var refl = TopoArrayUtils.Rotate(ta, new Rotation(0 * 90, true));

            Assert.AreEqual(2, refl.Get(0, 0)); Assert.AreEqual(1, refl.Get(1, 0));
            Assert.AreEqual(4, refl.Get(0, 1)); Assert.AreEqual(3, refl.Get(1, 1));
        }
Beispiel #6
0
        private static IList <AdjacentModel.Adjacency> GetAutoAdjacencies <T>(
            IDictionary <Tile, ITopoArray <T> > subTiles,
            GridTopology subTileTopology,
            TileRotation tileRotations,
            Func <T, T, double> diff,
            double tolerance)
        {
            // Pre-process for rotations
            var allSubTiles = subTiles;

            if (subTileTopology.Width == subTileTopology.Height)
            {
                allSubTiles = new Dictionary <Tile, ITopoArray <T> >();
                foreach (var kv in subTiles)
                {
                    foreach (var rot in tileRotations.RotationGroup)
                    {
                        if (tileRotations.Rotate(kv.Key, rot, out var rt) && !allSubTiles.ContainsKey(rt))
                        {
                            allSubTiles[rt] = TopoArrayUtils.Rotate(kv.Value, rot);
                        }
                    }
                }
            }


            var output = new List <AdjacentModel.Adjacency>();

            // Left-right
            {
                var leftSlices  = allSubTiles.ToDictionary(x => x.Key, x => SliceX(x.Value, 0));
                var rightSlices = allSubTiles.ToDictionary(x => x.Key, x => SliceX(x.Value, subTileTopology.Width - 1));

                foreach (var kv1 in leftSlices)
                {
                    foreach (var kv2 in rightSlices)
                    {
                        if (DiffSlice(kv1.Value, kv2.Value, diff) <= tolerance)
                        {
                            output.Add(new AdjacentModel.Adjacency
                            {
                                Src       = new[] { kv2.Key },
                                Dest      = new[] { kv1.Key },
                                Direction = Direction.XPlus
                            });
                        }
                    }
                }
            }

            //
            {
                var upSlices   = allSubTiles.ToDictionary(x => x.Key, x => SliceY(x.Value, 0));
                var downSlices = allSubTiles.ToDictionary(x => x.Key, x => SliceY(x.Value, subTileTopology.Height - 1));

                foreach (var kv1 in upSlices)
                {
                    foreach (var kv2 in downSlices)
                    {
                        if (DiffSlice(kv1.Value, kv2.Value, diff) <= tolerance)
                        {
                            output.Add(new AdjacentModel.Adjacency
                            {
                                Src       = new[] { kv2.Key },
                                Dest      = new[] { kv1.Key },
                                Direction = Direction.YPlus
                            });
                        }
                    }
                }
            }

            //
            if (subTileTopology.Directions.Type == DirectionSetType.Cartesian3d)
            {
                var aboveSlices = allSubTiles.ToDictionary(x => x.Key, x => SliceZ(x.Value, 0));
                var belowSlices = allSubTiles.ToDictionary(x => x.Key, x => SliceZ(x.Value, subTileTopology.Depth - 1));

                foreach (var kv1 in aboveSlices)
                {
                    foreach (var kv2 in belowSlices)
                    {
                        if (DiffSlice(kv1.Value, kv2.Value, diff) <= tolerance)
                        {
                            output.Add(new AdjacentModel.Adjacency
                            {
                                Src       = new[] { kv2.Key },
                                Dest      = new[] { kv1.Key },
                                Direction = Direction.ZPlus
                            });
                        }
                    }
                }
            }

            return(output);
        }