Hello,
In my code I create a PathGeometry that corresponds to the outline of a widened PathGeometry.
This outline contains several points into its PolyLineSegment. I need to minimize the number of points, whithout chaning the geometry of the segment.
Here is my testing code:
PathGeometry geo = new PathGeometry(); PathFigure fig = new PathFigure(); fig.StartPoint = new Point(100.0, 100.0); fig.Segments.Add(new LineSegment(new Point(150.0, 100.0), true)); fig.Segments.Add(new LineSegment(new Point(170.0, 120.0), true)); fig.Segments.Add(new LineSegment(new Point(170.0, 300.0), true)); fig.Segments.Add(new LineSegment(new Point(150.0, 320.0), true)); fig.Segments.Add(new LineSegment(new Point(100.0, 320.0), true)); fig.Segments.Add(new LineSegment(new Point(100.0, 100.0), true)); geo.Figures.Add(fig); //Widened Geometry Pen p = new Pen(Brushes.Red, 5.0d); p.EndLineCap = PenLineCap.Square; p.StartLineCap = PenLineCap.Square; PathGeometry pathGeoWidened = geo.GetWidenedPathGeometry(p); PathGeometry outlinedGeo = pathGeoWidened.GetOutlinedPathGeometry(); //Outside Geometry PolyLineSegment outterPolyLine = outlinedGeo.Figures[1].Segments[0] as PolyLineSegment; foreach (var item in outterPolyLine.Points) { Debug.WriteLine(String.Format("({0};{1})", item.X, item.Y)); }
The output is this:
(100;97,5)
(102,5;97,5)
(150;97,5)
(151,035537719727;97,5)
(171,767761230469;118,232231140137)
(172,5;118,964462280273)
(172,5;300)
(172,5;301,035522460938)
(151,767761230469;321,767761230469)
(151,035537719727;322,5)
(100;322,5)
(97,5;322,5)
(97,5;102,5)
(97,5;100)
(97,5;97,5)
Now, I need to exclude points that do not influence on the geometry of this segment. In this case, there should be only 6 points:
(151,035537719727;97,5)
(172,5;118,964462280273)
(172,5;301,035522460938)
(151,035537719727;322,5)
(97,5;322,5)
(97,5;97,5)
Any ideas on how to make this "cleaning" of the unnecessary points?
Thank you,
Igor
.NET Software developer for industrial internet and automation system.