/// <summary> /// Verifies the validity of a given TriangleName /// </summary> /// <param name="triangleName"></param> /// <returns>True / False</returns> public static bool VerifyTriangleName(char[] triangleName) { if (triangleName.Count() > 1 && triangleName.Count() < 4) { if (RegexValidators.ValidateLetter(triangleName[0]) && RegexValidators.Validate1stNumber(triangleName[1])) { Int32.TryParse(triangleName[1].ToString(), out int firstNum); if (triangleName.Count() == 2 || (RegexValidators.Validate2ndNumber(triangleName[2]) && firstNum < 2)) { return(true); } } } return(false); }
/// <summary> /// Verifies the validity of a given set of coordinates /// </summary> /// <param name="coordinates"></param> /// <returns>True / False</returns> public static bool VerifyCoordinates(string coordinates) { if (RegexValidators.ValidateCoordinateCharacters(coordinates)) { coordinates = coordinates.Replace("(", string.Empty); coordinates = coordinates.Replace(")", string.Empty); string[] splitCoordinates = coordinates.Split(','); // Check there is 6 coordinates if (splitCoordinates.Length != minMaxTriangleCoordinates) { return(false); } int[] convertedCoordinates = new int[splitCoordinates.Length]; for (int i = 0; i < splitCoordinates.Length; i++) { // Check if last character of the coordinate is 0 and coordinate length is under 3 if (splitCoordinates[i].Length == 1 && !splitCoordinates[i][0].Equals('0')) { return(false); } else if (!splitCoordinates[i][splitCoordinates[i].Length - 1].Equals('0') || splitCoordinates[i].Length > 2) { return(false); } Int32.TryParse(splitCoordinates[i], out convertedCoordinates[i]); } int maxX = Math.Max(convertedCoordinates[0], Math.Max(convertedCoordinates[2], convertedCoordinates[4])); // Check if odd triangle (eg A1, A3) if ((convertedCoordinates[0] == maxX && convertedCoordinates[2] != maxX && convertedCoordinates[4] != maxX) || (convertedCoordinates[0] != maxX && convertedCoordinates[2] == maxX && convertedCoordinates[4] != maxX) || (convertedCoordinates[0] != maxX && convertedCoordinates[2] != maxX && convertedCoordinates[4] == maxX)) { // validate X coordinates - 1 should be 10 higher than the other 2 if (convertedCoordinates[0] == convertedCoordinates[2] || convertedCoordinates[0] == convertedCoordinates[4]) // if X1 == X2 or X3 { if (!(convertedCoordinates[2] == (convertedCoordinates[0] + 10)) && !(convertedCoordinates[4] == (convertedCoordinates[0] + 10))) // if (X1 + 10) != X2 or X3 then invalid { return(false); } } else // X2 and X3 must be equal and X1 must be 10 higher { if (!(convertedCoordinates[2] == convertedCoordinates[4]) || !(convertedCoordinates[0] == (convertedCoordinates[2] + 10))) // if X2 != X3 OR X1 != (X2 + 10) then invalid { return(false); } } // validate Y coordinates - 1 should be 10 less than the other 2 if (convertedCoordinates[1] == convertedCoordinates[3] || convertedCoordinates[1] == convertedCoordinates[5]) // if Y1 == Y2 or Y3 { if (!(convertedCoordinates[3] == (convertedCoordinates[1] - 10)) && !(convertedCoordinates[5] == (convertedCoordinates[1] - 10))) // if (Y1 - 10) != Y2 or Y3 then invalid { return(false); } } else // Y2 and Y3 must be equal and Y1 must be 10 lower { if (!(convertedCoordinates[3] == convertedCoordinates[5]) || !(convertedCoordinates[1] == (convertedCoordinates[3] - 10))) // if Y2 != Y3 OR Y1 != (Y2 - 10) then invalid { return(false); } } } else // Else even triangle (eg A2, A6) { // validate X coordinates - 1 should be 10 less than the other 2 if (convertedCoordinates[0] == convertedCoordinates[2] || convertedCoordinates[0] == convertedCoordinates[4]) // if X1 == X2 or X3 { if (!(convertedCoordinates[2] == (convertedCoordinates[0] - 10)) && !(convertedCoordinates[4] == (convertedCoordinates[0] - 10))) // if (X1 - 10) != X2 or X3 then invalid { return(false); } } else // X2 and X3 must be equal and X1 must be 10 lower { if (!(convertedCoordinates[2] == convertedCoordinates[4]) || !(convertedCoordinates[0] == (convertedCoordinates[2] - 10))) // if X2 != X3 OR X1 != (X2 - 10) then invalid { return(false); } } // validate Y coordinates - 1 should be 10 higher than the other 2 if (convertedCoordinates[1] == convertedCoordinates[3] || convertedCoordinates[1] == convertedCoordinates[5]) // if Y1 == Y2 or Y3 { if (!(convertedCoordinates[3] == (convertedCoordinates[1] + 10)) && !(convertedCoordinates[5] == (convertedCoordinates[1] + 10))) // if (Y1 + 10) != Y2 or Y3 then invalid { return(false); } } else // Y2 and Y3 must be equal and Y1 must be 10 higher { if (!(convertedCoordinates[3] == convertedCoordinates[5]) || !(convertedCoordinates[1] == (convertedCoordinates[3] + 10))) // if Y2 != Y3 OR Y1 != (Y2 + 10) then invalid { return(false); } } } return(true); } return(false); }