|
@@ -1,8 +1,14 @@
|
|
|
import { Transformer } from "konva/lib/shapes/Transformer";
|
|
|
-import { CopyProps, copyEntityAttrib } from "../../shared";
|
|
|
+import {
|
|
|
+ CopyProps,
|
|
|
+ copyEntityAttrib,
|
|
|
+ isLineIntersectingPolygon,
|
|
|
+} from "../../shared";
|
|
|
import { Poi, PoiAttrib } from "./poi";
|
|
|
import { Group } from "konva/lib/Group";
|
|
|
import { Rect } from "konva/lib/shapes/Rect";
|
|
|
+import { Transform } from "konva/lib/Util";
|
|
|
+import { MathUtils } from "three";
|
|
|
|
|
|
export class EditPoi<T extends PoiAttrib = PoiAttrib> extends Poi<T> {
|
|
|
initShape() {
|
|
@@ -50,6 +56,52 @@ export class EditPoi<T extends PoiAttrib = PoiAttrib> extends Poi<T> {
|
|
|
return group;
|
|
|
}
|
|
|
|
|
|
+ isIntersecting() {
|
|
|
+ const room = this.container.attrib.data.rooms[0];
|
|
|
+ if (!room) return;
|
|
|
+ const points = room.points;
|
|
|
+ const lines = room.lines.map((line) =>
|
|
|
+ line.pointIds.flatMap((pid) => points.find(({ id }) => pid === id))
|
|
|
+ );
|
|
|
+
|
|
|
+ const w = 0.8;
|
|
|
+ const h = 0.8 * (800 / 1000);
|
|
|
+
|
|
|
+ const poi = this.attrib;
|
|
|
+ const poyPoints = [
|
|
|
+ [poi.x - w / 2, poi.y - h / 2],
|
|
|
+ [poi.x + w / 2, poi.y - h / 2],
|
|
|
+ [poi.x + w / 2, poi.y + h / 2],
|
|
|
+ [poi.x - w / 2, poi.y + h / 2],
|
|
|
+ [poi.x - w / 2, poi.y - h / 2],
|
|
|
+ ];
|
|
|
+ const tf = new Transform()
|
|
|
+ .translate(poi.x, poi.y)
|
|
|
+ .rotate(MathUtils.degToRad(poi.rotate || 0))
|
|
|
+ .translate(-poi.x, -poi.y);
|
|
|
+ poyPoints.forEach((point) => {
|
|
|
+ const tpoint = tf.point({ x: point[0], y: point[1] });
|
|
|
+ point[0] = tpoint.x;
|
|
|
+ point[1] = tpoint.y;
|
|
|
+ });
|
|
|
+
|
|
|
+ const isJoin = lines.some((line) => {
|
|
|
+ return isLineIntersectingPolygon(poyPoints, [
|
|
|
+ line[0].x,
|
|
|
+ line[0].y,
|
|
|
+ line[1].x,
|
|
|
+ line[1].y,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+ this.attrib.intersect = isJoin;
|
|
|
+ return isJoin;
|
|
|
+ }
|
|
|
+
|
|
|
+ diffRedraw(): void {
|
|
|
+ this.isIntersecting();
|
|
|
+ super.diffRedraw();
|
|
|
+ }
|
|
|
+
|
|
|
mounted(): void {
|
|
|
super.enableMouseAct(this.actShape);
|
|
|
this.bus.on("shapeStatusChange", (data) => {
|