Ejemplo n.º 1
0
        public void ClonesCorrectly()
        {
            var packed = Packed.Create(new byte[] { 0x10, 0x01, 0x02, 0xF3 });
            var cloned = packed.Clone();

            Assert.IsTrue(packed.GetBytes().SequenceEqual(cloned.GetBytes()));
        }
Ejemplo n.º 2
0
 public void readIt(Packed packed)
 {
     for (int i = 0; i < packed.vs.count; ++i)
     {
         dictionary_ [packed.vs.getData(i).position + packed.offset] = packed.vs.getData(i);
     }
 }
Ejemplo n.º 3
0
 protected override byte[] GetExtensionData()
 {
     return(Label.GetBytes().Concatenate(BlockSize.GetBytes(),
                                         Packed.Print(),
                                         DelayTime.GetBytes(),
                                         ColorIndex.GetBytes()));
 }
Ejemplo n.º 4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Kind != global::Google.Protobuf.WellKnownTypes.Field.Types.Kind.TYPE_UNKNOWN)
            {
                hash ^= Kind.GetHashCode();
            }
            if (Cardinality != global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.CARDINALITY_UNKNOWN)
            {
                hash ^= Cardinality.GetHashCode();
            }
            if (Number != 0)
            {
                hash ^= Number.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (TypeUrl.Length != 0)
            {
                hash ^= TypeUrl.GetHashCode();
            }
            if (OneofIndex != 0)
            {
                hash ^= OneofIndex.GetHashCode();
            }
            if (Packed != false)
            {
                hash ^= Packed.GetHashCode();
            }
            hash ^= options_.GetHashCode();
            return(hash);
        }
Ejemplo n.º 5
0
        public ActionResult UnpackedList(string item)
        {
            Packed        newUnPacked = new Packed(item);
            List <Packed> allItems    = Packed.GetAll();

            return(View("UnpackedList", allItems));
        }
Ejemplo n.º 6
0
            public static Packed <T> Some(T value)
            {
                var packed = new Packed <T> (value);

                UnderlyingSwiftType.StoreTag(&packed, Tag.Some);
                return(packed);
            }
Ejemplo n.º 7
0
		public void addVoxel(VoxelStruct vs, VectorInt3 offset){
//			Debug.Log (offset.x +","+ offset.y+","+ offset.z);
			Packed packed = new Packed ();
			packed.vs = vs;
			packed.offset = offset;
			list_.Add (packed);
		}
            public void GetSameBitsAsWerePutIn()
            {
                var packed = Packed.Create(new[] { true, false, true, false });

                Assert.IsTrue(packed.GetBit(1));
                Assert.IsTrue(packed.GetBit(3));
            }
            public void CanGetBits()
            {
                var packed = new Packed(new [] { 1, 1L << 63 });

                Assert.IsTrue(packed.GetBit(0));
                Assert.IsTrue(packed.GetBit(64 + 63));
            }
Ejemplo n.º 10
0
 public void readIt(Packed packed)
 {
     for (int i = 0; i < packed.vs.datas.Count; ++i)
     {
         dictionary_ [packed.vs.datas [i].pos + packed.offset] = packed.vs.datas [i];
     }
 }
Ejemplo n.º 11
0
        public ActionResult PackedForm(string item)
        {
            Packed        newPacked = new Packed(item);
            List <Packed> allItems  = Packed.GetAll();

            return(View("PackList", allItems));
        }
Ejemplo n.º 12
0
        public void PacksBitsCorrectly()
        {
            var packed = Packed.Create(new[] { true, false, true });

            Assert.AreEqual(1, packed.PackedBytes.Count);
            Assert.AreEqual(5, packed.PackedBytes[0]);
        }
Ejemplo n.º 13
0
        public void CanGetBackSameBytes()
        {
            var bytes    = new byte[] { 0x01, 0x02, 0xF3, 0xE4 };
            var packed   = Packed.Create(bytes);
            var newBytes = packed.GetBytes().Take(4);

            Assert.IsTrue(newBytes.SequenceEqual(bytes));
        }
Ejemplo n.º 14
0
		public void readIt(Packed packed){
			for (int i = 0; i < packed.vs.datas.Count; ++i) {
				dictionary_ [packed.vs.datas [i].pos +packed.offset ] = packed.vs.datas [i];

			}


		}
            public void IsSameEndiannessAsGetBytes()
            {
                var packed = new Packed(new [] { 1, 1L << 63 });
                var bytes  = packed.GetBytes().ToList();

                Assert.AreEqual(1, bytes[0]);
                Assert.AreEqual(0x80, bytes[15]);
            }
