<commit_before>package org.yellcorp.lib.geom.curves
{
import flash.display.Graphics;
import flash.geom.Point;
import flash.geom.Rectangle;


public class CubicBezier
{
    public var p0:Point;
    public var p1:Point;
    public var p2:Point;
    public var p3:Point;

    public static function createFromPoints(point0:Point, point1:Point, point2:Point, point3:Point):CubicBezier
    {
        var b:CubicBezier = new CubicBezier();
        b.p0 = point0;  b.p1 = point1;  b.p2 = point2;  b.p3 = point3;
        return b;
    }

    public static function create():CubicBezier
    {
        return createFromPoints(new Point(), new Point(), new Point(), new Point());
    }

    public static function createFromCoords(x0:Number, y0:Number,
                                            x1:Number, y1:Number,
                                            x2:Number, y2:Number,
                                            x3:Number, y3:Number):CubicBezier
    {
        return createFromPoints(new Point(x0, y0),
                                new Point(x1, y1),
                                new Point(x2, y2),
                                new Point(x3, y3));
    }

    public static function createFromPointArray(array:*):CubicBezier
    {
        var b:CubicBezier = create();
        b.setPointArray(array);
        return b;
    }

    public static function createFromCoordArray(array:*):CubicBezier
    {
        var b:CubicBezier = create();
        b.setCoordArray(array);
        return b;
    }

    public function toString():String
    {
        return "[CubicBezier (" + p0.x + ", " + p0.y +
                        "), (" + p1.x + ", " + p1.y +
                        "), (" + p2.x + ", " + p2.y +
                        "), (" + p3.x + ", " + p3.y +
                        ")]";
    }

    public function clone():CubicBezier
    {
        return createFromPoints(p0.clone(), p1.clone(), p2.clone(), p3.clone());
    }

    public function setPoints(point0:Point, point1:Point, point2:Point, point3:Point):void
    {
        p0 = point0;  p1 = point1;  p2 = point2;  p3 = point3;
    }

    public function setCoords(x0:Number, y0:Number,
                              x1:Number, y1:Number,
                              x2:Number, y2:Number,
                              x3:Number, y3:Number):void
    {
        p0.x = x0;  p0.y = y0;  p1.x = x1;  p1.y = y1;
        p2.x = x2;  p2.y = y2;  p3.x = x3;  p3.y = y3;
    }

    public function setPointArray(array:*):void
    {
        if (array.length != 4)
            throw new ArgumentError("Array must be of length 4");

        setCoords(array[0].x, array[0].y,
                  array[1].x, array[1].y,
                  array[2].x, array[2].y,
                  array[3].x, array[3].y);
    }

    public function setCoordArray(array:*):void
    {
        if (array.length != 8)
            throw new ArgumentError("Array must be of length 8");

        setCoords(array[0], array[1],
                  array[2], array[3],
                  array[4], array[5],
                  array[6], array[7]);
    }

    public function sample(t:Number, out:Point):Point
    {
        var u:Number = 1 - t;
        var uu:Number = u * u;
        var tt:Number = t * t;

        out.x = uu * (u * p0.x + 3 * t * p1.x) +
                tt * (3 * u * p2.x + t * p3.x);

        out.y = uu * (u * p0.y + 3 * t * p1.y) +
                tt * (3 * u * p2.y + t * p3.y);

        return out;
    }

    public function sampleX(t:Number):Number
    {
        var u:Number = 1 - t;
        return u * u * (u * p0.x + 3 * t * p1.x) +
               t * t * (3 * u * p2.x + t * p3.x);
    }

    public function sampleY(t:Number):Number
    {
        var u:Number = 1 - t;
        return u * u * (u * p0.y + 3 * t * p1.y) +
               t * t * (3 * u * p2.y + t * p3.y);
    }

    public function tangent(t:Number, out:Point):Point
    {
        out.x = 3 * (-p0.x + p1.x +
                     t * (2 * p0.x - 4 * p1.x + 2 * p2.x +
                          t * (-p0.x + 3 * p1.x -3 * p2.x + p3.x)));

        out.y = 3 * (-p0.y + p1.y +
                     t * (2 * p0.y - 4 * p1.y + 2 * p2.y +
                          t * (-p0.y + 3 * p1.y -3 * p2.y + p3.y)));

        return out;
    }

/*
    public function split(t:Number, outLow:CubicBezier, outHigh:CubicBezier):void
    {
        splitLow(t, outLow);
        splitHigh(t, outHigh);
    }

    public function splitLow(t:Number, out:CubicBezier):CubicBezier
    {
        out.p0.x = p0.x;
        out.p0.y = p0.y;
        out.p1.x = p0.x + (p1.x - p0.x) * t;
        out.p1.y = p0.y + (p1.y - p0.y) * t;
        sample(t, out.p2);
        return out;
    }

    public function splitHigh(t:Number, out:CubicBezier):CubicBezier
    {
        sample(t, out.p0);
        out.p1.x = p1.x + (p2.x - p1.x) * t;
        out.p1.y = p1.y + (p2.y - p1.y) * t;
        out.p2.x = p2.x;
        out.p2.y = p2.y;
        return out;
    }
     */

    private static function appendFirstDerivRoots(a:Number, b:Number, c:Number, d:Number, out:Array):void
    {
        var divisor:Number = -a + 3 * b - 3 * c + d;
        var radicand:Number;
        var root:Number;

        if (divisor != 0)
        {
            radicand = a * (d - c) + b * (b - c - d) + c * c;
            if (radicand >= 0)
            {
                root = (Math.sqrt(radicand) - a + 2 * b - c) / (-a + 3 * (b - c) + d);
                out.push(root);
                if (root != 0) out.push(-root);
            }
        }
        else
        {
            divisor = a - 2 * b + c;
            if (divisor != 0)
            {<commit_msg>Was calculating divisor twice in cubic root finding<commit_after>package org.yellcorp.lib.geom.curves
{
import flash.display.Graphics;
import flash.geom.Point;
import flash.geom.Rectangle;


public class CubicBezier
{
    public var p0:Point;
    public var p1:Point;
    public var p2:Point;
    public var p3:Point;

    public static function createFromPoints(point0:Point, point1:Point, point2:Point, point3:Point):CubicBezier
    {
        var b:CubicBezier = new CubicBezier();
        b.p0 = point0;  b.p1 = point1;  b.p2 = point2;  b.p3 = point3;
        return b;
    }

    public static function create():CubicBezier
    {
        return createFromPoints(new Point(), new Point(), new Point(), new Point());
    }

    public static function createFromCoords(x0:Number, y0:Number,
                                            x1:Number, y1:Number,
                                            x2:Number, y2:Number,
                                            x3:Number, y3:Number):CubicBezier
    {
        return createFromPoints(new Point(x0, y0),
                                new Point(x1, y1),
                                new Point(x2, y2),
                                new Point(x3, y3));
    }

    public static function createFromPointArray(array:*):CubicBezier
    {
        var b:CubicBezier = create();
        b.setPointArray(array);
        return b;
    }

    public static function createFromCoordArray(array:*):CubicBezier
    {
        var b:CubicBezier = create();
        b.setCoordArray(array);
        return b;
    }

    public function toString():String
    {
        return "[CubicBezier (" + p0.x + ", " + p0.y +
                        "), (" + p1.x + ", " + p1.y +
                        "), (" + p2.x + ", " + p2.y +
                        "), (" + p3.x + ", " + p3.y +
                        ")]";
    }

    public function clone():CubicBezier
    {
        return createFromPoints(p0.clone(), p1.clone(), p2.clone(), p3.clone());
    }

    public function setPoints(point0:Point, point1:Point, point2:Point, point3:Point):void
    {
        p0 = point0;  p1 = point1;  p2 = point2;  p3 = point3;
    }

    public function setCoords(x0:Number, y0:Number,
                              x1:Number, y1:Number,
                              x2:Number, y2:Number,
                              x3:Number, y3:Number):void
    {
        p0.x = x0;  p0.y = y0;  p1.x = x1;  p1.y = y1;
        p2.x = x2;  p2.y = y2;  p3.x = x3;  p3.y = y3;
    }

    public function setPointArray(array:*):void
    {
        if (array.length != 4)
            throw new ArgumentError("Array must be of length 4");

        setCoords(array[0].x, array[0].y,
                  array[1].x, array[1].y,
                  array[2].x, array[2].y,
                  array[3].x, array[3].y);
    }

    public function setCoordArray(array:*):void
    {
        if (array.length != 8)
            throw new ArgumentError("Array must be of length 8");

        setCoords(array[0], array[1],
                  array[2], array[3],
                  array[4], array[5],
                  array[6], array[7]);
    }

    public function sample(t:Number, out:Point):Point
    {
        var u:Number = 1 - t;
        var uu:Number = u * u;
        var tt:Number = t * t;

        out.x = uu * (u * p0.x + 3 * t * p1.x) +
                tt * (3 * u * p2.x + t * p3.x);

        out.y = uu * (u * p0.y + 3 * t * p1.y) +
                tt * (3 * u * p2.y + t * p3.y);

        return out;
    }

    public function sampleX(t:Number):Number
    {
        var u:Number = 1 - t;
        return u * u * (u * p0.x + 3 * t * p1.x) +
               t * t * (3 * u * p2.x + t * p3.x);
    }

    public function sampleY(t:Number):Number
    {
        var u:Number = 1 - t;
        return u * u * (u * p0.y + 3 * t * p1.y) +
               t * t * (3 * u * p2.y + t * p3.y);
    }

    public function tangent(t:Number, out:Point):Point
    {
        out.x = 3 * (-p0.x + p1.x +
                     t * (2 * p0.x - 4 * p1.x + 2 * p2.x +
                          t * (-p0.x + 3 * p1.x -3 * p2.x + p3.x)));

        out.y = 3 * (-p0.y + p1.y +
                     t * (2 * p0.y - 4 * p1.y + 2 * p2.y +
                          t * (-p0.y + 3 * p1.y -3 * p2.y + p3.y)));

        return out;
    }

/*
    public function split(t:Number, outLow:CubicBezier, outHigh:CubicBezier):void
    {
        splitLow(t, outLow);
        splitHigh(t, outHigh);
    }

    public function splitLow(t:Number, out:CubicBezier):CubicBezier
    {
        out.p0.x = p0.x;
        out.p0.y = p0.y;
        out.p1.x = p0.x + (p1.x - p0.x) * t;
        out.p1.y = p0.y + (p1.y - p0.y) * t;
        sample(t, out.p2);
        return out;
    }

    public function splitHigh(t:Number, out:CubicBezier):CubicBezier
    {
        sample(t, out.p0);
        out.p1.x = p1.x + (p2.x - p1.x) * t;
        out.p1.y = p1.y + (p2.y - p1.y) * t;
        out.p2.x = p2.x;
        out.p2.y = p2.y;
        return out;
    }
     */

    private static function appendFirstDerivRoots(a:Number, b:Number, c:Number, d:Number, out:Array):void
    {
        var divisor:Number = -a + 3 * b - 3 * c + d;
        var radicand:Number;
        var root:Number;

        if (divisor != 0)
        {
            radicand = a * (d - c) + b * (b - c - d) + c * c;
            if (radicand >= 0)
            {
                root = (Math.sqrt(radicand) - a + 2 * b - c) / divisor;
                out.push(root);
                if (root != 0) out.push(-root);
            }
        }
        else
        {
            divisor = a - 2 * b + c;
            if (divisor != 0)
            {
{'fraction_non_alphanumeric': 0.14422480276571226, 'fraction_numerical': 0.03395089087846822, 'mean_word_length': 1.3474823137744487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7315243', 'n_tokens_mistral': 4220, 'n_tokens_neox': 4014, 'n_words': 903}