public void LargestComponentShouldWork() { var input = new Dictionary<int, List<int>> { { 0, new List<int> { 8, 1, 5 } }, { 1, new List<int> { 0 } }, { 5, new List<int> { 0, 8 } }, { 8, new List<int> { 0, 5 } }, { 2, new List<int> { 3, 4 } }, { 3, new List<int> { 2, 4 } }, { 4, new List<int> { 3, 2 } }, }; var result = LargestComponent.GetLargest(input); Assert.Equal(4, result); }
public void LargestComponentShouldWork2() { var input = new Dictionary<int, List<int>> { { 3, new List<int> { } }, { 4, new List<int> { 6 } }, { 6, new List<int> { 4, 5, 7, 8 } }, { 8, new List<int> { 6 } }, { 7, new List<int> { 6 } }, { 5, new List<int> { 6 } }, { 1, new List<int> { 2 } }, { 2, new List<int> { 1} } }; var result = LargestComponent.GetLargest(input); Assert.Equal(5, result); }
public static uint Compress(Quaternion rotation) { float absX = Mathf.Abs(rotation.x), absY = Mathf.Abs(rotation.y), absZ = Mathf.Abs(rotation.z), absW = Mathf.Abs(rotation.w); var largestComponent = new LargestComponent(ComponentType.X, absX); if (absY > largestComponent.Value) { largestComponent.Value = absY; largestComponent.ComponentType = ComponentType.Y; } if (absZ > largestComponent.Value) { largestComponent.Value = absZ; largestComponent.ComponentType = ComponentType.Z; } if (absW > largestComponent.Value) { largestComponent.Value = absW; largestComponent.ComponentType = ComponentType.W; } float a, b, c; switch (largestComponent.ComponentType) { case ComponentType.X: if (rotation.x >= 0) { a = rotation.y; b = rotation.z; c = rotation.w; } else { a = -rotation.y; b = -rotation.z; c = -rotation.w; } break; case ComponentType.Y: if (rotation.y >= 0) { a = rotation.x; b = rotation.z; c = rotation.w; } else { a = -rotation.x; b = -rotation.z; c = -rotation.w; } break; case ComponentType.Z: if (rotation.z >= 0) { a = rotation.x; b = rotation.y; c = rotation.w; } else { a = -rotation.x; b = -rotation.y; c = -rotation.w; } break; case ComponentType.W: if (rotation.w >= 0) { a = rotation.x; b = rotation.y; c = rotation.z; } else { a = -rotation.x; b = -rotation.y; c = -rotation.z; } break; default: // Should never happen! throw new ArgumentOutOfRangeException("Unknown rotation component type: " + largestComponent.ComponentType); } float normalizedA = (a - Minimum) / (Maximum - Minimum), normalizedB = (b - Minimum) / (Maximum - Minimum), normalizedC = (c - Minimum) / (Maximum - Minimum); uint integerA = (uint)Mathf.FloorToInt(normalizedA * 1024.0f + 0.5f), integerB = (uint)Mathf.FloorToInt(normalizedB * 1024.0f + 0.5f), integerC = (uint)Mathf.FloorToInt(normalizedC * 1024.0f + 0.5f); return((((uint)largestComponent.ComponentType) << 30) | (integerA << 20) | (integerB << 10) | integerC); }