<commit_before><?php

namespace Davaxi\Sparkline;

/**
 * Class PictureTrait.
 */
class Picture
{
    const DOT_RADIUS_TO_WIDTH = 2;

    /**
     * @var resource
     */
    protected $resource;

    /**
     * @var int
     */
    protected $height;

    /**
     * @var int
     */
    protected $width;

    /**
     * Picture constructor.
     * @param int $width
     * @param int $height
     */
    public function __construct(int $width, int $height)
    {
        $this->width = $width;
        $this->height = $height;
        $this->resource = imagecreatetruecolor($width, $height);
    }

    /**
     * @param array $setColor
     *
     * @return int
     */
    protected function getBackground(array $setColor = []): int
    {
        if ($setColor) {
            return imagecolorallocate(
                $this->resource,
                $setColor[0],
                $setColor[1],
                $setColor[2]
            );
        }

        return imagecolorallocatealpha(
            $this->resource,
            0,
            0,
            0,
            127
        );
    }

    /**
     * @param array $lineColor
     *
     * @return int
     */
    public function getLineColor(array $lineColor): int
    {
        return imagecolorallocate(
            $this->resource,
            $lineColor[0],
            $lineColor[1],
            $lineColor[2]
        );
    }

    /**
     * @param array $backgroundColor
     */
    public function applyBackground(array $backgroundColor)
    {
        imagesavealpha($this->resource, true);
        imagefill(
            $this->resource,
            0,
            0,
            $this->getBackground($backgroundColor)
        );
    }

    /**
     * @param int $lineThickness
     */
    public function applyThickness(int $lineThickness)
    {
        imagesetthickness($this->resource, $lineThickness);
    }

    /**
     * @param array $polygon
     * @param array $fillColor
     * @param int $count
     */
    public function applyPolygon(array $polygon, array $fillColor, int $count)
    {
        if (!$fillColor) {
            return;
        }
        $fillColor = imagecolorallocate($this->resource, $fillColor[0], $fillColor[1], $fillColor[2]);
        imagefilledpolygon($this->resource, $polygon, $count + 2, $fillColor);
    }

    /**<commit_msg>Fixes deprecation warning on PHP 8.1<commit_after><?php

namespace Davaxi\Sparkline;

/**
 * Class PictureTrait.
 */
class Picture
{
    const DOT_RADIUS_TO_WIDTH = 2;

    /**
     * @var resource
     */
    protected $resource;

    /**
     * @var int
     */
    protected $height;

    /**
     * @var int
     */
    protected $width;

    /**
     * Picture constructor.
     * @param int $width
     * @param int $height
     */
    public function __construct(int $width, int $height)
    {
        $this->width = $width;
        $this->height = $height;
        $this->resource = imagecreatetruecolor($width, $height);
    }

    /**
     * @param array $setColor
     *
     * @return int
     */
    protected function getBackground(array $setColor = []): int
    {
        if ($setColor) {
            return imagecolorallocate(
                $this->resource,
                $setColor[0],
                $setColor[1],
                $setColor[2]
            );
        }

        return imagecolorallocatealpha(
            $this->resource,
            0,
            0,
            0,
            127
        );
    }

    /**
     * @param array $lineColor
     *
     * @return int
     */
    public function getLineColor(array $lineColor): int
    {
        return imagecolorallocate(
            $this->resource,
            $lineColor[0],
            $lineColor[1],
            $lineColor[2]
        );
    }

    /**
     * @param array $backgroundColor
     */
    public function applyBackground(array $backgroundColor)
    {
        imagesavealpha($this->resource, true);
        imagefill(
            $this->resource,
            0,
            0,
            $this->getBackground($backgroundColor)
        );
    }

    /**
     * @param int $lineThickness
     */
    public function applyThickness(int $lineThickness)
    {
        imagesetthickness($this->resource, $lineThickness);
    }

    /**
     * @param array $polygon
     * @param array $fillColor
     * @param int $count
     */
    public function applyPolygon(array $polygon, array $fillColor, int $count)
    {
        if (!$fillColor) {
            return;
        }
        $fillColor = imagecolorallocate($this->resource, $fillColor[0], $fillColor[1], $fillColor[2]);
        if (version_compare(PHP_VERSION, '8.1.0') === -1) {
            imagefilledpolygon($this->resource, $polygon, $count + 2, $fillColor);
        } else {
            imagefilledpolygon($this->resource, $polygon, $fillColor);
        }
    }

    /**
{'fraction_non_alphanumeric': 0.12733620866707743, 'fraction_numerical': 0.009036763195728076, 'mean_word_length': 1.5987193169690501, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707362', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1410, 'n_words': 287}