var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import { SGraphyItem } from '@sybotan-web/graphy';
import { SRect, SPoint } from "@sybotan-web/base";
import { SColor } from "@sybotan-web/draw";
/**
 * 不规则多边形Item类
 *
 */
var SGraphyPolygonItem = /** @class */ (function (_super) {
    __extends(SGraphyPolygonItem, _super);
    // actived: boolean = false; 				//是否激活
    /**
     * 构造函数
     *
     * @param pointArr									点坐标list
     * @param width											边框的宽度
     * @param color											边框的颜色
     * @param fillColor   							多边形填充的颜色
     * @param businessId								空间id
     * @param businessName							空间名称
     * @param centerOfGravityPoint			中心点
     * @param isBusiness								状态
     * @param parent
     */
    function SGraphyPolygonItem(PolygonItemData) {
        var _this = _super.call(this, PolygonItemData.parent) || this;
        _this.fillColor = new SColor('#F2F6FC');
        _this.color = SColor.Black;
        _this.width = 200;
        _this.viewText = ''; //绘出的文案
        _this.isBusiness = 1;
        _this.cacheColor = SColor.Black; //需要缓存的边框
        _this.cacheFillColor = new SColor('#F2F6FC'); //需要缓存的填充色
        _this.cacheWidth = 100;
        _this.businessType = ''; //类型
        // 修改绘制路径格式
        var newSpacePaths = PolygonItemData.space.Paths[0].map(function (item) {
            return new SPoint(item.X, item.Y);
        });
        _this.pointArr = newSpacePaths;
        // 填充色
        _this.fillColor = PolygonItemData.space.fillColor ? PolygonItemData.space.fillColor : new SColor('#F2F6FC');
        // 边框色
        _this.color = PolygonItemData.space.color ? PolygonItemData.space.color : SColor.Black;
        //边框宽度
        _this.width = PolygonItemData.space.width ? PolygonItemData.space.width : 100;
        //中心点
        _this.centerOfGravityPoint = {
            x: PolygonItemData.space.LocationPoint.X,
            y: -PolygonItemData.space.LocationPoint.Y
        };
        //业务空间类型
        _this.isBusiness = PolygonItemData.space.isBusiness ? PolygonItemData.space.isBusiness : 1;
        //业务空间id
        _this.businessId = PolygonItemData.space.businessId ? PolygonItemData.space.businessId : null;
        //业务空间名称
        _this.businessName = PolygonItemData.space.Name;
        _this.initName = PolygonItemData.space.Name;
        // 空间id
        _this.id = PolygonItemData.space.id;
        _this.viewText = PolygonItemData.space.Name;
        //类型
        _this.businessType = PolygonItemData.businessType ? PolygonItemData.businessType : '';
        return _this;
    }
    /**
     * Item对象边界区域
     *
     * @return SRect
     */
    SGraphyPolygonItem.prototype.boundingRect = function () {
        var minX = this.pointArr[0].x;
        var maxX = minX;
        var minY = this.pointArr[0].y;
        var maxY = minY;
        for (var i = 1; i < this.pointArr.length; i++) {
            if (this.pointArr[i].x < minX) {
                minX = this.pointArr[i].x;
            }
            if (this.pointArr[i].y < minY) {
                minY = this.pointArr[i].y;
            }
            if (this.pointArr[i].x > maxX) {
                maxX = this.pointArr[i].x;
            }
            if (this.pointArr[i].y > maxY) {
                maxY = this.pointArr[i].y;
            }
        }
        return new SRect(minX, minY, maxX - minX, maxY - minY);
    }; // Function boundingRect()
    /**
     * 判断点是否在区域内
     *
     * @param x
     * @param y
     */
    SGraphyPolygonItem.prototype.contains = function (x, y) {
        var nCross = 0, point = [x, y], APoints = this.pointArr, length = APoints.length, p1, p2, i, xinters;
        p1 = APoints[0];
        for (i = 1; i <= length; i++) {
            p2 = APoints[i % length];
            if (point[0] > Math.min(p1.x, p2.x) &&
                point[0] <= Math.max(p1.x, p2.x)) {
                if (point[1] <= Math.max(p1.y, p2.y)) {
                    if (p1.x != p2.x) {
                        //计算位置信息
                        xinters = (point[0] - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
                        if (p1.y == p2.y || point[1] <= xinters) {
                            nCross++;
                        }
                    }
                }
            }
            p1 = p2;
        }
        return nCross % 2 === 1;
    };
    /**
     *
     * @param text 修改的文字
     * @param centerOfGravityPoint 文字的坐标
     */
    SGraphyPolygonItem.prototype.addText = function (text, centerOfGravityPoint) {
        this.viewText = text;
        if (centerOfGravityPoint) {
            this.centerOfGravityPoint = centerOfGravityPoint;
        }
    };
    /**
     * Item绘制操作
     *
     * @param   painter       painter对象
     * @param   rect          绘制区域
     */
    SGraphyPolygonItem.prototype.onDraw = function (painter, rect) {
        if (this.pointArr.length) {
            painter.pen.color = this.color;
            painter.brush.color = this.fillColor;
            painter.pen.lineWidth = this.width;
            painter.drawPolygon(this.pointArr);
            // let text = ''
            // if (this.businessName || this.businessId) {
            // 	text = '👇   ' + this.businessName
            // } else {
            // 	text = '⬇️   ' + this.initName
            // }
            painter.font.size = this.scale * 200;
            painter.brush.color = SColor.Black;
            // painter.drawText(text,this.centerOfGravityPoint.x,this.centerOfGravityPoint.y)
            painter.drawText(this.viewText, this.centerOfGravityPoint.x, this.centerOfGravityPoint.y);
        }
    };
    SGraphyPolygonItem.prototype.onClick = function (event) {
        this.$emit('click', { item: this, event: event });
        return true;
    }; // Function onClick()
    /**
  * 鼠标双击事件
  *
  * @param   event   保存事件参数
  * @return  boolean
  */
    SGraphyPolygonItem.prototype.onDoubleClick = function (event) {
        this.$emit('doubleClick', event);
        return true;
    };
    /**
  * 鼠标按下事件
  *
  * @param   event   保存事件参数
  * @return  boolean
  */
    SGraphyPolygonItem.prototype.onMouseDown = function (event) {
        this.$emit('mouseDown', event);
        return true;
    }; // Function onMouseDown()
    /**
     * 鼠标移动事件
     *
     * @param   event   保存事件参数
     * @return  boolean
     */
    SGraphyPolygonItem.prototype.onMouseMove = function (event) {
        this.$emit('mouseMove', event);
        return true;
    }; // Function onMouseMove()
    /**
     * 释放鼠标事件
     *
     * @param   event   保存事件参数
     * @return  boolean
     */
    SGraphyPolygonItem.prototype.onMouseUp = function (event) {
        this.$emit('mouseUp', event);
        return true;
    };
    return SGraphyPolygonItem;
}(SGraphyItem)); // Class SGraphyPolygonItem
export default SGraphyPolygonItem;
