private string GetCircumference() { Point p1 = Point.Empty; // previous point Point p2 = Point.Empty; // current point double sum = 0; PointFEnumerator enumerator = pointArray.GetEnumerator(); if (enumerator.MoveNext()) { p1 = Point.Ceiling(enumerator.Current); p1.Offset(MovingOffset); } while (enumerator.MoveNext()) { p2 = Point.Ceiling(enumerator.Current); p2.Offset(MovingOffset); float x = System.Math.Abs(p2.X - p1.X); float y = System.Math.Abs(p2.Y - p1.Y); sum += Math.Sqrt(x * x + y * y) / UnitOfMeasureFactor; p1 = p2; } enumerator.Reset(); if (enumerator.MoveNext()) { p2 = Point.Ceiling(enumerator.Current); p2.Offset(MovingOffset); } return(string.Format("{0:F2} {1}", sum, pictureBox.UnitOfMeasure.ToString())); }
/// <summary> /// draw object /// </summary> /// <param name="g"></param> /// <param name="pictureBox"></param> public override void Draw(Graphics g, ZWPictureBox pictureBox) { Point p1 = Point.Empty; // previous point Point p2 = Point.Empty; // current point g.SmoothingMode = SmoothingMode.AntiAlias; using (Pen pen = new Pen(GraphicsProperties.Color, GraphicsProperties.PenWidth)) { PointFEnumerator enumerator = pointArray.GetEnumerator(); if (enumerator.MoveNext()) { p1 = Point.Ceiling(enumerator.Current); p1.Offset(MovingOffset); } while (enumerator.MoveNext()) { p2 = Point.Ceiling(enumerator.Current); p2.Offset(MovingOffset); g.DrawLine(pen, p1, p2); p1 = p2; } enumerator.Reset(); if (enumerator.MoveNext()) { p2 = Point.Ceiling(enumerator.Current); p2.Offset(MovingOffset); g.DrawLine(pen, p1, p2); } } }
/// <summary> /// Create graphic object used for hit test /// </summary> protected void CreateObjects() { Invalidate(); // invalidate every time, since draw area may resize if (AreaPath != null) { return; } // Create closed path which contains all polygon vertexes AreaPath = new GraphicsPath(); PointF p1 = PointF.Empty; // previous point PointF p2 = PointF.Empty; // current point PointFEnumerator enumerator = pointArray.GetEnumerator(); if (enumerator.MoveNext()) { p1 = enumerator.Current; } while (enumerator.MoveNext()) { p2 = enumerator.Current; AreaPath.AddLine(p1, p2); p1 = p2; } AreaPath.CloseFigure(); // Create region from the path AreaRegion = new Region(AreaPath); }