<commit_before>function Shape(id, transform_matrix) {
    this.id = id;
    this.original_transform_matrix = transform_matrix;
    this.paper_shape = undefined;

    this.fill_color = undefined;
    this.stroke_color = undefined;
    this.stroke_width = undefined;

    this._configJSON = function() {
        var fill_color_json = ColorsAdapter.paperColorToHex(this.fill_color);
        var stroke_color_json = ColorsAdapter.paperColorToHex(this.stroke_color);
        return {
            'shape_id': this.id,
            'transform': (typeof this.original_transform_matrix !== 'undefined') ?
                this.original_transform_matrix.toJSON() : undefined,
            'fill_color': fill_color_json.hex_color,
            'fill_alpha': fill_color_json.alpha,
            'stroke_color': stroke_color_json.hex_color,
            'stroke_alpha': stroke_color_json.alpha,
            'stroke_width': this.stroke_width
        }
    };

    this._bindWrapper = function() {
        if (typeof this.paper_shape !== 'undefined') {
            this.paper_shape.shape_wrapper = this;
        }
    };

    this._shapeToPath = function() {
        try {
            return this.paper_shape.toPath(false);
        } catch(err) {
            return this.paper_shape;
        }
    };

    this.setStrokeColor = function(color, alpha) {
        var color_value = (typeof color === 'undefined') ? this.stroke_color.toCSS(true) : color;
        var alpha_value = (typeof alpha === 'undefined') ? this.stroke_color.getAlpha() : alpha;
        this.stroke_color = ColorsAdapter.hexToPaperColor(color_value, alpha_value);
        this.paper_shape.setStrokeColor(this.stroke_color);
    };

    this.setFillColor = function(color, alpha) {
        var color_value = (typeof color === 'undefined') ? this.fill_color.toCSS(true) : color;
        var alpha_value = (typeof alpha === 'undefined') ? this.fill_color.getAlpha() : alpha;
        this.fill_color = ColorsAdapter.hexToPaperColor(color_value, alpha_value);
        this.paper_shape.setFillColor(this.fill_color);
    };

    this.setStrokeWidth = function(stroke_width) {
        this.stroke_width = stroke_width;
        this.paper_shape.setStrokeWidth = this.stroke_width;
    };

    this.transformShape = function(transform_matrix) {
        if (typeof this.paper_shape !== 'undefined') {
            this.paper_shape.transform(transform_matrix);
        } else {
            console.info('Shape not initialized');
        }
    };

    this.getCenter = function() {
        if (typeof this.paper_shape !== 'undefined') {
            var bbox = this.paper_shape.bounds;
            return {
                'x': bbox.center.x,
                'y': bbox.center.y
            }
        } else {
            console.info('Shape not initialized');
        }
    };

    this.getPathSegments = function() {
        if (typeof this.paper_shape !== 'undefined') {
            return this._shapeToPath().getSegments();
        } else {
            return undefined;
        }
    };

    this.getArea = function(pixel_size, decimal_digits) {
        var decimals = (typeof decimal_digits === 'undefined') ? 2 : decimal_digits;
        if (typeof this.paper_shape !== 'undefined') {
            var area = Math.abs(this._shapeToPath().area * Math.pow(pixel_size, 2));
            return Number(area.toFixed(decimals));
        } else {
            console.log('Shape not initialized');
            return undefined;
        }
    };

    this.getPerimeter = function(pixel_size, decimal_digits) {
        var decimals = (typeof decimal_digits === 'undefined') ? 2 : decimal_digits;
        if (typeof this.paper_shape !== 'undefined') {
            var perimeter = this._shapeToPath().length * pixel_size;
            return Number(perimeter.toFixed(decimals));
        } else {
            console.log('Shape not initialized');
        }
    };

    this.getBoundingBoxDimensions = function() {
        if (typeof this.paper_shape !== 'undefined') {
            var bbox = this.paper_shape.bounds;
            return {
                'width': bbox.width,
                'height': bbox.height
            };
        } else {
            console.info('Shape not initialized');
        }
    };

    this.containsPoint = function(point_x, point_y) {
        var point_obj = new paper.Point(point_x, point_y);
        if (typeof this.paper_shape !== 'undefined')
            return this.paper_shape.contains(point_obj);
        else
            console.info('Shape not initialized');
    };

    this.containsShape = function(shape) {
        var shape_segments = shape.getPathSegments(shape);
        if ((typeof this.paper_shape !== 'undefined') && (typeof shape_segments !== 'undefined')) {
            for (var segment_id in shape_segments) {
                if (!this.paper_shape.contains(shape_segments[segment_id].point)) {
                    return false;
                }
            }
            return true;
        }
        else {
            console.error('Both shapes must be initialized');
            return undefined;
        }
    };

    this.getIntersection = function(shape) {
        return this._shapeToPath().intersect(shape._shapeToPath());
    this.intersectsShape = function(shape, x_offset, y_offset) {
        var intersection = this.getIntersection(shape);
        var intersection_path = ShapeConverter.extractPathSegments(intersection, x_offset, y_offset);
        return (intersection_path.length > 0);
    };

    };

    this.getCoveragePercentage = function(shape) {
        var shape_area = shape.getArea(1);
        if ((typeof this.paper_shape !== 'undefined') && (typeof shape_area !== 'undefined')) {
            var intersection = this.getIntersection(shape);
            // passing 1 as pixel size because we only need area in pixels to get the coverage ratio
            var coverage_ratio = Math.abs(intersection.area) / this.getArea(1);
            intersection.remove();
            return (coverage_ratio * 100);
        } else {
            console.error('Both shapes must be initialized');
            return undefined;
        }
    };

    this.configure = function(shape_config) {
        if (typeof this.paper_shape !== 'undefined') {
            this.fill_color = ColorsAdapter.hexToPaperColor(shape_config.fill_color, shape_config.fill_alpha);
            this.paper_shape.setFillColor(this.fill_color);<commit_msg>choose if intersection must be kept<commit_after>function Shape(id, transform_matrix) {
    this.id = id;
    this.original_transform_matrix = transform_matrix;
    this.paper_shape = undefined;

    this.fill_color = undefined;
    this.stroke_color = undefined;
    this.stroke_width = undefined;

    this._configJSON = function() {
        var fill_color_json = ColorsAdapter.paperColorToHex(this.fill_color);
        var stroke_color_json = ColorsAdapter.paperColorToHex(this.stroke_color);
        return {
            'shape_id': this.id,
            'transform': (typeof this.original_transform_matrix !== 'undefined') ?
                this.original_transform_matrix.toJSON() : undefined,
            'fill_color': fill_color_json.hex_color,
            'fill_alpha': fill_color_json.alpha,
            'stroke_color': stroke_color_json.hex_color,
            'stroke_alpha': stroke_color_json.alpha,
            'stroke_width': this.stroke_width
        }
    };

    this._bindWrapper = function() {
        if (typeof this.paper_shape !== 'undefined') {
            this.paper_shape.shape_wrapper = this;
        }
    };

    this._shapeToPath = function() {
        try {
            return this.paper_shape.toPath(false);
        } catch(err) {
            return this.paper_shape;
        }
    };

    this.setStrokeColor = function(color, alpha) {
        var color_value = (typeof color === 'undefined') ? this.stroke_color.toCSS(true) : color;
        var alpha_value = (typeof alpha === 'undefined') ? this.stroke_color.getAlpha() : alpha;
        this.stroke_color = ColorsAdapter.hexToPaperColor(color_value, alpha_value);
        this.paper_shape.setStrokeColor(this.stroke_color);
    };

    this.setFillColor = function(color, alpha) {
        var color_value = (typeof color === 'undefined') ? this.fill_color.toCSS(true) : color;
        var alpha_value = (typeof alpha === 'undefined') ? this.fill_color.getAlpha() : alpha;
        this.fill_color = ColorsAdapter.hexToPaperColor(color_value, alpha_value);
        this.paper_shape.setFillColor(this.fill_color);
    };

    this.setStrokeWidth = function(stroke_width) {
        this.stroke_width = stroke_width;
        this.paper_shape.setStrokeWidth = this.stroke_width;
    };

    this.transformShape = function(transform_matrix) {
        if (typeof this.paper_shape !== 'undefined') {
            this.paper_shape.transform(transform_matrix);
        } else {
            console.info('Shape not initialized');
        }
    };

    this.getCenter = function() {
        if (typeof this.paper_shape !== 'undefined') {
            var bbox = this.paper_shape.bounds;
            return {
                'x': bbox.center.x,
                'y': bbox.center.y
            }
        } else {
            console.info('Shape not initialized');
        }
    };

    this.getPathSegments = function() {
        if (typeof this.paper_shape !== 'undefined') {
            return this._shapeToPath().getSegments();
        } else {
            return undefined;
        }
    };

    this.getArea = function(pixel_size, decimal_digits) {
        var decimals = (typeof decimal_digits === 'undefined') ? 2 : decimal_digits;
        if (typeof this.paper_shape !== 'undefined') {
            var area = Math.abs(this._shapeToPath().area * Math.pow(pixel_size, 2));
            return Number(area.toFixed(decimals));
        } else {
            console.log('Shape not initialized');
            return undefined;
        }
    };

    this.getPerimeter = function(pixel_size, decimal_digits) {
        var decimals = (typeof decimal_digits === 'undefined') ? 2 : decimal_digits;
        if (typeof this.paper_shape !== 'undefined') {
            var perimeter = this._shapeToPath().length * pixel_size;
            return Number(perimeter.toFixed(decimals));
        } else {
            console.log('Shape not initialized');
        }
    };

    this.getBoundingBoxDimensions = function() {
        if (typeof this.paper_shape !== 'undefined') {
            var bbox = this.paper_shape.bounds;
            return {
                'width': bbox.width,
                'height': bbox.height
            };
        } else {
            console.info('Shape not initialized');
        }
    };

    this.containsPoint = function(point_x, point_y) {
        var point_obj = new paper.Point(point_x, point_y);
        if (typeof this.paper_shape !== 'undefined')
            return this.paper_shape.contains(point_obj);
        else
            console.info('Shape not initialized');
    };

    this.containsShape = function(shape) {
        var shape_segments = shape.getPathSegments(shape);
        if ((typeof this.paper_shape !== 'undefined') && (typeof shape_segments !== 'undefined')) {
            for (var segment_id in shape_segments) {
                if (!this.paper_shape.contains(shape_segments[segment_id].point)) {
                    return false;
                }
            }
            return true;
        }
        else {
            console.error('Both shapes must be initialized');
            return undefined;
        }
    };

    this.intersectsShape = function(shape, x_offset, y_offset) {
        var intersection = this.getIntersection(shape);
        var intersection_path = ShapeConverter.extractPathSegments(intersection, x_offset, y_offset);
        return (intersection_path.length > 0);
    };

    this.getIntersection = function(shape, draw_intersection) {
        var draw = typeof draw_intersection === 'undefined' ? false : draw_intersection;
        return this._shapeToPath().intersect(shape._shapeToPath(), {insert: draw});
    };

    this.getCoveragePercentage = function(shape) {
        var shape_area = shape.getArea(1);
        if ((typeof this.paper_shape !== 'undefined') && (typeof shape_area !== 'undefined')) {
            var intersection = this.getIntersection(shape);
            // passing 1 as pixel size because we only need area in pixels to get the coverage ratio
            var coverage_ratio = Math.abs(intersection.area) / this.getArea(1);
            intersection.remove();
            return (coverage_ratio * 100);
        } else {
            console.error('Both shapes must be initialized');
            return undefined;
        }
    };

    this.configure = function(shape_config) {
        if (typeof this.paper_shape !== 'undefined') {
            this.fill_color = ColorsAdapter.hexToPaperColor(shape_config.fill_color, shape_config.fill_alpha);
            this.paper_shape.setFillColor(this.fill_color);
{'fraction_non_alphanumeric': 0.11374845869297164, 'fraction_numerical': 0.0015413070283600493, 'mean_word_length': 2.298678190137265, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6463985', 'n_tokens_mistral': 3647, 'n_tokens_neox': 3561, 'n_words': 696}