{"size": 3763, "ext": "js", "max_stars_repo_path": "src/render/shape/Shape.js", "max_stars_repo_name": "yunbiji/fonteditor", "max_stars_repo_stars_event_min_datetime": "2017-09-05T22:10:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T06:44:36.000Z", "max_issues_repo_path": "src/render/shape/Shape.js", "max_issues_repo_name": "2947721120/fonteditor", "max_issues_repo_issues_event_min_datetime": "2017-09-27T16:26:22.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-06T01:59:53.000Z", "max_forks_repo_path": "src/render/shape/Shape.js", "max_forks_repo_name": "fontmoa/fonteditor", "max_forks_repo_forks_event_min_datetime": "2021-05-06T05:51:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-06T05:51:37.000Z"}
{"max_stars_count": 2, "max_issues_count": 11, "max_forks_count": 1, "avg_line_length": 24.4350649351, "max_line_length": 70, "alphanum_fraction": 0.3813446718}
/**
 * @file Shape 基础对象，用来绘制shape数据
 * @author mengke01(kekee000@gmail.com)
 */

define(
    function (require) {
        var lang = require('common/lang');

        /**
         * Shape 基础对象
         *
         * @constructor
         * @param {Object} options 参数选项
         */
        function Shape(options) {
            options = options || {};
        }

        Shape.prototype = {

            constructor: Shape,

            /**
             * 对形状进行缩放平移调整
             *
             * @param {Object} shape shape对象
             * @param {Camera} camera Camera对象
             *
             * @return {Object} shape对象
             */
            adjust: function (shape, camera) {
                var center = camera.center;
                var ratio = camera.ratio;

                if (typeof shape.x === 'number') {
                    shape.x = ratio * (shape.x - center.x) + center.x;
                }

                if (typeof shape.y === 'number') {
                    shape.y = ratio * (shape.y - center.y) + center.y;
                }

                if (typeof shape.width === 'number') {
                    shape.width = ratio * shape.width;
                }

                if (typeof shape.width === 'number') {
                    shape.height = ratio * shape.height;
                }

                if (typeof shape.r === 'number') {
                    shape.r = ratio * shape.r;
                }

                return shape;
            },

            /**
             * 移动指定位置
             * @param {Object} shape shape对象
             * @param {number} mx x偏移
             * @param {number} my y偏移
             * @return {Object} shape对象
             */
            move: function (shape, mx, my) {

                if (typeof shape.x === 'number') {
                    shape.x += mx;
                }

                if (typeof shape.y === 'number') {
                    shape.y += my;
                }

                return shape;
            },

            /**
             * 获取shape的矩形区域
             *
             * @param {Object} shape shape数据
             * @return {Object} 矩形区域
             */
            getRect: function (shape) {
                // TODO
                return false;
            },

            /**
             * 判断点是否在shape内部
             *
             * @param {Object} shape shape数据
             * @param {number} x x偏移
             * @param {number} y y偏移
             * @return {boolean} 是否
             */
            isIn: function (shape, x, y) {
                // TODO
                return false;
            },

            /**
             * 绘制一个shape对象
             *
             * @param {CanvasRenderingContext2D} ctx canvas的context
             * @param {Object} shape shape数据
             * @param {Object} camera 当前的视角对象
             */
            draw: function (ctx, shape, camera) {
                // TODO
            },

            /**
             * 注销本对象
             */
            dispose: function () {
                // TODO
            }
        };

        /**
         * 派生出一个shape对象
         *
         * @param {Object} prototype 参数
         * @return {Shape} Shape类
         */
        Shape.derive = function (prototype) {

            function SubShape() {
                Shape.apply(this, arguments);
            }

            SubShape.prototype = prototype;
            lang.inherits(SubShape, Shape);
            return SubShape;
        };

        /**
         * 克隆一个shape对象
         *
         * @param {Object} shape shape对象
         * @return {Object} shape对象
         */
        function cloneShape(shape) {
            return lang.clone(shape);
        }

        Shape.clone = cloneShape;

        return Shape;
    }
);
