<commit_before>cg.Group = (function () {

    /**
     * Represent a group instance into the graph, a group is a container for grouping sub-entities.
     * @param _id {Number|String} the unique id within the graph for this kind of entity.
     * @param name {String} the action name to refer to the action.
     * @param position {pandora.Vec2} the position on the screen.
     * @param size {pandora.Vec2} the size on the screen.
     * @extends cg.Entity
     * @constructor
     */
    var Group = pandora.class_("Group", cg.Entity, function (_id, name, position, size) {
        cg.Entity.call(this, _id, this.constructor.typename, name, position);

        /**
         * Group size.
         * @type {pandora.Vec2}
         * @private
         */
        this._size = size || new pandora.Vec2();
        Object.defineProperty(this, "size", {
            get: function () { return this._size; }.bind(this),
            set: function (size) { this._size = size; }.bind(this)
        });

        /**
         * Group children.
         * @type {cg.Container}
         * @private
         */
        this._children = new cg.Container();
        Object.defineProperty(this, "children", {
            get: function () { return this._children; }.bind(this)
        });

        /**
         * Helper method to get the bounding box of this group.
         */
        Object.defineProperty(this, "box", {
            get: function () { return new pandora.Box2(this.absolutePosition, this._size); }.bind(this)
        });
    });

    /**
     * Call the callback for each child recursively.
     * @param callback {Function}
     */
    Group.prototype.forEachChild = function (callback) {
        (function next(group) {
            group.children.forEach(function (entity) {
                if (callback(entity)) {
                    return;
                }
                if (entity instanceof cg.Group) {
                    next(entity);
                }
            });
        })(this);
    };

    /**
     * Add the given entity.
     * @param entity {cg.Entity}
     * @protected
     */
    Group.prototype._addChild = function (entity) {
        if (entity.parent === this) {
            this.graph.emit("error", new Error("Cannot add entity as child if the entity is already a child", this, entity));
            return ;
        }
        if (entity.parent) {
            entity._changeParent(this);
        }
        entity.parent = this;
        this._children.add(entity);
    };

    /**
     * Remove the given entity from the group.
     * @param entity {cg.Entity}
     * @protected
     */
    Group.prototype._removeChild = function (entity) {
        this._children.remove(entity);
    };

    /**
     * Remove the group from the graph.
     * @protected
     * @override
     */
    Group.prototype._remove = function() {
        (function next(children) {
            var child = children[0];
            if (child) {
                child._remove();
            }
            if (children[0] !== child) {
                next(children);
            }
        })(this._children._entities);
        cg.Entity.prototype._remove.call(this);
    };<commit_msg>Fixed remove entity child from group, fixes #40<commit_after>cg.Group = (function () {

    /**
     * Represent a group instance into the graph, a group is a container for grouping sub-entities.
     * @param _id {Number|String} the unique id within the graph for this kind of entity.
     * @param name {String} the action name to refer to the action.
     * @param position {pandora.Vec2} the position on the screen.
     * @param size {pandora.Vec2} the size on the screen.
     * @extends cg.Entity
     * @constructor
     */
    var Group = pandora.class_("Group", cg.Entity, function (_id, name, position, size) {
        cg.Entity.call(this, _id, this.constructor.typename, name, position);

        /**
         * Group size.
         * @type {pandora.Vec2}
         * @private
         */
        this._size = size || new pandora.Vec2();
        Object.defineProperty(this, "size", {
            get: function () { return this._size; }.bind(this),
            set: function (size) { this._size = size; }.bind(this)
        });

        /**
         * Group children.
         * @type {cg.Container}
         * @private
         */
        this._children = new cg.Container();
        Object.defineProperty(this, "children", {
            get: function () { return this._children; }.bind(this)
        });

        /**
         * Helper method to get the bounding box of this group.
         */
        Object.defineProperty(this, "box", {
            get: function () { return new pandora.Box2(this.absolutePosition, this._size); }.bind(this)
        });
    });

    /**
     * Call the callback for each child recursively.
     * @param callback {Function}
     */
    Group.prototype.forEachChild = function (callback) {
        (function next(group) {
            group.children.forEach(function (entity) {
                if (callback(entity)) {
                    return;
                }
                if (entity instanceof cg.Group) {
                    next(entity);
                }
            });
        })(this);
    };

    /**
     * Add the given entity.
     * @param entity {cg.Entity}
     * @protected
     */
    Group.prototype._addChild = function (entity) {
        if (entity.parent === this) {
            this.graph.emit("error", new Error("Cannot add entity as child if the entity is already a child", this, entity));
            return ;
        }
        if (entity.parent) {
            entity._changeParent(this);
        }
        entity.parent = this;
        this._children.add(entity);
    };

    /**
     * Remove the given entity from the group.
     * @param entity {cg.Entity}
     * @protected
     */
    Group.prototype._removeChild = function (entity) {
        this._children.remove(entity);
    };

    /**
     * Remove the group from the graph.
     * @protected
     * @override
     */
    Group.prototype._remove = function() {
        var graph = this.graph;
        (function next(children) {
            while (children[0]) {
                graph.removeEntity(children[0]);
            }
        })(this._children._entities);
        cg.Entity.prototype._remove.call(this);
    };
{'fraction_non_alphanumeric': 0.12568995426588866, 'fraction_numerical': 0.0025232613152499604, 'mean_word_length': 1.7218884120171674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1517785', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1717, 'n_words': 469}