Ejemplo n.º 16
0
        public void addVoxel(VoxelStruct vs, VectorInt3 offset)
        {
            Packed packed = new Packed();

            packed.vs     = vs;
            packed.offset = offset;
            list_.Add(packed);
        }
Ejemplo n.º 17
0
        public void XorsCorrectly()
        {
            var packed1 = Packed.Create(new byte[] { 0x00, 0x01, 0x02, 0x03 });
            var packed2 = Packed.Create(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });

            packed1.Xor(packed2);
            Assert.IsTrue(packed1.GetBytes().SequenceEqual(new byte[] { 0xFF, 0xFE, 0xFD, 0xFC }.Concat(Enumerable.Repeat(default(byte), 4))));
        }
Ejemplo n.º 18
0
        public void TestPacked()
        {
            var obj = new Packed {
                B = 0xbb, I1 = 1, I2 = 2, L1 = 3, L2 = 4
            };

            Assert.AreEqual(Packed.DebuggerSize, obj.GetExclusiveSize());
        }
 /// <summary>
 /// Creates a new <see cref="Slice"/> from the given <paramref name="coefficients"/> and
 /// <paramref name="data"/>.
 /// </summary>
 public static Slice Create(
     IReadOnlyCollection <bool> coefficients,
     IReadOnlyCollection <byte> data) =>
 new Slice(
     numCoefficients: coefficients.Count,
     numData: data.Count,
     packedCoefficients: Packed.Create(coefficients.ToBytes()),
     packedData: Packed.Create(data)
     );
Ejemplo n.º 20
0
        /// <summary>
        /// Returns the bit at the given <paramref name="index"/>.
        /// </summary>
        public static bool GetBit(
            this Packed packed,
            int index)
        {
            const int numBitsInLong = 64;

            var l = packed.PackedBytes[index / numBitsInLong];

            return(((l >> index % numBitsInLong) & 1) != 0);
        }
Ejemplo n.º 21
0
    public string ToJson()
    {
        var packed = new Packed();

        packed.X     = this.transform.position.x.Truncate(2);
        packed.Y     = this.transform.position.y.Truncate(2);
        packed.Shape = this.Shape;
        packed.Color = this.Color;

        return(JsonUtility.ToJson(packed));
    }
 private Slice(
     int numCoefficients,
     int numData,
     Packed packedCoefficients,
     Packed packedData)
 {
     _numCoefficients    = numCoefficients;
     _numData            = numData;
     _packedCoefficients = packedCoefficients;
     PackedData          = packedData;
 }
Ejemplo n.º 23
0
        public void CanGetBackPackedBytes()
        {
            var packed = new Packed(new long[] { 1, 2, 3 });
            var bytes  = packed.GetBytes();

            Assert.IsTrue(bytes.SequenceEqual(new byte[]
            {
                1, 0, 0, 0, 0, 0, 0, 0,
                2, 0, 0, 0, 0, 0, 0, 0,
                3, 0, 0, 0, 0, 0, 0, 0
            }));
        }
Ejemplo n.º 24
0
        public VoxelStruct doIt()
        {
            this.clear();
            for (int i = 0; i < list_.Count; ++i)
            {
                Packed p = this.list_ [i];
                this.readIt(p);
            }
            VoxelStruct vs = new VoxelStruct();

            vs.datas = this.getDatas();
            return(vs);
        }
            public void DoesNotSolveUnsolvableSystem()
            {
                var coefficients = new List <Packed>
                {
                    Packed.Create(new[] { true, false, false })
                };
                var solution = GaussianEliminationHelpers.Solve(coefficients, 3).ToList();

                if (solution.Count > 0)
                {
                    Assert.IsTrue(solution[solution.Count].Operation != Operation.Complete);
                }
            }
Ejemplo n.º 26
0
    static void Main(string[] args)
    {
        Packed p = Packed.Info1 | Packed.Info3;

        if ((p & Packed.Info2) != 0)
        {
            //if (p.HasFlag(Packed.Info2))
            Console.WriteLine("Info2があります");
        }
        else
        {
            Console.WriteLine("Info2がありません");
        }
    }
            public void SolvesComplicatedSystem()
            {
                var coefficients = new List <Packed>
                {
                    Packed.Create(new[] { true, false, true }),
                    Packed.Create(new[] { true, true, true }),
                    Packed.Create(new[] { false, false, true })
                };
                var steps = GaussianEliminationHelpers.Solve(coefficients, 3).ToList();

                Assert.IsTrue(steps.Count > 0);
                Assert.AreEqual(Operation.Complete, steps[steps.Count - 1].Operation);
                AssertIsSolved(coefficients, 3);
            }
