Ejemplo n.º 1
0
        // Displays the values of the variables
        public void ShowVars()
        {
            Point4D p1 = new Point4D(10, 5, 1, 4);
            Point4D p2 = new Point4D(15, 40, 60, 75);

            Matrix3D m1 = new Matrix3D(10,10,10,0,20,20,20,0,30,30,30,0,5,10,15,1);

            // Displaying values in Text objects
            txtPoint1.Text = p1.ToString();
            txtPoint2.Text = p2.ToString();
            txtMatrix1.Text = m1.ToString();
        }
Ejemplo n.º 2
0
        // This method performs the Point operations
        public 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":
                    {
                        // Converts a String to a Point using a PointConverter
                        // Returns a Point.

                        PointConverter pConverter = new PointConverter();
                        Point pointResult = new Point();
                        string string1 = "10,20";

                        pointResult = (Point)pConverter.ConvertFromString(string1);
                        // pointResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);";
                        resultType = "Point";
                        operationString = "Converting a String to a Point";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Converts a String to a Vector using a VectorConverter
                        // Returns a Vector.

                        VectorConverter vConverter = new VectorConverter();
                        Vector vectorResult = new Vector();
                        string string1 = "10,20";

                        vectorResult = (Vector)vConverter.ConvertFromString(string1);
                        // vectorResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);";
                        resultType = "Vector";
                        operationString = "Converting a String into a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Converts a String to a Matrix using a MatrixConverter
                        // Returns a Matrix.

                        MatrixConverter mConverter = new MatrixConverter();
                        Matrix matrixResult = new Matrix();
                        string string2 = "10,20,30,40,50,60";

                        matrixResult = (Matrix)mConverter.ConvertFromString(string2);
                        // matrixResult is equal to (10, 20, 30, 40, 50, 60)

                        // Displaying Results
                        syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);";
                        resultType = "Matrix";
                        operationString = "Converting a String into a Matrix";
                        ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Converts a String to a Point3D using a Point3DConverter
                        // Returns a Point3D.

                        Point3DConverter p3DConverter = new Point3DConverter();
                        Point3D point3DResult = new Point3D();
                        string string3 = "10,20,30";

                        point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);
                        // point3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);";
                        resultType = "Point3D";
                        operationString = "Converting a String into a Point3D";
                        ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Converts a String to a Vector3D using a Vector3DConverter
                        // Returns a Vector3D.

                        Vector3DConverter v3DConverter = new Vector3DConverter();
                        Vector3D vector3DResult = new Vector3D();
                        string string3 = "10,20,30";

                        vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);
                        // vector3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Vector3D";
                        operationString = "Converting a String into a Vector3D";
                        ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Converts a String to a Size3D using a Size3DConverter
                        // Returns a Size3D.

                        Size3DConverter s3DConverter = new Size3DConverter();
                        Size3D size3DResult = new Size3D();
                        string string3 = "10,20,30";

                        size3DResult = (Size3D)s3DConverter.ConvertFromString(string3);
                        // size3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Size3D";
                        operationString = "Converting a String into a Size3D";
                        ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Converts a String to a Point4D using a Point4DConverter
                        // Returns a Point4D.

                        Point4DConverter p4DConverter = new Point4DConverter();
                        Point4D point4DResult = new Point4D();
                        string string4 = "10,20,30,40";

                        point4DResult = (Point4D)p4DConverter.ConvertFromString(string4);
                        // point4DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Point4D";
                        operationString = "Converting a String into a Point4D";
                        ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                    default:
                    break;

            } //end switch
        }
Ejemplo n.º 3
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
        }