public static void PointDTest() { Console.WriteLine("++++++++++++++++++++PointD++++++++++++++++++++++"); PointD c1 = new PointD(102.01, 2990.19945); Console.WriteLine("Point 01:{0}", c1.ToString()); try { PointD c2 = PointD.Parse(c1.ToString()); Console.WriteLine("Point 02:{0}", c2.ToString()); if (c2 == c1) { Console.WriteLine("01 == 02"); } else { Console.WriteLine("01 != 02"); } } catch (Exception ex) { Console.WriteLine("PointD.Parse failed, {0}.", ex.Message); } Console.WriteLine("==============================================="); }
/// <summary> /// 解析线段的字符串形式 /// </summary> /// <param name="value">字符串</param> /// <returns>如果解析成功,返回LineD类型,否则将抛出异常</returns> /// <exception cref="System.FormatException">非法的字符串格式。</exception> public static LineD Parse(String value) { Regex reg = new Regex(RegularExpressionString, RegexOptions.Compiled); if (reg.IsMatch(value) == false) { throw new FormatException(String.Format("{0}'s string format is illegal. {1}", typeof(PointD).FullName, value)); } MatchCollection collection = reg.Matches(value); return(new LineD(PointD.Parse(collection[0].Groups["Starting"].Value), PointD.Parse(collection[0].Groups["End"].Value))); }
/// <summary> /// 解析多线段的字符串形式 /// </summary> /// <param name="value">字符串</param> /// <returns>如果解析成功,返回PolylineD类型,否则将抛出异常</returns> /// <exception cref="System.FormatException">非法的字符串格式。</exception> public static PolylineD Parse(String value) { if (value == "") { return(new PolylineD(null)); } Regex reg = new Regex(RegularExpressionString, RegexOptions.Compiled); if (reg.IsMatch(value) == false) { throw new FormatException(String.Format("{0}'s string format is illegal. {1}", typeof(PolylineD).FullName, value)); } MatchCollection collection = reg.Matches(value); CaptureCollection vertexs = collection[0].Groups["Point"].Captures; List <PointD> points = new List <PointD>(); for (int i = 0; i < vertexs.Count; ++i) { points.Add(PointD.Parse(vertexs[i].Value)); } return(new PolylineD(points.ToArray())); }