// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors.ImageSharp.Processing
{
///
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
///
///
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
/// section 1 will be width long (making a square) and will be filled by the brush
/// section 2 will be width * 2 long and will be empty
/// section 3 will be width/2 long and will be filled
/// the the pattern will immediately repeat without gap.
///
public class Pen : IPen
{
private readonly float[] pattern;
///
/// Initializes a new instance of the class.
///
/// The color.
/// The width.
/// The pattern.
public Pen(Color color, float width, float[] pattern)
: this(new SolidBrush(color), width, pattern)
{
}
///
/// Initializes a new instance of the class.
///
/// The brush.
/// The width.
/// The pattern.
public Pen(IBrush brush, float width, float[] pattern)
{
this.StrokeFill = brush;
this.StrokeWidth = width;
this.pattern = pattern;
}
///
/// Initializes a new instance of the class.
///
/// The color.
/// The width.
public Pen(Color color, float width)
: this(new SolidBrush(color), width)
{
}
///
/// Initializes a new instance of the class.
///
/// The brush.
/// The width.
public Pen(IBrush brush, float width)
: this(brush, width, Pens.EmptyPattern)
{
}
///
public IBrush StrokeFill { get; }
///
public float StrokeWidth { get; }
///
public ReadOnlySpan StrokePattern => this.pattern;
}
}