Ejemplo n.º 28
0
        public VoxelStruct doIt()
        {
            this.clear();
            for (int i = 0; i < list_.Count; ++i)
            {
                Packed p = this.list_ [i];
//				Debug.Log ("p vs data is" + p.vs.datas.Count);
//				Debug.Break ();
                this.readIt(p);
            }
            VoxelStruct vs = new VoxelStruct();

            vs.datas = this.getDatas();
            return(vs);
        }
            public void ProducesStepsWhichResultInIdenticalChangesAndASolution()
            {
                var coefficients = new List <Packed>
                {
                    Packed.Create(new [] { true, true, true }),
                    Packed.Create(new [] { false, true, true }),
                    Packed.Create(new [] { false, true, false })
                };
                var copy = coefficients.Select(x => x.Clone()).ToList();

                var steps = GaussianEliminationHelpers.Solve(coefficients, 3).ToList();

                // Assert that it has been solved
                Assert.IsTrue(steps.Count > 0);
                Assert.AreEqual(Operation.Complete, steps[steps.Count - 1].Operation);
                AssertIsSolved(coefficients, 3);

                // Perform the steps on the copy
                var mappedOperations = new Dictionary <Operation, Action <int, int, IList <Packed> > >
                {
                    {
                        Operation.Swap,
                        (from, to, list) =>
                        {
                            var temp = list[to];
                            list[to]   = list[from];
                            list[from] = temp;
                        }
                    },
                    {
                        Operation.Xor,
                        (from, to, list) => list[to].Xor(list[from])
                    }
                };

                foreach (var step in steps)
                {
                    if (!mappedOperations.TryGetValue(step.Operation, out var operation))
                    {
                        continue;
                    }
                    operation.Invoke(step.From, step.To, copy);
                }

                // Assert that the copy has been solved
                AssertIsSolved(copy, 3);
            }
            public void GetSameBitsAsBytes()
            {
                var packed = Packed.Create(new byte[] { 0x55, 0xFF });
                var bits   =
                    Enumerable.Range(
                        0,
                        16)
                    .Select(x => packed.GetBit(x))
                    .ToList();
                var expectedSequence = new[]
                {
                    true, false, true, false, true, false, true, false,
                    true, true, true, true, true, true, true, true,
                };

                Assert.IsTrue(expectedSequence.SequenceEqual(bits));
            }
Ejemplo n.º 31
0
 protected virtual void OnPacked(PackingSummary summary)
 {
     Packed?.Invoke(summary);
 }
