コード例 #1
0
        // This method performs the Point4D operations
        private void PerformOperation(object sender, System.Windows.RoutedEventArgs e)
        {
            //RadioButton li = ((sender as RadioButtonList).SelectedItem as RadioButton);
            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":
                    {
                        // Add a Point4D to a Point4D using the overloaded + operator.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        Point4D pointResult = new Point4D();

                        pointResult = point1 + point2;
                        // pointResult is equal to (25, 45, 61, 79))

                        // Displaying Results
                        syntaxString = "pointResult = point1 + point2;";
                        resultType = "Point4D";
                        operationString = "Adding a 3D Point and a 3D Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Add a Point4D to a Point4D using the static Add method.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        Point4D pointResult = new Point4D();

                        pointResult = Point4D.Add(point1, point2);
                        // pointResult is equal to (25, 45, 61, 79)

                        // Displaying Results
                        syntaxString = "pointResult = Point4D.Add(point1, point2);";
                        resultType = "Point4D";
                        operationString = "Adding a 3D Point and a 3D Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Subtracts a Point4D from a Point4D using the overloaded - operator.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        Point4D pointResult = new Point4D();

                        pointResult = point1 - point2;
                        // pointResult is equal to (-5, -35, -59, -71)

                        // Displaying Results
                        syntaxString = "pointResult = point1 - point2;";
                        resultType = "Point4D";
                        operationString = "Subtracting a Vector3D from a Point4D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Subtracts a Point3D from a Point4D using the static Subtract method.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        Point4D pointResult = new Point4D();

                        pointResult = Point4D.Subtract(point1, point2);
                        // pointResult is equal to (-5, -35, -59, -71)

                        // Displaying Results
                        syntaxString = "pointResult = Point4D.Subtract(point1, point2);";
                        resultType = "Point4D";
                        operationString = "Subtracting a Vector3D from a Point4D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Offsets the X, Y, Z, and W values of a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);

                        point1.Offset(20, 30, 40, 50);
                        // point1 is equal to (30, 35, 41, 54)

                        // Displaying Results
                        syntaxString = "point1.Offset(20, 30, 41, 54);";
                        resultType = "Point4D";
                        operationString = "Offsetting a Point4D";
                        ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Multiplies a Point4D by a Matrix.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D pointResult = new Point4D();
                        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 (250, 270, 290, 4)

                        // Displaying Results
                        resultType = "Point4D";
                        syntaxString = "pointResult = point1 * matrix1;";
                        operationString = "Multiplying a Point4D by a Matrix3D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Multiplies a Point4D by a Matrix.
                        // Returns a Point4D.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D pointResult = new Point4D();
                        Matrix3D matrix1 = new Matrix3D(10, 10, 10, 0, 20, 20, 20, 0, 30, 30, 30, 0, 5, 10, 15, 1);

                        pointResult = Point4D.Multiply(point1, matrix1);
                        // pointResult is equal to (250, 270, 290, 4)

                        // Displaying Results
                        resultType = "Point4D";
                        syntaxString = "pointResult = Point4D.Multiply(point1, matrix1);";
                        operationString = "Multiplying a Point4D by a Matrix3D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb8":
                    {
                        // Checks if two Point4D structures are equal using the overloaded equality operator.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        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 "rb9":
                    {
                        // Checks if two Point4D structures are equal using the static Equals method.

                        // point1's x,y,z,w properties set when the structure is created
                        Point4D point1 = new Point4D(10, 5, 1, 4);

                        Point4D point2 = new Point4D();
                        Boolean areEqual;

                        // settting point2's x,y,z,w properties
                        point2.X = 15;
                        point2.Y = 40;
                        point2.Z = 60;
                        point2.W = 75;

                        areEqual = Point4D.Equals(point1, point2);
                        // areEqual is False

                        //Displaying Results
                        syntaxString = "areEqual = Point4D.Equals(point1, point2);";
                        resultType = "Boolean";
                        operationString = "Checking if 3D two points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb10":
                    {
                        // Compares an Object and a Point4D for equality using the non-static Equals method.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        Boolean areEqual;

                        areEqual = point1.Equals(point2);
                        // areEqual is False.  point2 is a Point4D 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 "rb11":
                    {
                        // Converts a string representation of a 4D point into a Point4D structure.

                        Point4D pointResult = new Point4D();

                        pointResult = Point4D.Parse("1,3,5,7");
                        // pointResult is equal to (1, 3, 5, 7)

                        // Displaying Results
                        syntaxString = "pointResult = Point4D.Parse(\"1,3,5,7\");";
                        resultType = "Point4D";
                        operationString = "Converts a string into a Point4D structure.";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb12":
                    {
                        // Checks if two Point4Ds are not equal using the overloaded inequality operator.

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        Point4D point2 = new Point4D(15, 40, 60, 75);
                        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 "rb13":
                    {
                        // Gets a string representation of the structure
                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        String pointString;

                        pointString = point1.ToString();
                        // matrixString is equal to 10, 5, 1, 4

                        // Displaying Results
                        syntaxString = "pointString = point1.ToString();";
                        resultType = "String";
                        operationString = "Getting the string representation of a Point4D";
                        ShowResults(pointString.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb14":
                    {
                        // Gets the hashcode of a Point4D structure

                        Point4D point1 = new Point4D(10, 5, 1, 4);
                        int pointHashCode;

                        pointHashCode = point1.GetHashCode();

                        // Displaying Results
                        syntaxString = "pointHashCode = point1.GetHashCode();";
                        resultType = "int";
                        operationString = "Getting the hashcode of Point4D";
                        ShowResults(pointHashCode.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb15":
                    {
                        // Point4D Equality and Inequality operations

                        // instantiate variables
                        Point4D point4D1 = new Point4D();
                        Point4D point4D2 = new Point4D(15, 40, 60, 75);
                        Point3D point3D1 = new Point3D(15, 40, 60);

                        // result variables
                        Boolean areEqual;
                        Boolean areNotEqual;
                        String stringResult;

                        // defining x,y,z of point1
                        point4D1.X = 10;
                        point4D1.Y = 5;
                        point4D1.Z = 1;
                        point4D1.W = 4;

                        // equality operations

                        areEqual = point4D1 == point4D2;
                        // areEqual is False

                        areNotEqual = point4D1 != point4D2;
                        // areNotEqual is True

                        if(Point4D.Equals(point4D1, point3D1))
                        {
                            // the if condition is not true, so this block will not execute
                            stringResult = "Both objects are Point4D structures and they are equal";
                        }
                        else
                        {
                            // the if condition is false, so this branch will execute
                            stringResult = "parameters are not Point4D strucutres, or they are but are not equal";
                        }

                        // Displaying Results
                        syntaxString = "areNotEqual = (point1 != point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two 3D points are not equal";
                        ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                default:
                    break;

            } //end switch
        }