public static void PointITest() { Console.WriteLine("++++++++++++++++++++PointI++++++++++++++++++++++"); PointI c1 = new PointI(102, 2990); Console.WriteLine("Point 01:{0}", c1.ToString()); try { PointI c2 = PointI.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("PointI.Parse failed, {0}.", ex.Message); } Console.WriteLine("==============================================="); }
/// <summary> /// 解析线段的字符串形式 /// </summary> /// <param name="value">字符串</param> /// <returns>如果解析成功,返回LineI类型,否则将抛出异常</returns> /// <exception cref="System.FormatException">非法的字符串格式。</exception> public static LineI 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(PointI).FullName, value)); } MatchCollection collection = reg.Matches(value); return(new LineI(PointI.Parse(collection[0].Groups["Starting"].Value), PointI.Parse(collection[0].Groups["End"].Value))); }
/// <summary> /// 解析多边形的字符串形式 /// </summary> /// <param name="value">字符串</param> /// <returns>如果解析成功,返回PolygonI类型,否则将抛出异常</returns> /// <exception cref="System.FormatException">非法的字符串格式。</exception> public static PolygonI Parse(String value) { if (value == "") { return(new PolygonI(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(PolygonI).FullName, value)); } MatchCollection collection = reg.Matches(value); CaptureCollection vertexs = collection[0].Groups["Vertex"].Captures; List <PointI> points = new List <PointI>(); for (int i = 0; i < vertexs.Count; ++i) { points.Add(PointI.Parse(vertexs[i].Value)); } return(new PolygonI(points.ToArray())); }
/// <summary> /// Constructor /// </summary> /// <param name="location">位置</param> /// <param name="size">大小</param> public RectangleI(PointI location, SizeI size) : this(location.X, location.Y, size.Width, size.Height) { }
/// <summary> /// Constructor /// </summary> /// <param name="starting">开始</param> /// <param name="end">结束</param> public LineI(PointI starting, PointI end) { m_Starting = starting; m_End = end; }
/// <summary> /// Constructor /// </summary> /// <param name="center">中心点</param> /// <param name="radius">半径</param> public CircleI(PointI center, Int32 radius) { m_X = center.X; m_Y = center.Y; m_Radius = radius; }