internal IEnumerable <ModelTile> GetModelTiles(IEnumerable <TesseraTile> tiles)
        {
            var rg = new RotationGroup(4, true);

            foreach (var tile in tiles)
            {
                if (tile == null)
                {
                    continue;
                }

                foreach (var rot in rg)
                {
                    if (!tile.rotatable && rot.RotateCw != 0)
                    {
                        continue;
                    }
                    if (!tile.reflectable && rot.ReflectX)
                    {
                        continue;
                    }

                    foreach (var offset in tile.offsets)
                    {
                        var modelTile = new ModelTile(tile, rot, offset);
                        yield return(modelTile);
                    }
                }
            }
        }
Example #2
0
 private RotationGroup Clone(RotationGroup rg)
 {
     return(new RotationGroup
     {
         Entries = rg.Entries.ToList(),
         Tiles = rg.Tiles.ToDictionary(x => x.Key, x => x.Value),
         Treatment = rg.Treatment,
         TreatmentSetBy = rg.TreatmentSetBy,
     });
 }
Example #3
0
        // Gets the rotation group containing Tile, creating it if it doesn't exist
        private void GetGroup(Tile tile, out RotationGroup rg)
        {
            if (tileToRotationGroup.TryGetValue(tile, out rg))
            {
                return;
            }

            rg = new RotationGroup();
            rg.Tiles[new Transform()] = tile;
            tileToRotationGroup[tile] = rg;
        }
Example #4
0
 private bool Set(RotationGroup rg, Transform tf, Tile tile, string action)
 {
     if (rg.Tiles.TryGetValue(tf, out var current))
     {
         if (current != tile)
         {
             throw new Exception($"Cannot {action}: conflict between {current} and {tile}");
         }
         return(false);
     }
     rg.Tiles[tf] = tile;
     return(true);
 }
Example #5
0
        // Ensures that rg.Tiles is fully filled in
        // according to rg.Entries.
        private void Expand(RotationGroup rg)
        {
            bool expanded;

            do
            {
                expanded = false;
                foreach (var entry in rg.Entries)
                {
                    foreach (var kv in rg.Tiles.ToList())
                    {
                        if (kv.Value == entry.Src)
                        {
                            expanded = expanded || Set(rg, tg.Mul(kv.Key, entry.Tf), entry.Dest, "resolve conflicting rotations");
                        }
                        if (kv.Value == entry.Dest)
                        {
                            expanded = expanded || Set(rg, tg.Mul(kv.Key, tg.Inverse(entry.Tf)), entry.Src, "resolve conflicting rotations");
                        }
                    }
                }
            } while (expanded);
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create AdRemoteService instance.
            AdRemoteService service = (AdRemoteService)user.GetService(
                DfaService.v1_20.AdRemoteService);

            long   campaignId  = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE"));
            long   sizeId      = long.Parse(_T("INSERT_SIZE_ID_HERE"));
            long   creativeId  = long.Parse(_T("INSERT_CREATIVE_ID_HERE"));
            long   placementId = long.Parse(_T("INSERT_PLACEMENT_ID_HERE"));
            String adName      = _T("INSERT_AD_NAME_HERE");
            long   typeId      = long.Parse(_T("INSERT_AD_TYPEID_HERE"));

            // Create rotation group structure.
            RotationGroup rotationGroup = new RotationGroup();

            rotationGroup.id         = 0;
            rotationGroup.name       = adName;
            rotationGroup.active     = true;
            rotationGroup.archived   = false;
            rotationGroup.campaignId = campaignId;
            rotationGroup.sizeId     = sizeId;
            rotationGroup.typeId     = typeId;
            rotationGroup.priority   = 12;
            rotationGroup.ratio      = 1;

            // Set ad start and end dates.
            rotationGroup.startTime = DateTime.Today.AddDays(1);
            rotationGroup.endTime   = DateTime.Today.AddMonths(1);

            // Add creatives to the ad.
            CreativeAssignment creativeAssignment = new CreativeAssignment();

            creativeAssignment.active     = true;
            creativeAssignment.creativeId = creativeId;

            // Create click through url.
            ClickThroughUrl clickThroughUrl = new ClickThroughUrl();

            clickThroughUrl.defaultLandingPageUsed = true;
            clickThroughUrl.landingPageId          = 0;
            creativeAssignment.clickThroughUrl     = clickThroughUrl;

            // Create creative assigments.
            rotationGroup.creativeAssignments = new CreativeAssignment[] { creativeAssignment };
            rotationGroup.rotationType        = 1;

            // Assign ad to placement.
            PlacementAssignment placementAssignment = new PlacementAssignment();

            placementAssignment.active         = true;
            placementAssignment.placementId    = placementId;
            rotationGroup.placementAssignments = new PlacementAssignment[] { placementAssignment };

            try {
                // Create rotation group.
                AdSaveResult result = service.saveAd(rotationGroup);

                // Display new ad id.
                Console.WriteLine("Ad with id \"{0}\" was created.", result.id);
            } catch (Exception ex) {
                Console.WriteLine("Failed to create rotation group. Exception says \"{0}\"", ex.Message);
            }
        }
Example #7
0
        // Fills all remaining slots with RotatedTile
        // Care is taken that as few distinct RotatedTiles are used as possible
        // If there's two possible choices, prefernce is given to rotations over reflections.
        private void Generate(RotationGroup rg)
        {
start:
            for (var refl = 0; refl < 2; refl++)
            {
                for (var rot = 0; rot < tg.RotationalSymmetry; rot++)
                {
                    var transform = new Transform {
                        ReflectX = refl > 0, RotateCw = rot
                    };
                    if (rg.Tiles.ContainsKey(transform))
                    {
                        continue;
                    }

                    // Found an empty spot, figure out what to rotate from
                    for (var refl2 = 0; refl2 < 2; refl2++)
                    {
                        for (var rot2 = 0; rot2 < tg.RotationalSymmetry; rot2++)
                        {
                            var transform2 = new Transform {
                                ReflectX = (refl2 > 0) != (refl > 0), RotateCw = rot2
                            };
                            if (!rg.Tiles.TryGetValue(transform2, out var srcTile))
                            {
                                continue;
                            }

                            // Don't allow RotatedTiles to nest.
                            if (srcTile.Value is RotatedTile rt)
                            {
                                srcTile = rt.Tile;
                                var rtTransform = new Transform {
                                    RotateCw = rt.RotateCw, ReflectX = rt.ReflectX
                                };
                                transform2 = tg.Mul(tg.Inverse(rtTransform), transform2);
                            }

                            var srcToDest = tg.Mul(tg.Inverse(transform2), transform);

                            Tile destTile;
                            if (srcToDest.ReflectX == false && srcToDest.RotateCw == 0)
                            {
                                destTile = srcTile;
                            }
                            else
                            {
                                destTile = new Tile(new RotatedTile
                                {
                                    Tile     = srcTile,
                                    ReflectX = srcToDest.ReflectX,
                                    RotateCw = srcToDest.RotateCw,
                                });
                            }

                            // Found where we want to rotate from
                            rg.Entries.Add(new Entry
                            {
                                Src  = srcTile,
                                Tf   = srcToDest,
                                Dest = destTile,
                            });
                            Expand(rg);
                            goto start;
                        }
                    }
                }
            }
        }
Example #8
0
 public static IList <AdjacentModel.Adjacency> Rotate(IList <AdjacentModel.Adjacency> adjacencies, RotationGroup rg, DirectionSet directions, TileRotation tileRotation)
 {
     return(rg.SelectMany(r => Rotate(adjacencies, r, directions, tileRotation)).ToList());
 }