<commit_before>﻿/// <reference path="path.ts" />

module makerjs.model {

    /**
     * Moves all children (models and paths, recursively) within a model to their absolute position. Useful when referencing points between children.
     * 
     * @param modelToFlatten The model to flatten.
     * @param origin Optional offset reference point.
     */
    export function flatten(modelToFlatten: IMakerModel, origin?: IMakerPoint) {
        var newOrigin = point.add(modelToFlatten.origin, origin);

        if (modelToFlatten.paths) {
            for (var i = 0; i < modelToFlatten.paths.length; i++) {
                path.moveRelative(modelToFlatten.paths[i], newOrigin);
            }
        }

        if (modelToFlatten.models) {
            for (var i = 0; i < modelToFlatten.models.length; i++) {
                flatten(modelToFlatten.models[i], newOrigin);
            }
        }

        modelToFlatten.origin = point.ensure();

        return modelToFlatten;
    }

    /**
     * Create a clone of a model, mirrored on either or both x and y axes.
     * 
     * @param modelToMirror The model to mirror.
     * @param mirrorX Boolean to mirror on the x axis.
     * @param mirrorY Boolean to mirror on the y axis.
     * @returns Mirrored model.
     */
    export function mirror(modelToMirror: IMakerModel, mirrorX: boolean, mirrorY: boolean): IMakerModel {
        var newModel: IMakerModel = {};

        if (modelToMirror.id) {
            newModel.id = modelToMirror.id + '_mirror';
        }

        if (modelToMirror.origin) {
            newModel.origin = point.mirror(modelToMirror.origin, mirrorX, mirrorY);
        }

        if (modelToMirror.type) {
            newModel.type = modelToMirror.type;
        }

        if (modelToMirror.units) {
            newModel.units = modelToMirror.units;
        }

        if (modelToMirror.paths) {
            newModel.paths = [];
            for (var i = 0; i < modelToMirror.paths.length; i++) {
                newModel.paths.push(path.mirror(modelToMirror.paths[i], mirrorX, mirrorY));
            }
        }

        if (modelToMirror.models) {
            newModel.models = [];
            for (var i = 0; i < modelToMirror.models.length; i++) {
                newModel.models.push(model.mirror(modelToMirror.models[i], mirrorX, mirrorY));
            }
        }

        return newModel;
    }

    /**
     * Move a model to an absolute position. Note that this is also accomplished by directly setting the origin property. This function exists because the origin property is optional.
     * 
     * @param modelToMove The model to move.
     * @param origin The new position of the model.
     * @returns The original model (for chaining).
     */
    export function move(modelToMove: IMakerModel, origin: IMakerPoint): IMakerModel {
        modelToMove.origin = point.clone(point.ensure(origin));
        return modelToMove;
    }

    /**
     * Rotate a model.
     * 
     * @param modelToRotate The model to rotate.
     * @param angleInDegrees The amount of rotation, in degrees.
     * @param rotationOrigin The center point of rotation.<commit_msg>added overload to move method.<commit_after>﻿/// <reference path="path.ts" />

module makerjs.model {

    /**
     * Moves all children (models and paths, recursively) within a model to their absolute position. Useful when referencing points between children.
     * 
     * @param modelToFlatten The model to flatten.
     * @param origin Optional offset reference point.
     */
    export function flatten(modelToFlatten: IMakerModel, origin?: IMakerPoint) {
        var newOrigin = point.add(modelToFlatten.origin, origin);

        if (modelToFlatten.paths) {
            for (var i = 0; i < modelToFlatten.paths.length; i++) {
                path.moveRelative(modelToFlatten.paths[i], newOrigin);
            }
        }

        if (modelToFlatten.models) {
            for (var i = 0; i < modelToFlatten.models.length; i++) {
                flatten(modelToFlatten.models[i], newOrigin);
            }
        }

        modelToFlatten.origin = point.zero();

        return modelToFlatten;
    }

    /**
     * Create a clone of a model, mirrored on either or both x and y axes.
     * 
     * @param modelToMirror The model to mirror.
     * @param mirrorX Boolean to mirror on the x axis.
     * @param mirrorY Boolean to mirror on the y axis.
     * @returns Mirrored model.
     */
    export function mirror(modelToMirror: IMakerModel, mirrorX: boolean, mirrorY: boolean): IMakerModel {
        var newModel: IMakerModel = {};

        if (modelToMirror.id) {
            newModel.id = modelToMirror.id + '_mirror';
        }

        if (modelToMirror.origin) {
            newModel.origin = point.mirror(modelToMirror.origin, mirrorX, mirrorY);
        }

        if (modelToMirror.type) {
            newModel.type = modelToMirror.type;
        }

        if (modelToMirror.units) {
            newModel.units = modelToMirror.units;
        }

        if (modelToMirror.paths) {
            newModel.paths = [];
            for (var i = 0; i < modelToMirror.paths.length; i++) {
                newModel.paths.push(path.mirror(modelToMirror.paths[i], mirrorX, mirrorY));
            }
        }

        if (modelToMirror.models) {
            newModel.models = [];
            for (var i = 0; i < modelToMirror.models.length; i++) {
                newModel.models.push(model.mirror(modelToMirror.models[i], mirrorX, mirrorY));
            }
        }

        return newModel;
    }

    export function move(modelToMove: IMakerModel, origin: IMakerPoint): IMakerModel;
    export function move(modelToMove: IMakerModel, origin: number[]): IMakerModel;

    /**
     * Move a model to an absolute position. Note that this is also accomplished by directly setting the origin property. This function exists because the origin property is optional.
     * 
     * @param modelToMove The model to move.
     * @param origin The new position of the model.
     * @returns The original model (for chaining).
     */
    export function move(modelToMove: IMakerModel, origin: any): IMakerModel {
        modelToMove.origin = point.clone(point.ensure(origin));
        return modelToMove;
    }

    /**
     * Rotate a model.
     * 
     * @param modelToRotate The model to rotate.
     * @param angleInDegrees The amount of rotation, in degrees.
     * @param rotationOrigin The center point of rotation.
{'fraction_non_alphanumeric': 0.0988399071925754, 'fraction_numerical': 0.0012374323279195668, 'mean_word_length': 2.171162334477685, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2801601', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1792, 'n_words': 531}