From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/components/MagicCubeEditor/util.ts |   72 ++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/src/components/MagicCubeEditor/util.ts b/src/components/MagicCubeEditor/util.ts
new file mode 100644
index 0000000..e7c6465
--- /dev/null
+++ b/src/components/MagicCubeEditor/util.ts
@@ -0,0 +1,72 @@
+// 鍧愭爣鐐�
+export interface Point {
+  x: number
+  y: number
+}
+
+// 鐭╁舰
+export interface Rect {
+  // 宸︿笂瑙� X 杞村潗鏍�
+  left: number
+  // 宸︿笂瑙� Y 杞村潗鏍�
+  top: number
+  // 鍙充笅瑙� X 杞村潗鏍�
+  right: number
+  // 鍙充笅瑙� Y 杞村潗鏍�
+  bottom: number
+  // 鐭╁舰瀹藉害
+  width: number
+  // 鐭╁舰楂樺害
+  height: number
+}
+
+/**
+ * 鍒ゆ柇涓や釜鐭╁舰鏄惁閲嶅彔
+ * @param a 鐭╁舰 A
+ * @param b 鐭╁舰 B
+ */
+export const isOverlap = (a: Rect, b: Rect): boolean => {
+  return (
+    a.left < b.left + b.width &&
+    a.left + a.width > b.left &&
+    a.top < b.top + b.height &&
+    a.height + a.top > b.top
+  )
+}
+/**
+ * 妫�鏌ュ潗鏍囩偣鏄惁鍦ㄧ煩褰㈠唴
+ * @param hotArea 鐭╁舰
+ * @param point 鍧愭爣
+ */
+export const isContains = (hotArea: Rect, point: Point): boolean => {
+  return (
+    point.x >= hotArea.left &&
+    point.x < hotArea.right &&
+    point.y >= hotArea.top &&
+    point.y < hotArea.bottom
+  )
+}
+
+/**
+ * 鍦ㄤ袱涓潗鏍囩偣涓棿锛屽垱寤轰竴涓煩褰�
+ *
+ * 瀛樺湪浠ヤ笅鎯呭喌锛�
+ * 1. 涓や釜鍧愭爣鐐规槸鍚屼竴涓綅缃紝鍙崰涓�涓綅缃殑姝f柟褰紝瀹介珮閮戒负 1
+ * 2. X 杞村潗鏍囩浉鍚岋紝鍙崰涓�琛岀殑鐭╁舰锛岄珮搴︿负 1
+ * 3. Y 杞村潗鏍囩浉鍚岋紝鍙崰涓�鍒楃殑鐭╁舰锛屽搴︿负 1
+ * 4. 澶氳澶氬垪鐨勭煩褰�
+ *
+ * @param a 鍧愭爣鐐逛竴
+ * @param b 鍧愭爣鐐逛簩
+ */
+export const createRect = (a: Point, b: Point): Rect => {
+  // 璁$畻鐭╁舰鐨勮寖鍥�
+  const [left, left2] = [a.x, b.x].sort()
+  const [top, top2] = [a.y, b.y].sort()
+  const right = left2 + 1
+  const bottom = top2 + 1
+  const height = bottom - top
+  const width = right - left
+
+  return { left, right, top, bottom, height, width }
+}

--
Gitblit v1.8.0