Ejemplo n.º 32
0
        public Atlas Build(int pad)
        {
            var packer = new RectanglePacker(maxSize, maxSize, packCount);

            //This ID is used to keep the rectangles ordered (we need to unpack in the same order we packed)
            int nextID = 0;

            //Add all the bitmaps (padding them)
            foreach (var pair in bitmaps)
            {
                RectangleI rect;
                if (!trims.TryGetValue(pair.Value, out rect))
                {
                    rect = new RectangleI(pair.Value.Width, pair.Value.Height);
                }
                packer.Add(++nextID, rect.W + pad, rect.H + pad, true);
            }

            //Add all the font characters (padding them)
            foreach (var pair in fonts)
            {
                FontChar chr;
                for (int i = 0; i < pair.Value.CharCount; ++i)
                {
                    pair.Value.GetCharInfoAt(i, out chr);
                    if (!pair.Value.IsEmpty(chr.Char))
                    {
                        packer.Add(++nextID, chr.Width + pad, chr.Height + pad, true);
                    }
                }
            }

            //Add all the tiles (padding them)
            foreach (var pair in tiles)
            {
                var        tileset = pair.Value;
                RectangleI rect;
                for (int y = 0; y < tileset.Rows; ++y)
                {
                    for (int x = 0; x < tileset.Cols; ++x)
                    {
                        var tile = tileset.Bitmaps[x, y];
                        if (tile != null)
                        {
                            if (!trims.TryGetValue(tile, out rect))
                            {
                                rect = new RectangleI(tile.Width, tile.Height);
                            }
                            packer.Add(++nextID, rect.W + pad, rect.H + pad, true);
                        }
                    }
                }
            }

            //Pack the rectangles
            if (!packer.Pack())
            {
                return(null);
            }

            //Sort the packed rectangles so they're in the same order we added them
            var packed = new Packed[packer.PackedCount];

            for (int i = 0; i < packed.Length; ++i)
            {
                packer.GetPacked(i, out packed[i].ID, out packed[i].Rect);
            }
            Array.Sort(packed, (a, b) => a.ID.CompareTo(b.ID));

            //Get the atlas size
            int atlasW, atlasH;

            packer.GetBounds(out atlasW, out atlasH);
            atlasW = atlasW.ToPowerOf2();
            atlasH = atlasH.ToPowerOf2();

            ///Create the atlas with an empty texture for now
            var atlas       = new Atlas(new Texture2D(atlasW, atlasH, TextureFormat.RGBA));
            var atlasBitmap = new Bitmap(atlasW, atlasH);
            var rotBitmap   = new Bitmap(1, 1);
            var trimBitmap  = new Bitmap(1, 1);

            //Reset the ID so we get the correct packed rectangles as we go
            nextID = 0;

            AtlasImage AddImage(string name, Bitmap bitmap)
            {
                RectangleI trim;

                if (!trims.TryGetValue(bitmap, out trim))
                {
                    trim = new RectangleI(bitmap.Width, bitmap.Height);
                }

                //Get the rectangle and unpad it
                var rect = packed[nextID++].Rect;

                rect.W -= pad;
                rect.H -= pad;

                var img = atlas.AddImage(name, bitmap.Width, bitmap.Height, trim.X, trim.Y, trim.W, trim.H, rect, trim.W != rect.W);

                //Blit the bitmap onto the atlas, optionally rotating it
                if (trim.W != rect.W)
                {
                    //Rotate the bitmap, trimming first if the bitmap was trimmed
                    if (trim.W < bitmap.Width || trim.H < bitmap.Height)
                    {
                        bitmap.GetSubRect(trimBitmap, trim);
                        trimBitmap.RotateRight(rotBitmap);
                    }
                    else
                    {
                        bitmap.RotateRight(rotBitmap);
                    }

                    atlasBitmap.CopyPixels(rotBitmap, rect.X, rect.Y);
                }
                else
                {
                    atlasBitmap.CopyPixels(bitmap, trim.X, trim.Y, trim.W, trim.H, rect.X, rect.Y);
                }

                return(img);
            }

            //Add the images
            foreach (var pair in bitmaps)
            {
                AddImage(pair.Key, pair.Value);
            }

            //Add the fonts
            Bitmap charBitmap = null;

            foreach (var pair in fonts)
            {
                var size = pair.Value;

                //This is the bitmap we'll render the character onto
                if (charBitmap == null)
                {
                    charBitmap = new Bitmap(size.MaxCharW, size.MaxCharH);
                }
                else
                {
                    charBitmap.Resize(size.MaxCharW, size.MaxCharH);
                }

                //Create an atlas font to populate with the characters
                var        font = atlas.AddFont(pair.Key, size.Ascent, size.Descent, size.LineGap);
                FontChar   chr;
                RectangleI rect;
                for (int i = 0; i < size.CharCount; ++i)
                {
                    size.GetCharInfoAt(i, out chr);

                    if (!size.IsEmpty(chr.Char))
                    {
                        //Get the packed rectangle and unpad it
                        rect    = packed[nextID++].Rect;
                        rect.W -= pad;
                        rect.H -= pad;

                        //Rasterize the character and optionally rotate it before blitting
                        size.GetPixels(chr.Char, charBitmap, fontsToPremultiply.Contains(size));
                        if (chr.Width != rect.W)
                        {
                            charBitmap.RotateRight(rotBitmap);
                            atlasBitmap.CopyPixels(rotBitmap, rect.X, rect.Y);
                        }
                        else
                        {
                            atlasBitmap.CopyPixels(charBitmap, rect.X, rect.Y);
                        }
                    }
                    else
                    {
                        rect = RectangleI.Empty;
                    }

                    var atlasChar = font.AddChar(chr.Char, chr.Width, chr.Height, chr.Advance, chr.OffsetX, chr.OffsetY, rect, chr.Width != rect.W);

                    //Set character kerning
                    for (int j = 0; j < size.CharCount; ++j)
                    {
                        char nextChar = size.GetCharAt(j);
                        int  kern     = size.GetKerning(chr.Char, nextChar);
                        if (kern != 0)
                        {
                            atlasChar.SetKerning(nextChar, kern);
                        }
                    }
                }
            }

            //Add the tiles
            foreach (var pair in tiles)
            {
                var prefix     = pair.Key;
                var tileset    = pair.Value;
                var atlasTiles = atlas.AddTiles(prefix, tileset.Cols, tileset.Rows, tileset.TileWidth, tileset.TileHeight);

                for (int y = 0; y < tileset.Rows; ++y)
                {
                    for (int x = 0; x < tileset.Cols; ++x)
                    {
                        var tile = tileset.Bitmaps[x, y];
                        if (tile != null)
                        {
                            var image = AddImage($"{prefix}:{x},{y}", tile);
                            atlasTiles.SetTile(x, y, image);
                        }
                    }
                }
            }

            //Now that the bitmap is rendered, upload it to the texture
            atlas.Texture.SetPixels(atlasBitmap);

            return(atlas);
        }
Ejemplo n.º 33
0
		internal Canvas(Packed image) :
			this(image, image.Backend.Composition)
		{ }