public void TestLongFrameListBoundsSharing() { var frames = new List <Frame>(); for (int i = 0; i < 100; i++) { var frame = FrameGenerator.GenerateRandomFrame(32, 32); frame.ID = i; frames.Add(frame); } var map = new DefaultTexturePacker.FrameBoundsMap(); foreach (var frame in frames) { map.RegisterFrames(new[] { frame }, new Rectangle(0, 0, 10, 10)); } var rand = new Random(); // Go around now sharing frames for (int i = 0; i < frames.Count; i++) { int lower = rand.Next(0, frames.Count); int upper = rand.Next(0, frames.Count); map.ShareSheetBoundsForFrames(frames[lower], frames[upper]); } // Go around now sharing frames map.ShareSheetBoundsForFrames(frames[0], frames[1]); map.ShareSheetBoundsForFrames(frames[10], frames[20]); map.ShareSheetBoundsForFrames(frames[30], frames[5]); }
public void TestFrameBoundsSharing() { var frame1 = FrameGenerator.GenerateRandomFrame(32, 32); frame1.ID = 1; var frame2 = FrameGenerator.GenerateRandomFrame(32, 32); frame2.ID = 2; var frame3 = FrameGenerator.GenerateRandomFrame(32, 32); frame3.ID = 3; var bounds1 = new Rectangle(0, 0, 32, 32); var bounds2 = new Rectangle(0, 0, 40, 40); var map = new DefaultTexturePacker.FrameBoundsMap(); map.RegisterFrames(new[] { frame1 }, bounds1); map.RegisterFrames(new[] { frame2 }, bounds2); map.RegisterFrames(new[] { frame3 }, bounds2); Assert.AreEqual(map.GetSheetBoundsForFrame(frame1), bounds1); Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), bounds2); map.ShareSheetBoundsForFrames(frame1, frame2); // frame2 now should point to the same bounds as frame1 Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), bounds1); // Test calling share again with already-shared frames is a noop map.ShareSheetBoundsForFrames(frame1, frame2); Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), bounds1); }
public void TestFrameBoundsSetForFrame() { var frame1 = FrameGenerator.GenerateRandomFrame(32, 32); frame1.ID = 1; var frame2 = FrameGenerator.GenerateRandomFrame(32, 32); frame2.ID = 2; var rectangle = new Rectangle(0, 0, 32, 32); var newBounds = new Rectangle(32, 0, 32, 32); var map = new DefaultTexturePacker.FrameBoundsMap(); map.RegisterFrames(new[] { frame1 }, rectangle); map.RegisterFrames(new[] { frame2 }, rectangle); // Direct set map.SetSheetBoundsForFrame(frame1, newBounds); Assert.AreEqual(map.GetSheetBoundsForFrame(frame1), newBounds); Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), rectangle); // Now share and set the bounds again map.ShareSheetBoundsForFrames(frame1, frame2); map.SetSheetBoundsForFrame(frame1, newBounds); Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), newBounds); }
public void TestSequentialFrameListBoundsSharing() { var frames = new List <Frame>(); for (int i = 0; i < 100; i++) { var frame = FrameGenerator.GenerateRandomFrame(32, 32); frame.ID = i; frames.Add(frame); } var map = new DefaultTexturePacker.FrameBoundsMap(); for (int i = 0; i < frames.Count; i++) { var frame = frames[i]; map.RegisterFrames(new[] { frame }, new Rectangle(0, 0, 10, 10 + i)); } var rand = new Random(); // Go around now sharing frames for (int i = 0; i < frames.Count - 1; i++) { map.ShareSheetBoundsForFrames(frames[i], frames[i + 1]); } // Test now frames are all the same var targetRect = new Rectangle(0, 0, 10, 10); foreach (var frame in frames) { Assert.AreEqual(map.GetSheetBoundsForFrame(frame), targetRect); } }
public void TestFrameClone() { Frame frame1 = FrameGenerator.GenerateRandomFrame(64, 63, 2); Frame frame2 = frame1.Clone(); Assert.AreEqual(frame1, frame2, "Frames cloned using .Clone() should be exactly equivalent"); }
public void TestFrameCopyFrom() { Animation anim = new Animation("TestAnimation", 16, 16); Frame frame1 = anim.CreateFrame(); Frame frame2 = FrameGenerator.GenerateRandomFrame(16, 16); frame1.CopyFrom(frame2); Assert.AreEqual(frame1, frame2, "After a successful call to CopyFrom(), the frames must return true to .Equals()"); }
public void TestLayerReinserting() { Frame frame1 = FrameGenerator.GenerateRandomFrame(64, 64, 10); Frame frame2 = frame1.Clone(); IFrameLayer layer = frame2.GetLayerAt(0); frame2.RemoveLayerAt(0, false); frame2.AddLayer(layer, 0); Assert.AreEqual(frame1, frame2, "After removing and readding a layer back to its original place, the frame structure must be considered unchanged"); }
public void TestLayerIndexing() { Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 5, 1); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 2)); IFrameLayer layer = frame.CreateLayer(); Assert.AreEqual(0, frame.GetLayerAt(0).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(1, frame.GetLayerAt(1).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, frame.GetLayerAt(2).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, layer.Index, "Layers returned by calls to AddLayer() and CreateLayer() must have an index that match the 'index' parameter passed"); }
public void TestFrameCompositing() { Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 5, 1); Bitmap target = frame.GetComposedBitmap(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0xB2, 0x91, 0xF2, 0xB1, 0x17, 0xF7, 0x17, 0x46, 0xA0, 0x1C, 0xA4, 0xCB, 0x45, 0x82, 0x17, 0xA4, 0x42, 0x60, 0x2F, 0xEE, 0x7E, 0x1A, 0xDC, 0xE3, 0x2F, 0xB, 0x89, 0xEC, 0x76, 0x6, 0x2C, 0xA1 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "FrameCompositing"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the composed frame does not match the good hash stored. Verify the output image for an analysis of what went wrong"); }
public void TestFrameSharing_LocalBoundsBug() { var frame1 = FrameGenerator.GenerateRandomFrame(32, 32); frame1.ID = 1; var frame2 = FrameGenerator.GenerateRandomFrame(32, 32); frame2.ID = 2; var frame3 = FrameGenerator.GenerateRandomFrame(32, 32); frame3.ID = 3; var bounds1 = new Rectangle(0, 0, 32, 32); var bounds2 = new Rectangle(0, 0, 20, 20); var bounds3 = new Rectangle(0, 0, 10, 10); var map = new DefaultTexturePacker.FrameBoundsMap(); map.RegisterFrames(new [] { frame1 }, bounds1); map.RegisterFrames(new[] { frame2 }, bounds2); map.RegisterFrames(new[] { frame3 }, bounds3); map.ShareSheetBoundsForFrames(frame1, frame2); Assert.AreEqual(map.GetSheetBoundsForFrame(frame3), bounds3); }
public void TestFrameLayerCreation() { // TODO: Find out why this test fails under Release mode but succeeds under Debug mode Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 1, 1); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 2)); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 3)); Bitmap target = frame.GetComposedBitmap(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0xBF, 0x8F, 0x9B, 0x56, 0xBE, 0x8D, 0xF5, 0xD2, 0x99, 0x1C, 0x9B, 0xEC, 0x56, 0xB8, 0x6D, 0xA9, 0x41, 0xBB, 0x31, 0x66, 0xD, 0xB2, 0xDC, 0x66, 0xF3, 0x5C, 0x9A, 0xDE, 0x59, 0xC2, 0xC2, 0x52 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "FrameLayering"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the composed frame does not match the good hash stored. Verify the output image for an analysis of what went wrong"); }
public void TestFrameRegistering() { var frame = FrameGenerator.GenerateRandomFrame(32, 32); frame.ID = 1; var bounds = new Rectangle(0, 10, 32, 32); var boundsZero = new Rectangle(0, 0, 32, 32); var map = new DefaultTexturePacker.FrameBoundsMap(); Assert.IsNull(map.GetLocalBoundsForFrame(frame)); Assert.IsFalse(map.ContainsFrame(frame)); map.RegisterFrames(new[] { frame }, bounds); Assert.IsNotNull(map.GetLocalBoundsForFrame(frame)); Assert.IsTrue(map.ContainsFrame(frame)); Assert.AreEqual(map.GetLocalBoundsForFrame(frame), bounds); Assert.AreEqual(map.GetSheetBoundsForFrame(frame), boundsZero, "When adding a frame sheet bounds via RegisterFrames(), the X and Y axis of the bounds rectangle must be ignored and set to 0."); }
public void TestFrameBoundsReplacing() { var frame1 = FrameGenerator.GenerateRandomFrame(32, 32); frame1.ID = 1; var frame2 = FrameGenerator.GenerateRandomFrame(32, 32); frame2.ID = 2; var bounds1 = new Rectangle(0, 0, 32, 32); var bounds2 = new Rectangle(32, 32, 40, 40); var map = new DefaultTexturePacker.FrameBoundsMap(); map.RegisterFrames(new[] { frame1 }, bounds1); map.RegisterFrames(new[] { frame2 }, bounds2); var replace1 = new Rectangle(10, 20, 30, 40); var replace2 = new Rectangle(100, 200, 300, 400); map.ReplaceSheetBounds(new [] { replace1, replace2 }); Assert.AreEqual(map.GetSheetBoundsForFrame(frame1), replace1); Assert.AreEqual(map.GetSheetBoundsForFrame(frame2), replace2); }