public void RemovesTest() { int numberOfElems = 10; OffsetList list = new OffsetList(); for (int i = 0; i < numberOfElems; ++i) { list.Add(new Offset(i, i)); } Assert.IsFalse(list.Remove(null)); Assert.IsFalse(list.Remove(new Offset(numberOfElems, numberOfElems))); Assert.AreEqual(numberOfElems, list.Length); int numberOfDeletions = 0; for (int i = 0; i < numberOfElems; i += 2) { Assert.IsTrue(list.Remove(new Offset(i, i))); numberOfDeletions++; } Assert.AreEqual(numberOfElems - numberOfDeletions, list.Length); for (int i = 0; i < numberOfElems; i += 2) { Assert.IsFalse(list.Contains(new Offset(i, i))); } }
public void FromPmxMorph(PmxMorph m, bool nonStr = false) { if (!nonStr) { Name = m.Name; NameE = m.NameE; } Panel = m.Panel; Kind = m.Kind; int count = m.OffsetList.Count; OffsetList.Clear(); OffsetList.Capacity = count; for (int i = 0; i < count; i++) { OffsetList.Add(m.OffsetList[i].Clone()); } FromID(m); }
public void TestOffsetList() { OffsetList listOffset = new OffsetList(); Random random = new Random(DateTime.Now.Millisecond); for (int i = 0; i < 10; ++i) { for (int j = 0; j < 5; ++j) { listOffset.Add(new Offset(i, j)); } } for (int i = 0; i < 10; i += 2) { for (int j = 0; j < 5; j += 2) { listOffset.Remove(new Offset(i, j)); listOffset.Remove(new Offset(10 + random.Next(100), random.Next(300))); } } for (int i = 0; i < 10; ++i) { for (int j = 0; j < 5; ++j) { if (i % 2 == 0 && j % 2 == 0) { Assert.IsFalse(listOffset.Contains(new Offset(i, j))); } else { Assert.IsTrue(listOffset.Contains(new Offset(i, j))); } } } Assert.AreEqual(listOffset.Length, 35); }
public void FromStreamEx(Stream s, PmxElementFormat f = null) { Name = PmxStreamHelper.ReadString(s, f); NameE = PmxStreamHelper.ReadString(s, f); Panel = PmxStreamHelper.ReadElement_Int32(s, 1); Kind = (OffsetKind)PmxStreamHelper.ReadElement_Int32(s, 1); int num = PmxStreamHelper.ReadElement_Int32(s); OffsetList.Clear(); OffsetList.Capacity = num; for (int i = 0; i < num; i++) { switch (Kind) { case OffsetKind.Group: case OffsetKind.Flip: { PmxGroupMorph pmxGroupMorph = new PmxGroupMorph(); pmxGroupMorph.FromStreamEx(s, f); OffsetList.Add(pmxGroupMorph); break; } case OffsetKind.Vertex: { PmxVertexMorph pmxVertexMorph = new PmxVertexMorph(); pmxVertexMorph.FromStreamEx(s, f); OffsetList.Add(pmxVertexMorph); break; } case OffsetKind.Bone: { PmxBoneMorph pmxBoneMorph = new PmxBoneMorph(); pmxBoneMorph.FromStreamEx(s, f); OffsetList.Add(pmxBoneMorph); break; } case OffsetKind.Impulse: { PmxImpulseMorph pmxImpulseMorph = new PmxImpulseMorph(); pmxImpulseMorph.FromStreamEx(s, f); OffsetList.Add(pmxImpulseMorph); break; } case OffsetKind.Material: { PmxMaterialMorph pmxMaterialMorph = new PmxMaterialMorph(); pmxMaterialMorph.FromStreamEx(s, f); OffsetList.Add(pmxMaterialMorph); break; } case OffsetKind.UV: case OffsetKind.UVA1: case OffsetKind.UVA2: case OffsetKind.UVA3: case OffsetKind.UVA4: { PmxUVMorph pmxUVMorph = new PmxUVMorph(); pmxUVMorph.FromStreamEx(s, f); OffsetList.Add(pmxUVMorph); break; } } } if (f.WithID) { base.UID = PmxStreamHelper.ReadElement_UInt(s); base.CID = PmxStreamHelper.ReadElement_UInt(s); } }