public static bool isSquare(_2dObject squareObject)
        {
            if (squareObject.Edges.Count() != 4)
            {
                return(false);
            }
            double firstItem = squareObject.Edges[0];

            return(squareObject.Edges.All(x => double.Equals(x, firstItem)));
        }
Example #2
0
        static void Main(string[] args)
        {
            AppData appDataDirectory = new AppData();

            Log.init(appDataDirectory.path);
            StorageFactory storageFactory = new StorageFactory();

            _2dObject testObject = new _2dObject();
            string    readFile   = ConfigurationManager.AppSettings["readFile"];
            string    writeFile  = ConfigurationManager.AppSettings["writeFile"];

            string pathToDataFile          = Path.Combine(appDataDirectory.path, readFile);
            string pathToDataFileToBeWrite = Path.Combine(appDataDirectory.path, writeFile);

            List <_2dObject> squareObjects = testObject.read(storageFactory.getXMLManager(), pathToDataFile);

            Console.WriteLine("\n === 2dObjectCoordinator methods ===");
            Console.WriteLine("isTriangle( 5, 5, 1 ): {0}", _2dObjectCoordinator.isTriangle(new _2dObject(new double[] { 5, 5, 1 })));
            Console.WriteLine("isSquare( 1, 1, 1, 1, 1 ): {0}", _2dObjectCoordinator.isSquare(new _2dObject(new double[] { 1, 1, 1, 1, 1 })));
            Console.WriteLine("isRectangle( 1, 2, 1, 1 ): {0}", _2dObjectCoordinator.isRectangle(new _2dObject(new double[] { 1, 2, 1, 1 })));

            Console.WriteLine("\ngetTrianglesPeriphery(...) MIN:\n{0}", _2dObjectCoordinator.getTrianglesPeriphery(squareObjects, min: true));
            Console.WriteLine("\ngetSquarePeriphery(...) MAX:\n{0}", _2dObjectCoordinator.getSquarePeriphery(squareObjects, max: true));
            Console.WriteLine("\ngetRectanglePeriphery(...) MIN:\n{0}", _2dObjectCoordinator.getRectanglePeriphery(squareObjects, min: true));

            Console.WriteLine("\ngetPythagoreanTriangles(...):");
            foreach (var item in _2dObjectCoordinator.getPythagoreanTriangles(squareObjects))
            {
                Console.WriteLine(item.ToString());
            }

            squareObjects.RemoveAt(1);
            squareObjects.RemoveAt(2);
            squareObjects.RemoveAt(3);

            testObject.write(storageFactory.getXMLManager(), squareObjects, pathToDataFileToBeWrite);

            Console.WriteLine("\n === DBManager reader/writer ===");

            //testObject.write(storageFactory.getDBManager(), squareObjects);
            try {
                squareObjects = testObject.read(storageFactory.getDBManager());

                foreach (var squareObject in squareObjects)
                {
                    Console.WriteLine(squareObject);
                }
            } catch (Exception e) {
                Log.writeError(e.ToString());
            }

            Console.ReadKey();
        }
        public static bool isRectangle(_2dObject squareObject)
        {
            if (squareObject.Edges.Count() != 4)
            {
                return(false);
            }
            if (isSquare(squareObject))
            {
                return(false);
            }

            bool sidesUpDown    = squareObject.Edges[0] == squareObject.Edges[2];
            bool sidesLeftRight = squareObject.Edges[1] == squareObject.Edges[3];

            return(sidesUpDown && sidesLeftRight);
        }
        public static bool isTriangle(_2dObject squareObject)
        {
            if (squareObject.Edges.Count() != 3)
            {
                return(false);
            }
            Triangle triangle = new Triangle();

            triangle.Edges = squareObject.Edges;
            bool isTriangleCorrect = false;

            try {
                isTriangleCorrect = triangle.isTriangleValid();
            } catch (InvalidTriangleSidesException e) {
                Log.writeError(e.ToString());
            }
            return(isTriangleCorrect);
        }