public void ArithmeticOperationTest2() { var add1 = new ValueTuple <int, int>(1, 2); var add2 = add1.Add(2, 3); Assert.IsTrue(add2.Equals(new ValueTuple <int, int>(3, 5))); }
public void ArithmeticOperationTest1() { var add1 = new ValueTuple <int, int>(1, 2); var add2 = new ValueTuple <int, int>(2, 3); var add3 = add1.Add(add2); var mul = add3.Multiply(3); Assert.IsTrue(add3.Equals(new ValueTuple <int, int>(3, 5))); Assert.IsTrue(mul.Equals(new ValueTuple <int, int>(9, 15))); }
public List <(int, int, int)> GetCells() { var rs = new List <(int, int, int)>(); // Start XY Cell과 증가 방향을 정한다. var startUpXY = new ValueTuple <int, int>(X, Y); var startDownXY = new ValueTuple <int, int>(X, Y - 1); var incrementalW = new ValueTuple <int, int>(1, 0); var incrementalUpH = new ValueTuple <int, int>(0, 1); var incrementalDownH = new ValueTuple <int, int>(0, -1); dynamic upZs = new { left = new int[] { 1, 2, }, right = new int[] { 1, 4 }, sole = 1 }; dynamic downZs = new { left = new int[] { 2, 3, }, right = new int[] { 3, 4 }, sole = 3 }; // Calculate Interval을 정한다. var calculateInterval = new List <(int, int)>(); var bottomLine = Enumerable.Range(0, Magnification).ToList(); while (bottomLine.Count != 0) { calculateInterval.Add(new ValueTuple <int, int>(bottomLine.First(), bottomLine.Last())); if (bottomLine.Count == 1) { bottomLine.RemoveAt(0); } else { bottomLine.RemoveAt(0); bottomLine.RemoveAt(bottomLine.Count - 1); } } foreach ((int, int)interval in calculateInterval) { if (interval.Item1 == interval.Item2) { var targetUpXY = startUpXY.Add(incrementalW.Multiply(interval.Item2)); var targetDownXY = startDownXY.Add(incrementalW.Multiply(interval.Item2)); rs.Add(new ValueTuple <int, int, int>(targetUpXY.Item1, targetUpXY.Item2, upZs.sole)); rs.Add(new ValueTuple <int, int, int>(targetDownXY.Item1, targetDownXY.Item2, downZs.sole)); continue; } for (int i = interval.Item1; i <= interval.Item2; i++) { var targetUpXY = startUpXY.Add(incrementalW.Multiply(i)); var targetDownXY = startDownXY.Add(incrementalW.Multiply(i)); int[] targetUpZs = null; int[] targetDownZs = null; if (i == interval.Item1) { targetUpZs = upZs.left; targetDownZs = downZs.left; } else if (i == interval.Item2) { targetUpZs = upZs.right; targetDownZs = downZs.right; } else { targetUpZs = new int[] { 1, 2, 3, 4 }; targetDownZs = new int[] { 1, 2, 3, 4 }; } foreach (int item in targetUpZs) { rs.Add(new ValueTuple <int, int, int>(targetUpXY.Item1, targetUpXY.Item2, item)); } foreach (int item in targetDownZs) { rs.Add(new ValueTuple <int, int, int>(targetDownXY.Item1, targetDownXY.Item2, item)); } } startUpXY = startUpXY.Add(incrementalUpH); startDownXY = startDownXY.Add(incrementalDownH); } return(rs); }
public List <(int, int, int)> GetCells() { var rs = new List <(int, int, int)>(); // Start XY Cell과 증가 방향을 정한다. ValueTuple <int, int> startXY = new ValueTuple <int, int>(); ValueTuple <int, int> incrementalW = new ValueTuple <int, int>(); ValueTuple <int, int> incrementalH = new ValueTuple <int, int>(); dynamic zs = null; switch (Direction) { case Direction.Down: startXY = new ValueTuple <int, int>(X, Y - 1); incrementalW = new ValueTuple <int, int>(0, -1); incrementalH = new ValueTuple <int, int>(1, 0); zs = new { left = new int[] { 1, 4, }, right = new int[] { 3, 4 }, down = 4 }; break; case Direction.Right: startXY = new ValueTuple <int, int>(X, Y); incrementalW = new ValueTuple <int, int>(1, 0); incrementalH = new ValueTuple <int, int>(0, 1); zs = new { left = new int[] { 1, 2, }, right = new int[] { 1, 4 }, down = 1 }; break; case Direction.Up: startXY = new ValueTuple <int, int>(X - 1, Y); incrementalW = new ValueTuple <int, int>(0, 1); incrementalH = new ValueTuple <int, int>(-1, 0); zs = new { left = new int[] { 2, 3, }, right = new int[] { 1, 2 }, down = 2 }; break; case Direction.Left: startXY = new ValueTuple <int, int>(X - 1, Y - 1); incrementalW = new ValueTuple <int, int>(-1, 0); incrementalH = new ValueTuple <int, int>(0, -1); zs = new { left = new int[] { 3, 4, }, right = new int[] { 2, 3 }, down = 3 }; break; default: throw new NotImplementedException(); } // 사용되는 모든 XY Cell을 정한다. // Calculate Interval을 정한다. var calculateInterval = new List <(int, int)>(); var bottomLine = Enumerable.Range(0, Magnification).ToList(); while (bottomLine.Count != 0) { calculateInterval.Add(new ValueTuple <int, int>(bottomLine.First(), bottomLine.Last())); if (bottomLine.Count == 1) { bottomLine.RemoveAt(0); } else { bottomLine.RemoveAt(0); bottomLine.RemoveAt(bottomLine.Count - 1); } } foreach ((int, int)interval in calculateInterval) { if (interval.Item1 == interval.Item2) { var targetXY = startXY.Add(incrementalW.Multiply(interval.Item2)); rs.Add(new ValueTuple <int, int, int>(targetXY.Item1, targetXY.Item2, zs.down)); continue; } for (int i = interval.Item1; i <= interval.Item2; i++) { var targetXY = startXY.Add(incrementalW.Multiply(i)); int[] targetZs = null; if (i == interval.Item1) { targetZs = zs.left; } else if (i == interval.Item2) { targetZs = zs.right; } else { targetZs = new int[] { 1, 2, 3, 4 }; } foreach (int item in targetZs) { rs.Add(new ValueTuple <int, int, int>(targetXY.Item1, targetXY.Item2, item)); } } startXY = startXY.Add(incrementalH); } return(rs); }
public static ValueTuple <T1, T2, T3> ad <T1, T2, T3>(ValueTuple <T1, T2> self, T3 third) => self.Add(third);