/* * ********************************************************************************************************************* * * !! * .F88X * X8888Y * .}888888N; * i888888N; .:! .I$WI: * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8& * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I * +888888N; .8888888Y "&&8Y.}8, * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$* * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~ * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi' * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/ * .:R888888I * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司 * ~8888' * .!88~ All rights reserved. * * ********************************************************************************************************************* */ import { Door } from "../../types/floor/Door"; import { SPainter, SPoint, SRect } from "@persagy-web/draw"; import { SMathUtil } from "../../utils/SMathUtil"; import { ItemOrder, ItemColor } from "../.."; import { SGraphItem } from "@persagy-web/graph"; /** * 门 item * * @author 郝建龙 */ export class SDoorItem extends SGraphItem { /** 门数据 */ data: Door; /** 门轮廓线坐标 list */ private readonly pointArr: SPoint[] = []; /** 门长度 */ private readonly r: number = 0; /** 角度 */ private readonly ang: number = 0; /** 旋转点 */ private readonly p: SPoint = new SPoint(0, 0); /** 旋转起始角度,结束角度 + Math.PI / 2 */ private readonly startAng: number = -Math.PI / 2; /** X 坐标最小值 */ private minX = Number.MAX_SAFE_INTEGER; /** X 坐标最大值 */ private maxX = Number.MIN_SAFE_INTEGER; /** Y 坐标最小值 */ private minY = Number.MAX_SAFE_INTEGER; /** Y 坐标最大值 */ private maxY = Number.MIN_SAFE_INTEGER; /** * 构造函数 * * @param parent 指向父对象 * @param data 门数据 */ constructor(parent: SGraphItem | null, data: Door) { super(parent); this.data = data; this.zOrder = ItemOrder.doorOrder; if (this.data.OutLine.length) { this.pointArr = this.data.OutLine[0].map( (t): SPoint => { let x = t.X; let y = -t.Y; if (x < this.minX) { this.minX = x; } if (y < this.minY) { this.minY = y; } if (x > this.maxX) { this.maxX = x; } if (y > this.maxY) { this.maxY = y; } return new SPoint(t.X, -t.Y); } ); let p1 = this.pointArr[0]; let p2 = this.pointArr[1]; // 旋转点 this.p = p1; const HX = (this.data.HandDirection.X = Number( this.data.HandDirection.X.toFixed() )); const HY = (this.data.HandDirection.Y = Number( this.data.HandDirection.Y.toFixed() )); const FX = (this.data.FaceDirection.X = Number( this.data.FaceDirection.X.toFixed() )); const FY = (this.data.FaceDirection.Y = Number( this.data.FaceDirection.Y.toFixed() )); // 向量点乘 => x1 * x2 + y1 * y2,大于0同向 let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY; if (dotProduct > 0) { this.p = p2; p2 = p1; p1 = this.p; } // 两点间距离 this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y); // 门朝向角度 let fo = Math.atan(-FY / FX); this.ang = FX > 0 ? fo : fo + Math.PI; // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针 let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX; if (direction > 0) { this.startAng = 0; } } } // Constructor /** * Item 对象边界区域 * * @return 边界矩形 */ boundingRect(): SRect { return new SRect(0, 0, this.r, this.r); } // Function boundingRect() /** * Item 绘制操作 * * @param painter 绘制对象 */ onDraw(painter: SPainter): void { painter.translate(this.p.x, this.p.y); painter.rotate(this.ang); painter.pen.lineWidth = 100; painter.pen.color = ItemColor.doorColor; painter.drawLine(0, 0, this.r, 0); painter.pen.lineDash = [50, 100]; painter.pen.lineWidth = painter.toPx(1); // painter.drawArc( // -this.r, // -this.r, // this.r * 2, // this.r * 2, // this.startAng, // this.startAng + Math.PI / 2 // ); } // Function onDraw() } // Class SDoorItem