/// <summary> /// Equals - compares this Point3D with the passed in object. In this equality /// Double.NaN is equal to itself, unlike in numeric equality. /// Note that double values can acquire error when operated upon, such that /// an exact comparison between two values which /// are logically equal may fail. /// </summary> /// <returns> /// bool - true if the object is an instance of Point3D and if it's equal to "this". /// </returns> /// <param name='o'>The object to compare to "this"</param> public override bool Equals(object o) { if ((null == o) || !(o is Point3D)) { return(false); } Point3D value = (Point3D)o; return(Point3D.Equals(this, value)); }
// This method performs the Point3D operations private void PerformOperation(object sender, RoutedEventArgs e) { RadioButton li = (sender as RadioButton); // Strings used to display the results String syntaxString, resultType, operationString; // The local variables point1, point2, vector2, etc are defined in each // case block for readability reasons. Each variable is contained within // the scope of each case statement. switch (li.Name) { //begin switch case "rb1": { // Translates a Point3D by a Vector3D using the overloaded + operator. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Vector3D vector1 = new Vector3D(20, 30, 40); Point3D pointResult = new Point3D(); pointResult = point1 + vector1; // point3DResult is equal to (30, 35, 41) // Displaying Results syntaxString = "pointResult = point1 + vector1;"; resultType = "Point3D"; operationString = "Adding a 3D Point and a 3D Vector"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { // Translates a Point3D by a Vector3D using the static Add method. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Vector3D vector1 = new Vector3D(20, 30, 40); Point3D pointResult = new Point3D(); pointResult = Point3D.Add(point1, vector1); // pointResult is equal to (30, 35, 41) // Displaying Results syntaxString = "pointResult = Point3D.Add(point1, vector1);"; resultType = "Point3D"; operationString = "Adding a 3D Point and a 3D Vector"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Subtracts a Vector3D from a Point3D using the overloaded - operator. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Vector3D vector1 = new Vector3D(20, 30, 40); Point3D pointResult = new Point3D(); pointResult = point1 - vector1; // pointResult is equal to (-10, -25, -39) // Displaying Results syntaxString = "pointResult = point1 - vector1;"; resultType = "Point3D"; operationString = "Subtracting a Vector3D from a Point3D"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Subtracts a Vector3D from a Point3D using the static Subtract method. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Vector3D vector1 = new Vector3D(20, 30, 40); Point3D pointResult = new Point3D(); pointResult = Point3D.Subtract(point1, vector1); // pointResult is equal to (-10, -25, -39) // Displaying Results syntaxString = "pointResult = Point3D.Subtract(point1, vector1);"; resultType = "Point3D"; operationString = "Subtracting a Vector3D from a Point3D"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Subtracts a Point3D from a Point3D using the overloaded - operator. // Returns a Vector3D. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Vector3D vectorResult = new Vector3D(); vectorResult = point1 - point2; // vectorResult is equal to (-5, -35, -59) // Displaying Results syntaxString = " vectorResult = point1 - point2;"; resultType = "Vector3D"; operationString = "Subtracting a Point3D from a Point3D"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Subtracts a Point3D from a Point3D using the static Subtract method. // Returns a Vector3D. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Vector3D vectorResult = new Vector3D(); vectorResult = Point3D.Subtract(point1, point2); // vectorResult is equal to (-5, -35, -59) // Displaying Results syntaxString = "vectorResult = Point3D.Subtract(point1, point2);"; resultType = "Vector3D"; operationString = "Subtracting a Point3D from a Point3D"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Offsets the X, Y and Z values of a Point3D. Point3D point1 = new Point3D(10, 5, 1); point1.Offset(20, 30, 40); // point1 is equal to (30, 35, 41) // Note: This operation is equivalent to adding a point // to vector with the corresponding X,Y, Z values. // Displaying Results syntaxString = "point1.Offset(20, 30, 40);"; resultType = "Point3D"; operationString = "Offsetting a Point3D"; ShowResults(point1.ToString(), syntaxString, resultType, operationString); break; } case "rb8": { // Multiplies a Point3D by a Matrix. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Point3D pointResult = new Point3D(); Matrix3D matrix1 = new Matrix3D(10, 10, 10, 0, 20, 20, 20, 0, 30, 30, 30, 0, 5, 10, 15, 1); pointResult = point1 * matrix1; // pointResult is equal to (235, 240, 245) // Displaying Results resultType = "Point3D"; syntaxString = "pointResult = point1 * matrix1;"; operationString = "Multiplying a Point3D by a Matrix3D"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb9": { // Multiplies a Point3D by a Matrix. // Returns a Point3D. Point3D point1 = new Point3D(10, 5, 1); Point3D pointResult = new Point3D(); Matrix3D matrix1 = new Matrix3D(10, 10, 10, 0, 20, 20, 20, 0, 30, 30, 30, 0, 5, 10, 15, 1); pointResult = Point3D.Multiply(point1, matrix1); // pointResult is equal to (235, 240, 245) // Displaying Results resultType = "Point3D"; syntaxString = "pointResult = Point3D.Multiply(point1, matrix1);"; operationString = "Multiplying a Point3D by a Matrix"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb10": { // Checks if two Point3Ds are equal using the overloaded equality operator. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Boolean areEqual; areEqual = (point1 == point2); // areEqual is False // Displaying Results syntaxString = "areEqual = (point1 == point2);"; resultType = "Boolean"; operationString = "Checking if two 3D points are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb11": { // Checks if two Point3D structures are equal using the static Equals method. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Boolean areEqual; areEqual = Point3D.Equals(point1, point2); // areEqual is False //Displaying Results syntaxString = "areEqual = Point3D.Equals(point1, point2);"; resultType = "Boolean"; operationString = "Checking if 3D two points are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb12": { // Compares an Object and a Point3D for equality using the non-static Equals method. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Boolean areEqual; areEqual = point1.Equals(point2); // areEqual is False. point2 is a Point3D structure, but it is not equal to point1. // Displaying Results syntaxString = "areEqual = point1.Equals(point2);;"; resultType = "Boolean"; operationString = "Checking if two 3D points are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb13": { // Converts a string representation of a 3-D point into a Point3D structure. Point3D pointResult = new Point3D(); pointResult = Point3D.Parse("1,3,5"); // pointResult is equal to (1,3,5) // Displaying Results syntaxString = "ointResult = Point3D.Parse(\"1,3,5\");"; resultType = "Matrix"; operationString = "Converting a string into a Point3D structure."; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb14": { // Checks if two Point3Ds are not equal using the overloaded inequality operator. Point3D point1 = new Point3D(10, 5, 1); Point3D point2 = new Point3D(15, 40, 60); Boolean areNotEqual; areNotEqual = (point1 != point2); // areNotEqual is True // Displaying Results syntaxString = "areNotEqual = (point1 != point2);"; resultType = "Boolean"; operationString = "Checking if two 3D points are not equal"; ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb15": { // Point3D Subtraction // instantiate variables Point3D point1 = new Point3D(); Point3D point2 = new Point3D(15, 40, 60); Vector3D vector1 = new Vector3D(20, 30, 40); Point3D pointResult = new Point3D(); Vector3D vectorResult = new Vector3D(); // defining x,y,z of point1 point1.X = 10; point1.Y = 5; point1.Z = 1; vectorResult = Point3D.Subtract(point1, point2); // vectorResult is equal to (-5, -35, -39) vectorResult = point2 - point1; // vectorResult is equal to (5, 35, 59) //pointResult = Point3D.Subtract(point1, vector1); // pointResult is equal to (-10, -25, -39) pointResult = vector1 - point1; // pointResult is equal to (10, 25, 39) // Displaying Results syntaxString = "areNotEqual = (point1 != point2);"; resultType = "Boolean"; operationString = "Checking if two 3D points are not equal"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } default: break; } //end switch }
/// <summary> /// Equals - compares this Point3D with the passed in object. In this equality /// Double.NaN is equal to itself, unlike in numeric equality. /// Note that double values can acquire error when operated upon, such that /// an exact comparison between two values which /// are logically equal may fail. /// </summary> /// <returns> /// bool - true if "value" is equal to "this". /// </returns> /// <param name='value'>The Point3D to compare to "this"</param> public bool Equals(Point3D value) { return(Point3D.Equals(this, value)); }