<commit_before>package hx.xfl.graphic;

class Edge
{
    public var fillStyle1:Int;
    public var fillStyle0:Int;
    public var strokeStyle:Int;
    public var edges:Array<EdgeCommand>;

    public function new()
    {
        fillStyle1 = 0;
        fillStyle0 = 0;
        strokeStyle = 0;
        edges = [];
    }

    //重制edges数据，去除多余的moveTo
    public function rebuild():Void 
    {
        var n = 1;
        while (n < edges.length) {
            if (edges[n - 1].type != "curveTo" &&
                edges[n-1].x == edges[n].x &&
                edges[n-1].y == edges[n].y) {
                edges.remove(edges[n]);
            }else if (edges[n - 1].type == "curveTo" &&
                edges[n-1].anchorX == edges[n].x &&
                edges[n-1].anchorY == edges[n].y) {
                edges.remove(edges[n]);
            }else {
                n++;
            }
        }
    }

    public function reverse():Void 
    {
        var areas = getAreas();

        var reversAreas = [];
        for (area in areas) {
            var reversArea = [];
            for (n in 0...area.length) {
                reversArea.push(area.pop());
            }
            if (reversArea[0].type != "curveTo") {
                reversArea[0].type = "moveTo";
                reversArea[reversArea.length - 1].type = "lineTo";
            }else {
                reversArea[0].type = "moveTo";
                reversArea[reversArea.length - 1].type = "curveTo";
                reversArea[reversArea.length - 1].anchorX = reversArea[0].anchorX;
                reversArea[reversArea.length - 1].anchorY = reversArea[0].anchorY;
            }
            
            reversAreas.push(reversArea);
        }

        edges = [];
        for (a in reversAreas) {
            edges = edges.concat(a);
        }
    }

    public function getAreasVectors():Array<{starX:Float,starY:Float,angle:Float}>
    {
        var vectors = [];
        var areas = getAreas();
        for (area in areas) {
            var vector:Dynamic = { };
            vector.starX = area[0].x;
            vector.starY = area[0].y;
            var endEdgeCommand = area[area.length - 1];
            var endX, endY;
            if ("lineTo" == endEdgeCommand.type) {
                endX = endEdgeCommand.x;
                endY = endEdgeCommand.y;
            }else {
                endX = endEdgeCommand.anchorX;
                endY = endEdgeCommand.anchorY;
            }
            vector.angle = Math.atan2(endY - vector.starY, endX - vector.starX);

            vectors.push(vector);
        }
        return vectors;
    }

    public function getAreas():Array<Array<EdgeCommand>>
    {
        var areas = [];
        var fillArea = [];
        for (e in edges) {
            if (e.type == "moveTo") {
                if (fillArea.length > 0) {
                    areas.push(fillArea.copy());
                    fillArea = [];
                }
            }
            fillArea.push(e.clone());
        }
        if (fillArea.length > 0) {
            areas.push(fillArea.copy());
        }
        return areas;
    }

    public function clone():Edge
    {
        var edge = new Edge();
        edge.fillStyle0 = this.fillStyle0;
        edge.fillStyle1 = this.fillStyle1;
        edge.strokeStyle = this.strokeStyle;
        edge.edges = this.edges.copy();

        return edge;
    }
}<commit_msg>添加顺时针排序绘制区域向量<commit_after>package hx.xfl.graphic;

class Edge
{
    public var fillStyle1:Int;
    public var fillStyle0:Int;
    public var strokeStyle:Int;
    public var edges:Array<EdgeCommand>;

    public function new()
    {
        fillStyle1 = 0;
        fillStyle0 = 0;
        strokeStyle = 0;
        edges = [];
    }

    //重制edges数据，去除多余的moveTo
    public function rebuild():Void 
    {
        var n = 1;
        while (n < edges.length) {
            if (edges[n - 1].type != "curveTo" &&
                edges[n-1].x == edges[n].x &&
                edges[n-1].y == edges[n].y) {
                edges.remove(edges[n]);
            }else if (edges[n - 1].type == "curveTo" &&
                edges[n-1].anchorX == edges[n].x &&
                edges[n-1].anchorY == edges[n].y) {
                edges.remove(edges[n]);
            }else {
                n++;
            }
        }
    }

    public function reverse():Void 
    {
        var areas = getAreas();

        var reversAreas = [];
        for (area in areas) {
            var reversArea = [];
            for (n in 0...area.length) {
                reversArea.push(area.pop());
            }
            if (reversArea[0].type != "curveTo") {
                reversArea[0].type = "moveTo";
                reversArea[reversArea.length - 1].type = "lineTo";
            }else {
                reversArea[0].type = "moveTo";
                reversArea[reversArea.length - 1].type = "curveTo";
                reversArea[reversArea.length - 1].anchorX = reversArea[0].anchorX;
                reversArea[reversArea.length - 1].anchorY = reversArea[0].anchorY;
            }
            
            reversAreas.push(reversArea);
        }

        edges = [];
        for (a in reversAreas) {
            edges = edges.concat(a);
        }
    }

    function vectorsByClockwise():Array<{starX:Float,starY:Float,angle:Float,index:Int}>
    {
        var vectors = getAreasVectors();
        vectors.sort(function (a,b):Int 
        {
            if (a.angle != b.angle)
                return Reflect.compare(a.angle, b.angle);
            else 
                return -Reflect.compare(a.starX, b.starX);
        });
        return vectors;
    }

    function getAreasVectors():Array<{starX:Float,starY:Float,angle:Float,index:Int}>
    {
        var vectors = [];
        var areas = getAreas();
        var n = 0;
        for (area in areas) {
            var vector:Dynamic = { };
            vector.starX = area[0].x;
            vector.starY = area[0].y;
            var endEdgeCommand = area[area.length - 1];
            var endX, endY;
            if ("lineTo" == endEdgeCommand.type) {
                endX = endEdgeCommand.x;
                endY = endEdgeCommand.y;
            }else {
                endX = endEdgeCommand.anchorX;
                endY = endEdgeCommand.anchorY;
            }
            vector.angle = Math.atan2(endY - vector.starY, endX - vector.starX);
            vector.index = n;
            n++;

            vectors.push(vector);
        }
        return vectors;
    }

    function getAreas():Array<Array<EdgeCommand>>
    {
        var areas = [];
        var fillArea = [];
        for (e in edges) {
            if (e.type == "moveTo") {
                if (fillArea.length > 0) {
                    areas.push(fillArea.copy());
                    fillArea = [];
                }
            }
            fillArea.push(e.clone());
        }
        if (fillArea.length > 0) {
            areas.push(fillArea.copy());
        }
        return areas;
    }

    public function clone():Edge
    {
        var edge = new Edge();
        edge.fillStyle0 = this.fillStyle0;
        edge.fillStyle1 = this.fillStyle1;
        edge.strokeStyle = this.strokeStyle;
        edge.edges = this.edges.copy();

        return edge;
    }
}
{'fraction_non_alphanumeric': 0.12929014472777395, 'fraction_numerical': 0.009510682288077188, 'mean_word_length': 1.3774574049803407, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, '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': '3713892', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2167, 'n_words': 407}