public static List <PointF> AbsoluteBezierPoints(string str, bool svgOriginalCulture) { if (svgOriginalCulture) { StringBuilder tmpStr = new StringBuilder(str); tmpStr.Replace(',', ':'); tmpStr.Replace('.', ','); str = tmpStr.ToString(); } // Використати константу. const string matchStartPoint = @"(M|m) ((-?\d+,?\d*):(-?\d+,?\d*) )+"; const string matchPointSequence = @"(C|c) ((-?\d+,?\d*):(-?\d+,?\d*) )+"; List <PointF> result = new List <PointF>(); PointF[] pointsArray; MatchCollection startPoint = Regex.Matches(str, matchStartPoint); pointsArray = PointF.Points(startPoint[0].Value, false); result.Add(pointsArray[0]); MatchCollection points = Regex.Matches(str, matchPointSequence); foreach (Match m in points) { // Пропущено фігурні дужки. if (m.Value.StartsWith("C ")) { result.AddRange(PointF.Points(m.Value, false)); } else { pointsArray = PointF.Points(m.Value, false); var tmp = result[result.Count - 1]; var tmpSize = new SizeF(); // В даному випадку доцільніше використати var. for (var i = 0; i < pointsArray.Length; i++) { tmpSize.Width = pointsArray[i].X; tmpSize.Height = pointsArray[i].Y; result.Add(PointF.Add(tmp, tmpSize)); // Пропущено фігурні дужки if ((i + 1) % 3 == 0) { tmp = result[result.Count - 1]; } } } } return(result); }
public void Load(string filePath) { StreamReader reader = null; try { reader = new StreamReader(filePath); char[] coordSeparator = { ':' }; string line; // Field // line = reader.ReadLine(); if (line.StartsWith("Field: ")) { line = line.Substring("Field: ".Length); PointF[] coords = PointF.Points(line, true); _field = new Field((int)coords[0].X, (int)coords[0].Y); } else { throw new FormatException(filePath); } // Frog Location // line = reader.ReadLine(); if (line.StartsWith("FrogLocation: ")) { line = line.Substring("FrogLocation: ".Length); PointF[] coords = PointF.Points(line, true); _frogLocation = coords[0]; } else { throw new FormatException(filePath); } // Bonus Locations // line = reader.ReadLine(); if (line.StartsWith("BonusLocations: ")) { line = line.Substring("BonusLocations: ".Length); _bonusLocations = PointF.Points(line, true); } else { throw new FormatException(filePath); } // Path // line = reader.ReadLine(); if (line.StartsWith("BezierCombinedPath: ")) { line = line.Substring("BezierCombinedPath: ".Length); string[] bezCombSeparator = { "==" }; string[] bezCombParts = line.Split(bezCombSeparator, StringSplitOptions.None); _path = new BezierCombinedPath(PointF.Points(bezCombParts[0], true)); ((BezierCombinedPath)_path).SetPointsSVG(PointF.Points(bezCombParts[1], true)); } else { throw new FormatException(filePath); } } catch (Exception exception) { throw new Exception("An error while loading config from " + filePath, exception); } finally { if (reader != null) { reader.Close(); } } }