public static Models.GenerateRowAndColumnResult GenerateRowAndColumn(Models.Coordinates coordinates) { int pixelMultiplier = int.Parse(WebConfigurationManager.AppSettings["pixelMultiplier"]); try { // // All we need to determine which triangle is being referenced is by (V1x,V1Y) and one of the other values // I'm choosing (V3x,V3y) because I'm going to need to confirm the lower Horizontal axis to determine the row // string row; int column; // // Calculate the column, If V1y == V3y, then it's odd. Otherwise the column is even. // bool isOdd = coordinates.V1y == coordinates.V3y ? true : false; // // Make sure we are dealing with a right triangle // bool shouldProceed = ValidateRightTriangle(coordinates, isOdd); if (!shouldProceed) { throw new ApplicationException(); } if (isOdd) { column = ((coordinates.V3x / pixelMultiplier) * 2) - 1; } else { column = (coordinates.V3x / pixelMultiplier) * 2; } // // Calculate the row // row = CalculateRowFromCoordinate(coordinates.V3y); Models.GenerateRowAndColumnResult result = new Models.GenerateRowAndColumnResult() { Column = column, Row = row, IsSuccessful = true }; return(result); } catch (Exception ex) { // Don't do anything with the exception at this time, just return an error return(new Models.GenerateRowAndColumnResult() { IsSuccessful = false }); } }
// POST api/values public Models.GenerateRowAndColumnResult Post(Models.Coordinates coordinates) { Models.GenerateRowAndColumnResult result = Repositories.TriangleRepository.GenerateRowAndColumn(coordinates); return(result); }