コード例 #1
0
        public string GetTriangleVerticesByRowAndColumn(ShapesGrid shapeGrid, char row, int column)
        {
            TriangleGrid tGrid = (TriangleGrid)shapeGrid;

            if (TriangleFunctions.isLetterValid(row, tGrid) && TriangleFunctions.IsColumnValid(column, tGrid))
            {
                return(TriangleFunctions.GetVerticesByRowAndColumn(row, column, tGrid));
            }

            return("Invalid Request");
        }
コード例 #2
0
        public string GetTriangleRowAndColumnByVertices(ShapesGrid shapesGrid, string vertices)
        {
            TriangleGrid tGrid = (TriangleGrid)shapesGrid;

            if (TriangleFunctions.ValidateVertices(vertices, shapesGrid, out Triangle triangle))
            {
                return(TriangleFunctions.GetRowAndColumnByVertices(triangle, tGrid));
            }

            return("Invalid Vector Supplied");
        }
コード例 #3
0
        internal static bool ValidateVertices(string vertices, ShapesGrid grid, out Triangle triangle)
        {
            triangle = new Triangle();
            TriangleGrid tGrid = (TriangleGrid)grid;

            if (vertices == null || vertices.Length == 0)
            {
                return(false);
            }

            //split on commas and/or spaces
            string[] strVertices = vertices.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            ////we should have 6 numbers -- V1xy, V2xy, V3xy
            if (strVertices.Length == 6)
            {
                for (int i = 0; i < strVertices.Length; i++)
                {
                    string str = strVertices[i];
                    //validate input for numbers
                    if (int.TryParse(str, out int outNum))
                    {
                        switch (i)
                        {
                        //0 and 1 = right angle
                        case 0:
                            if (!isXNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector1X = outNum;
                            break;

                        case 1:
                            if (!isYNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector1Y = outNum;
                            break;

                        //2 and 3 = top
                        case 2:
                            if (!isXNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector2X = outNum;
                            break;

                        case 3:
                            if (!isYNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector2Y = outNum;
                            break;

                        //4 and 5 = bottom
                        case 4:
                            if (!isXNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector3X = outNum;
                            break;

                        case 5:
                            if (!isYNumberValid(outNum, tGrid))
                            {
                                return(false);
                            }

                            triangle.Vector3Y = outNum;
                            break;
                        }
                    }
                    else
                    {
                        //no int
                        return(false);
                    }
                }

                //continue validation
                if (triangle.Vector1Y > triangle.Vector2Y)
                {
                    triangle.RightAngle = Triangle.RightAngleSide.Left;

                    //40,10,40,0,50,10    A9
                    //30,30,30,20,40,30   C7
                    //30,40,30,30,40,40   D7
                    //50,40,50,30,60,40   D11

                    //validate x pattern
                    //x    x   x+pixelcount
                    if (triangle.Vector1X == triangle.Vector2X && (triangle.Vector3X == (triangle.Vector1X + tGrid.PixelCount)))
                    {
                        //validate y pattern
                        //y    y-pixencount   y
                        if (triangle.Vector1Y == triangle.Vector3Y && (triangle.Vector2Y == (triangle.Vector1Y - tGrid.PixelCount)))
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    triangle.RightAngle = Triangle.RightAngleSide.Right;

                    //40,0,30,0,40,10     A8
                    //40,20,30,20,40,30   C8
                    //40,30,30,30,40,40   D8
                    //50,30,40,30,50,40   D10

                    //validate x pattern
                    //x    x-pixelcount   x
                    if (triangle.Vector1X == triangle.Vector3X && (triangle.Vector2X == (triangle.Vector1X - tGrid.PixelCount)))
                    {
                        //validate y pattern
                        //y    y    y+pixelcount
                        if (triangle.Vector1Y == triangle.Vector2Y && (triangle.Vector3Y == (triangle.Vector1Y + tGrid.PixelCount)))
                        {
                            return(true);
                        }
                    }
                }
            }

            //validation has failed
            return(false);
        }