Source/OxyPlot.Avalonia/CanvasRenderContext.cs
/// <summary>
/// Draws a collection of polygons, where all polygons have the same stroke and fill.
/// This performs better than calling DrawPolygon multiple times.
/// </summary>
/// <param name="polygons">The polygons.</param>
/// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygons will not be filled.</param>
/// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygons will not be stroked.</param>
/// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
/// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
/// <param name="lineJoin">The line join type.</param>
/// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
Draws a collection of polygons, where all polygons have the same stroke and fill.
This performs better than calling DrawPolygon multiple times.
Draws a collection of polygons where all polygons have the same stroke and fill . This performs better than calling DrawPolygon multiple times .
public void DrawPolygons(
            IList<IList<ScreenPoint>> polygons,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased)
        {
            var usg = UseStreamGeometry;
            Path path = null;
            StreamGeometry streamGeometry = null;
            StreamGeometryContext sgc = null;
            PathGeometry pathGeometry = null;
            var count = 0;
            foreach (var polygon in polygons)
            {
                if (path == null)
                {
                    path = CreateAndAdd<Path>();
                    SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased);
                    if (!fill.IsUndefined())
                    {
                        path.Fill = GetCachedBrush(fill);
                    }
                    if (usg)
                    {
                        streamGeometry = new StreamGeometry();
                        sgc = streamGeometry.Open();
                        sgc.SetFillRule(FillRule.NonZero);
                    }
                    else
                    {
                        pathGeometry = new PathGeometry { FillRule = FillRule.NonZero };
                    }
                }
                PathFigure figure = null;
                var first = true;
                foreach (var p in polygon)
                {
                    var point = aliased ? ToPixelAlignedPoint(p) : ToPoint(p);
                    if (first)
                    {
                        if (usg)
                        {
                            sgc.BeginFigure(point, !fill.IsUndefined());
                        }
                        else
                        {
                            figure = new PathFigure
                            {
                                StartPoint = point,
                                IsFilled = !fill.IsUndefined(),
                                IsClosed = true
                            };
                            pathGeometry.Figures.Add(figure);
                        }
                        first = false;
                    }
                    else
                    {
                        if (usg)
                        {
                            sgc.LineTo(point);
                        }
                        else
                        {
                            figure.Segments.Add(new LineSegment { Point = point });
                        }
                    }
                }
                count++;
                if (count > MaxFiguresPerGeometry)
                {
                    if (usg)
                    {
                        sgc.Dispose();
                        path.Data = streamGeometry;
                    }
                    else
                    {
                        path.Data = pathGeometry;
                    }
                    path = null;
                    count = 0;
                }
            }
            if (path != null)
            {
                if (usg)
                {
                    sgc.Dispose();
                    path.Data = streamGeometry;
                }
                else
                {
                    path.Data = pathGeometry;
                }
            }
        }
public void DrawPolygons ( IList < IList < ScreenPoint > > polygons , OxyColor fill , OxyColor stroke , double thickness , double [ ] dashArray , LineJoin lineJoin , bool aliased ) { var usg = UseStreamGeometry ; Path path = null ; StreamGeometry streamGeometry = null ; StreamGeometryContext sgc = null ; PathGeometry pathGeometry = null ; var count = 0 ; foreach ( var polygon in polygons ) { if ( path == null ) { path = CreateAndAdd < Path > ( ) ; SetStroke ( path , stroke , thickness , lineJoin , dashArray , 0 , aliased ) ; if ( ! fill . IsUndefined ( ) ) { path . Fill = GetCachedBrush ( fill ) ; } if ( usg ) { streamGeometry = new StreamGeometry ( ) ; sgc = streamGeometry . Open ( ) ; sgc . SetFillRule ( FillRule . NonZero ) ; } else { pathGeometry = new PathGeometry { FillRule = FillRule . NonZero } ; } } PathFigure figure = null ; var first = true ; foreach ( var p in polygon ) { var point = aliased ? ToPixelAlignedPoint ( p ) : ToPoint ( p ) ; if ( first ) { if ( usg ) { sgc . BeginFigure ( point , ! fill . IsUndefined ( ) ) ; } else { figure = new PathFigure { StartPoint = point , IsFilled = ! fill . IsUndefined ( ) , IsClosed = true } ; pathGeometry . Figures . Add ( figure ) ; } first = false ; } else { if ( usg ) { sgc . LineTo ( point ) ; } else { figure . Segments . Add ( new LineSegment { Point = point } ) ; } } } count ++ ; if ( count > MaxFiguresPerGeometry ) { if ( usg ) { sgc . Dispose ( ) ; path . Data = streamGeometry ; } else { path . Data = pathGeometry ; } path = null ; count = 0 ; } } if ( path != null ) { if ( usg ) { sgc . Dispose ( ) ; path . Data = streamGeometry ; } else { path . Data = pathGeometry ; } } }
Draws a collection of polygons, where all polygons have the same stroke and fill.
Draws a collection of polygons where all polygons have the same stroke and fill .
// Must limit the number of figures, otherwise drawing errors...
polygons
IList<IList<ScreenPoint>>
None
fill
OxyColor
The fill color. If set to OxyColors.Undefined
The fill color . If set to OxyColors . Undefined
stroke
OxyColor
The stroke color. If set to OxyColors.Undefined
The stroke color . If set to OxyColors . Undefined
thickness
double
The stroke thickness (in device independent units, 1/96 inch).
The stroke thickness ( in device independent units 1 / 96 inch ) .
dashArray
double[]
The dash array (in device independent units, 1/96 inch).
The dash array ( in device independent units 1 / 96 inch ) .
lineJoin
LineJoin
The line join type.
The line join type .
aliased
bool
if set to true
if set to true