public static TVector2D operator -(TVector2D a, TVector2D b) { double n = a.x - b.x; double m = a.y - b.y; TVector2D vec = new TVector2D(n, m); return(vec); }
public virtual void VecEquals(TVector2D vec) { string equals = ""; if (x == vec.x && y == vec.y) { equals = "Vec1 equals Vec2"; } else { equals = "Vec1 not equals to vec2"; } Console.WriteLine(equals); }
static void Main(string[] args) { TVector2D vec1 = new TVector2D(); vec1.EnterVec(); vec1.ShowVec(); TVector2D vec2 = new TVector2D(22, 3); vec2.ShowVec(); TVector2D vec3 = new TVector2D(vec1); vec3.ShowVec(); Console.WriteLine(vec1.VecLength()); vec1.VecNormal(); vec1.VecEquals(vec2); Console.WriteLine(vec1 + vec2); Console.WriteLine(vec1 - vec2); Console.WriteLine(vec1 * vec2); //2) HashSet <TVector2D> hash = new HashSet <TVector2D>(); hash.Add(vec1); if (hash.Contains(vec1)) { Console.WriteLine("vector was found!"); } else { Console.WriteLine("vector not found!"); } TVector2DF vec4 = new TVector2DF(2, 3); HashSet <TVector2DF> hash2 = new HashSet <TVector2DF>(); TVector2DF vec5 = new TVector2DF(2, 3); hash2.Add(vec4); Console.WriteLine(vec4.GetHashCode()); Console.WriteLine(vec5.GetHashCode()); if (vec5.Equals(hash2)) { Console.WriteLine("vector was found!"); } else { Console.WriteLine("vector not found!"); } HashSet <TVector3D> hash3 = new HashSet <TVector3D>(); TVector3D vec6 = new TVector3D(2, 3, 4); TVector3D vec7 = new TVector3D(2, 3, 5); TVector3D vec8 = new TVector3D(2, 3, 2); TVector3D vec9 = new TVector3D(2, 3, 7); TVector3D vec10 = new TVector3D(2, 3, 6); hash3.Add(vec6); hash3.Add(vec7); hash3.Add(vec8); hash3.Add(vec9); hash3.Add(vec10); Console.WriteLine(hash3.Count); HashSet <TVector3DF> hash4 = new HashSet <TVector3DF>(); TVector3DF vec11 = new TVector3DF(2, 3, 4); TVector3DF vec12 = new TVector3DF(2, 3, 5); TVector3DF vec13 = new TVector3DF(2, 3, 2); TVector3DF vec14 = new TVector3DF(2, 3, 7); TVector3DF vec15 = new TVector3DF(2, 3, 6); hash4.Add(vec11); hash4.Add(vec12); hash4.Add(vec13); hash4.Add(vec14); hash4.Add(vec15); Console.WriteLine(hash4.Count); }
public TVector2DF(TVector2D vec) { this.x = vec.x; this.y = vec.y; }