<commit_before><?php

/*
 * This file is part of the Imagine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Imagine\Imagick;

use Imagine\Color;
use Imagine\Point;
use Imagine\Draw\DrawerInterface;
use Imagine\Exception\InvalidArgumentException;
use Imagine\Exception\RuntimeException;

final class Drawer implements DrawerInterface
{
    private $imagick;

    public function __construct(\Imagick $imagick)
    {
        $this->imagick = $imagick;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::arc()
     */
    public function arc(Point $center, $width, $height, $start, $end, Color $color)
    {
        $x = $center->getX();
        $y = $center->getY();

        try {
            $arc = new \ImagickDraw();
            $arc->setStrokeColor($this->getColor($color));
            $arc->setStrokeWidth(1);
            $arc->setFillColor('transparent');
            $arc->arc($x - $width / 2, $y - $height / 2, $x + $width / 2, $y + $height / 2, $start, $end);

            $this->imagick->drawImage($arc);

            $arc->clear();
            $arc->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw arc operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::chord()
     */
    public function chord(Point $center, $width, $height, $start, $end, Color $color, $fill = false)
    {
        $x = $center->getX();
        $y = $center->getY();

        try {
            $chord = new \ImagickDraw();
            $chord->setStrokeColor($this->getColor($color));
            $chord->setStrokeWidth(1);

            if ($fill) {
                $chord->setFillColor($this->getColor($color));
            } else {
                $x1 = round($x + $width / 2 * cos($start / 180 * M_PI));
                $y1 = round($y + $height / 2 * sin($start / 180 * M_PI));
                $x2 = round($x + $width / 2 * cos($end / 180 * M_PI));
                $y2 = round($y + $height / 2 * sin($end / 180 * M_PI));

                $this->line(new Point($x1, $y1), new Point($x2, $y2), $color);

                $chord->setFillColor('transparent');
            }

            $chord->arc($x - $width / 2, $y - $height / 2, $x + $width / 2, $y + $height / 2, $start, $end);

            $this->imagick->drawImage($chord);

            $chord->clear();
            $chord->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw chord operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::ellipse()
     */
    public function ellipse(Point $center, $width, $height, Color $color, $fill = false)
    {
        try {
            $ellipse = new \ImagickDraw();
            $ellipse->setStrokeColor($this->getColor($color));
            $ellipse->setStrokeWidth(1);

            if ($fill) {
                $ellipse->setFillColor($this->getColor($color));
            } else {
                $ellipse->setFillColor('transparent');
            }

            $ellipse->ellipse($center->getX(), $center->getY(), $width, $height, 0, 360);

            if (false === $this->imagick->drawImage($ellipse)) {
                throw new RuntimeException('Ellipse operation failed');
            }

            $ellipse->clear();
            $ellipse->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw ellipse operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::line()
     */
    public function line(Point $start, Point $end, Color $color)
    {
        try {
            $line = new \ImagickDraw();
            $line->setStrokeColor($this->getColor($color));
            $line->setStrokeWidth(1);
            $line->line($start->getX(), $start->getY(), $end->getX(), $end->getY());

            $this->imagick->drawImage($line);

            $line->clear();
            $line->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw line operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::pieSlice()
     */
    public function pieSlice(Point $center, $width, $height, $start, $end, Color $color, $fill = false)
    {
        $x1 = round($center->getX() + $width / 2 * cos($start / 180 * M_PI));
        $y1 = round($center->getY() + $height / 2 * sin($start / 180 * M_PI));
        $x2 = round($center->getX() + $width / 2 * cos($end / 180 * M_PI));
        $y2 = round($center->getY() + $height / 2 * sin($end / 180 * M_PI));

        if ($fill) {
            $this->chord($center, $width, $height, $start, $end, $color, true);
            $this->polygon(array(
                $center,<commit_msg>switched to deg2rad instead of manual degree to radian conversion<commit_after><?php

/*
 * This file is part of the Imagine package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Imagine\Imagick;

use Imagine\Color;
use Imagine\Point;
use Imagine\Draw\DrawerInterface;
use Imagine\Exception\InvalidArgumentException;
use Imagine\Exception\RuntimeException;

final class Drawer implements DrawerInterface
{
    private $imagick;

    public function __construct(\Imagick $imagick)
    {
        $this->imagick = $imagick;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::arc()
     */
    public function arc(Point $center, $width, $height, $start, $end, Color $color)
    {
        $x = $center->getX();
        $y = $center->getY();

        try {
            $arc = new \ImagickDraw();
            $arc->setStrokeColor($this->getColor($color));
            $arc->setStrokeWidth(1);
            $arc->setFillColor('transparent');
            $arc->arc($x - $width / 2, $y - $height / 2, $x + $width / 2, $y + $height / 2, $start, $end);

            $this->imagick->drawImage($arc);

            $arc->clear();
            $arc->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw arc operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::chord()
     */
    public function chord(Point $center, $width, $height, $start, $end, Color $color, $fill = false)
    {
        $x = $center->getX();
        $y = $center->getY();

        try {
            $chord = new \ImagickDraw();
            $chord->setStrokeColor($this->getColor($color));
            $chord->setStrokeWidth(1);

            if ($fill) {
                $chord->setFillColor($this->getColor($color));
            } else {
                $x1 = round($x + $width / 2 * cos(deg2rad($start)));
                $y1 = round($y + $height / 2 * sin(deg2rad($start)));
                $x2 = round($x + $width / 2 * cos(deg2rad($end)));
                $y2 = round($y + $height / 2 * sin(deg2rad($end)));

                $this->line(new Point($x1, $y1), new Point($x2, $y2), $color);

                $chord->setFillColor('transparent');
            }

            $chord->arc($x - $width / 2, $y - $height / 2, $x + $width / 2, $y + $height / 2, $start, $end);

            $this->imagick->drawImage($chord);

            $chord->clear();
            $chord->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw chord operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::ellipse()
     */
    public function ellipse(Point $center, $width, $height, Color $color, $fill = false)
    {
        try {
            $ellipse = new \ImagickDraw();
            $ellipse->setStrokeColor($this->getColor($color));
            $ellipse->setStrokeWidth(1);

            if ($fill) {
                $ellipse->setFillColor($this->getColor($color));
            } else {
                $ellipse->setFillColor('transparent');
            }

            $ellipse->ellipse($center->getX(), $center->getY(), $width, $height, 0, 360);

            if (false === $this->imagick->drawImage($ellipse)) {
                throw new RuntimeException('Ellipse operation failed');
            }

            $ellipse->clear();
            $ellipse->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw ellipse operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::line()
     */
    public function line(Point $start, Point $end, Color $color)
    {
        try {
            $line = new \ImagickDraw();
            $line->setStrokeColor($this->getColor($color));
            $line->setStrokeWidth(1);
            $line->line($start->getX(), $start->getY(), $end->getX(), $end->getY());

            $this->imagick->drawImage($line);

            $line->clear();
            $line->destroy();
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Draw line operation failed', $e->getCode(), $e
            );
        }

        return $this;
    }

    /**
     * (non-PHPdoc)
     * @see Imagine\Draw.DrawerInterface::pieSlice()
     */
    public function pieSlice(Point $center, $width, $height, $start, $end, Color $color, $fill = false)
    {
        $x1 = round($center->getX() + $width / 2 * cos(deg2rad($start)));
        $y1 = round($center->getY() + $height / 2 * sin(deg2rad($start)));
        $x2 = round($center->getX() + $width / 2 * cos(deg2rad($end)));
        $y2 = round($center->getY() + $height / 2 * sin(deg2rad($end)));

        if ($fill) {
            $this->chord($center, $width, $height, $start, $end, $color, true);
            $this->polygon(array(
                $center,
{'fraction_non_alphanumeric': 0.16908674054260603, 'fraction_numerical': 0.010030569354222392, 'mean_word_length': 1.8666484118291347, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 131, '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': '752465', 'n_tokens_mistral': 3348, 'n_tokens_neox': 3189, 'n_words': 698}