public IntVector4(IntVector4 location) { this.x = location.x; this.y = location.y; this.z = location.z; this.T = location.T; }
public int CompareTo(object obj) { if (obj == null) { return(1); } IntVector4 otherVector = obj as IntVector4; if (otherVector != null) { int value = t.CompareTo(otherVector.t); if (value == 0) { value = z.CompareTo(otherVector.z); if (value == 0) { value = y.CompareTo(otherVector.y); if (value == 0) { value = x.CompareTo(otherVector.x); } } } return(value); } else { throw new ArgumentException("Object is not a IntVector4"); } }
internal static void RunStep4() { Dictionary <IntVector4, int> adjCount = new Dictionary <IntVector4, int>(); foreach (IntVector4 location in grid4) { foreach (IntVector4 direction in IntVector4.CardinalDirectionsIncludingDiagonals) { IntVector4 position = IntVector4.Add(location, direction); if (!adjCount.ContainsKey(position)) { adjCount.Add(position, 0); } adjCount[position]++; } } HashSet <IntVector4> newGrid = new HashSet <IntVector4>(); foreach (KeyValuePair <IntVector4, int> pair in adjCount) { //If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive. if (grid4.Contains(pair.Key) && (pair.Value == 2 || pair.Value == 3)) { newGrid.Add(pair.Key); } //If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive. if ((!grid4.Contains(pair.Key)) && pair.Value == 3) { newGrid.Add(pair.Key); } } grid4 = newGrid; }
public override bool Equals(Object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return(false); } else { IntVector4 v = (IntVector4)obj; return((x == v.x) && (y == v.y) && (z == v.z) && (t == v.t)); } }
internal static IntVector4 Multiply(IntVector4 vector, int number) { return(new IntVector4(vector.x * number, vector.y * number, vector.z * number, vector.t * number)); }
internal static IntVector4 Subtract(IntVector4 vector1, IntVector4 vector2) { return(new IntVector4(vector1.x - vector2.x, vector1.y - vector2.y, vector1.z - vector2.z, vector1.t - vector2.t)); }
internal static IntVector4 Add(IntVector4 vector1, IntVector4 vector2) { return(new IntVector4(vector1.x + vector2.x, vector1.y + vector2.y, vector1.z + vector2.z, vector1.t + vector2.t)); }
internal static int Distance(IntVector4 a, IntVector4 b) { return(Math.Abs(a.x - b.x) + Math.Abs(a.y - b.y) + Math.Abs(a.z - b.z) + Math.Abs(a.t - b.t)); }
internal int Distance(IntVector4 coord) { return(Math.Abs(coord.x - x) + Math.Abs(coord.y - y) + Math.Abs(coord.z - z) + Math.Abs(coord.t - t)); }