public Analyzer(double meanX, double meanY, GraphicsPath path) { Counters = new RunningCount[Enum.GetValues(typeof(AnalysisMetric)).Length]; foreach (AnalysisMetric metric in Enum.GetValues(typeof(AnalysisMetric))) { Counters[(int)metric] = new RunningCount(metric); } MeanX = meanX; MeanY = meanY; path.Flatten(); using (GraphicsPathIterator PathIterator = new GraphicsPathIterator(path)) { using (GraphicsPath Subpath = new GraphicsPath()) { Paths = new List <PointF[]>(); bool Closed; while (PathIterator.NextSubpath(Subpath, out Closed) > 0) { Paths.Add(Subpath.PathPoints); Subpath.Reset(); } } } }
public DrawableMulti ToMultiPolygon(bool disposePath = true) { DrawableMulti multi = new DrawableMulti(); if (Path == null) { return(null); } using (GraphicsPathIterator iterator = new GraphicsPathIterator(Path)) { GraphicsPath subpath = new GraphicsPath(); bool closed; while (iterator.NextSubpath(subpath, out closed) != 0) { DrawablePolygon shape = new DrawablePolygon { Points = subpath.PathPoints, Brush = Brush, Pen = Pen, PenClosed = closed }; multi.Shapes.Add(shape); } subpath.Dispose(); } if (disposePath) { Path?.Dispose(); } return(multi); }
public DrawableMulti ToMulti(MultiGen cb, bool disposePath = true) { DrawableMulti multi = new DrawableMulti(); if (Path == null) { return(null); } using (GraphicsPathIterator iterator = new GraphicsPathIterator(Path)) { GraphicsPath subpath = new GraphicsPath(); bool closed; int i = 0; while (iterator.NextSubpath(subpath, out closed) != 0) { Drawable shape = cb(i++, subpath, Brush, Pen, closed); if (shape != null) { multi.Shapes.Add(shape); } } subpath.Dispose(); } if (disposePath) { Path?.Dispose(); } return(multi); }
public virtual void HasCurve() { GraphicsPath path = new GraphicsPath(); GraphicsPathIterator iterator = new GraphicsPathIterator(path); Assert.IsFalse(iterator.HasCurve()); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddLine(new Point(400, 200), new Point(10, 100)); iterator = new GraphicsPathIterator(path); Assert.IsFalse(iterator.HasCurve()); path.StartFigure(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.AddLine(new Point(400, 400), new Point(400, 10)); iterator = new GraphicsPathIterator(path); Assert.IsTrue(iterator.HasCurve()); }
public virtual void Rewind() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPathIterator iterator = new GraphicsPathIterator(path); int i; int j; iterator.NextMarker(out i, out j); iterator.NextMarker(out i, out j); iterator.Rewind(); iterator.NextMarker(out i, out j); Assert.AreEqual(0, i); Assert.AreEqual(3, j); }
// </snippet2> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.HasCurve // <snippet3> private void HasCurveExample(PaintEventArgs e) { // Create a path and add three lines, // a rectangle and an ellipse. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Test for a curve. bool myHasCurve = myPathIterator.HasCurve(); // Show the test result. MessageBox.Show(myHasCurve.ToString()); }
// </snippet5> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextPathType(System.Byte@,System.Int32@,System.Int32@) // <snippet6> public void NextPathTypeExample(PaintEventArgs e) { // Create the GraphicsPath. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, and an ellipse. myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // List all of the path points to the screen. ListPathPoints(e, myPath, null, 20, 1); // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the Iterator. myPathIterator.Rewind(); // Iterate the subpaths and types, and list the results to // the screen. int i, j = 20; int mySubPaths, subPathStartIndex, subPathEndIndex; Boolean IsClosed; byte subPathPointType; int pointTypeStartIndex, pointTypeEndIndex, numPointsFound; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); j = 20; for (i = 0; i < 3; i++) { mySubPaths = myPathIterator.NextSubpath( out subPathStartIndex, out subPathEndIndex, out IsClosed); numPointsFound = myPathIterator.NextPathType( out subPathPointType, out pointTypeStartIndex, out pointTypeEndIndex); e.Graphics.DrawString( "SubPath: " + i + " Points Found: " + numPointsFound.ToString() + " Type of Points: " + subPathPointType.ToString(), myFont, myBrush, 200, j); j += 20; } // List the total number of path points to the screen. ListPathPoints(e, myPath, myPathIterator, 200, 2); }
///<summary> /// Converts a flat path to a <see cref="IGeometry"/>. ///</summary> /// <param name="pathIt">The path iterator of the path to convert</param> /// <returns>A Geometry representing the path</returns> public IGeometry Read(GraphicsPathIterator pathIt) { var pathPtSeq = ToCoordinates(pathIt); var polys = new List <IGeometry>(); var seqIndex = 0; while (seqIndex < pathPtSeq.Count) { // assume next seq is shell // TODO: test this var pts = pathPtSeq[seqIndex]; var shell = _geometryFactory.CreateLinearRing(pts); seqIndex++; var holes = new List <ILinearRing>(); Coordinate[] holePts; // add holes as long as rings are CCW while (seqIndex < pathPtSeq.Count && IsHole(holePts = pathPtSeq[seqIndex])) { var hole = _geometryFactory.CreateLinearRing(holePts); holes.Add(hole); seqIndex++; } var holeArray = holes.ToArray();//GeometryFactory.ToLinearRingArray(holes); polys.Add(_geometryFactory.CreatePolygon(shell, holeArray)); } return(_geometryFactory.BuildGeometry(polys)); }
/// <summary> /// Insert new map area items into the collection. /// </summary> /// <param name="index">Index to insert at.</param> /// <param name="toolTip">Tool tip.</param> /// <param name="url">Jump URL.</param> /// <param name="attributes">Other area attributes.</param> /// <param name="postBackValue">The post back value associated with this item.</param> /// <param name="path">Area coordinates as graphics path.</param> /// <param name="absCoordinates">Absolute coordinates in the graphics path.</param> /// <param name="graph">Chart graphics object.</param> internal void InsertPath( int index, string toolTip, string url, string attributes, string postBackValue, GraphicsPath path, bool absCoordinates, ChartGraphics graph) { // If there is more then one graphical path split them and create // image maps for every graphical path separately. GraphicsPathIterator iterator = new GraphicsPathIterator(path); // There is more then one path. if (iterator.SubpathCount > 1) { GraphicsPath subPath = new GraphicsPath(); while (iterator.NextMarker(subPath) > 0) { InsertSubpath(index, toolTip, url, attributes, postBackValue, subPath, absCoordinates, graph); subPath.Reset(); } } // There is only one path else { InsertSubpath(index, toolTip, url, attributes, postBackValue, path, absCoordinates, graph); } }
public void DrawStep(Graphics graphics, Font font, string word, int[] order) { var isClosed = false; var pen = new Pen(Color.Red); var brush = new SolidBrush(Color.Black); var path = new GraphicsPath(); var subPath = new GraphicsPath(); path.AddString(word, font.FontFamily, (int)font.Style, font.Size, new PointF(0, 0), StringFormat.GenericDefault); var iterator = new GraphicsPathIterator(path); var rect = path.GetBounds(); graphics.PageUnit = font.Unit; graphics.SmoothingMode = SmoothingMode.HighQuality; DrawGrid(graphics, rect); graphics.DrawPath(pen, path); for (var i = 0; i < iterator.SubpathCount; i++) { Thread.Sleep(1000); iterator.Rewind(); for (var j = 0; j < order[i]; j++) { iterator.NextSubpath(subPath, out isClosed); } graphics.FillPath(brush, subPath); } }
public static List <List <IntPoint> > ConvertToClipperPolygons(GraphicsPath path) { var Polygon = new List <IntPoint>(); var Polygons = new List <List <IntPoint> >(); var it = new GraphicsPathIterator(path); it.Rewind(); for (int i = 0; i < it.SubpathCount; i++) { bool isClosed; int startIndex; int endIndex; it.NextSubpath(out startIndex, out endIndex, out isClosed); Polygon.AddRange( path.PathPoints .Skip(startIndex) .Take((endIndex - startIndex) + 1) .Select(x => new IntPoint(Convert.ToInt64(x.X * Scale), Convert.ToInt64(x.Y * Scale))) ); Polygons.Add(new List <IntPoint>(Polygon)); Polygon.Clear(); } it.Dispose(); return(Polygons); }
public void NextMarker_Null() { using (GraphicsPath gp = new GraphicsPath()) { gp.AddLines(pts_2f); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { Assert.AreEqual(0, gpi.NextMarker(null)); } } }
///<summary> /// Converts a <see cref="GraphicsPath"/> to a Geometry, flattening it first. ///</summary> /// <param name="shp">The <see cref="GraphicsPath"/></param> /// <param name="flatness">The flatness parameter to use</param> /// <param name="geomFact">The GeometryFactory to use</param> /// <returns>A Geometry representing the shape</returns> public static IGeometry Read(GraphicsPath shp, double flatness, IGeometryFactory geomFact) { var path = (GraphicsPath)shp.Clone(); path.Flatten(InvertY, (float)flatness); var pathIt = new GraphicsPathIterator(path); return(Read(pathIt, geomFact)); }
public GraphicsPath RandomWarp(GraphicsPath path) { // Add line // int PsCount = 10; PointF[] curvePs = new PointF[PsCount * 2]; for (int u = 0; u < PsCount; u++) { curvePs[u].X = u * (Width / PsCount); curvePs[u].Y = Height / 2; } for (int u = PsCount; u < (PsCount * 2); u++) { curvePs[u].X = (u - PsCount) * (Width / PsCount); curvePs[u].Y = Height / 2 + 2; } double eps = Height * 0.05; double amp = rnd.NextDouble() * (double)(Height / 3); double size = rnd.NextDouble() * (double)(Width / 4) + Width / 8; double offset = (double)(Height / 3); PointF[] pn = new PointF[path.PointCount]; byte[] pt = new byte[path.PointCount]; GraphicsPath np2 = new GraphicsPath(); GraphicsPathIterator iter = new GraphicsPathIterator(path); for (int i = 0; i < iter.SubpathCount; i++) { GraphicsPath sp = new GraphicsPath(); bool closed; iter.NextSubpath(sp, out closed); Matrix m = new Matrix(); m.RotateAt(Convert.ToSingle(rnd.NextDouble() * 30 - 15), sp.PathPoints[0]); m.Translate(-1 * i, 0);//uncomment sp.Transform(m); np2.AddPath(sp, true); } for (int i = 0; i < np2.PointCount; i++) { //pn[i] = Noise( path.PathPoints[i] , eps); pn[i] = Wave(np2.PathPoints[i], amp, size); pt[i] = np2.PathTypes[i]; } GraphicsPath newpath = new GraphicsPath(pn, pt); return newpath; }