public ITriangleCalculator Make(IGridReference gridReference)
 {
     if (gridReference.Column % 2 == 0)
     {
         return(new RightTriangleCalculator());
     }
     else
     {
         return(new LeftTriangleCalculator());
     }
 }
예제 #2
0
        public IGridShape Calculate(IGrid grid, IGridReference gridReference)
        {
            int topLeftX = (((gridReference.Column / 2) - 1) * grid.CellSize);
            int leftY    = (gridReference.GetNumericRow() - 1) * grid.CellSize;

            int bottomX      = topLeftX + grid.CellSize;
            int bottomRightY = leftY + grid.CellSize;

            return(new GridShape()
                   .AddCoordinate(new Coordinate(topLeftX, leftY))
                   .AddCoordinate(new Coordinate(bottomX, leftY))
                   .AddCoordinate(new Coordinate(bottomX, bottomRightY)));
        }
예제 #3
0
        public JsonResult Post([FromBody] CreateGridTriangleReferenceCalculationRequestBody request)
        {
            Grid grid = new Grid(request.GridHeight, request.GridWidth, request.CellSize);

            Triangle triangle = new Triangle()
                                .AddAngleCoordinate(new Coordinate(request.V1X, request.V1Y))
                                .AddTopLeftCoordinate(new Coordinate(request.V2X, request.V2Y))
                                .AddBottomRightCoordinate(new Coordinate(request.V3X, request.V3Y));

            IGridReference gridReference = this.Calculator.Calculate(grid, triangle);

            return(Json(gridReference));
        }
예제 #4
0
        public IGridShape Calculate(IGrid grid, IGridReference gridReference)
        {
            ITriangleCalculator triangleCalculator = this.CalculatorFactory.Make(gridReference);

            return(triangleCalculator.Calculate(grid, gridReference));
        }