|
@@ -142,7 +142,7 @@ interface Point {
|
|
* @param angle - 顺时针旋转角度 0, 90, 180, 270
|
|
* @param angle - 顺时针旋转角度 0, 90, 180, 270
|
|
* @returns 旋转后的矩形 { left, top, width, height }
|
|
* @returns 旋转后的矩形 { left, top, width, height }
|
|
*/
|
|
*/
|
|
-export function rotateRect(src_rect: Rect, pRadar: Point, angle: number): Rect {
|
|
|
|
|
|
+export function rotateRect_cw(src_rect: Rect, pRadar: Point, angle: number): Rect {
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0
|
|
if (![0, 90, 180, 270].includes(angle)) angle = 0
|
|
|
|
|
|
const { left, top, width, height } = src_rect
|
|
const { left, top, width, height } = src_rect
|
|
@@ -192,6 +192,63 @@ export function rotateRect(src_rect: Rect, pRadar: Point, angle: number): Rect {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 逆时针旋转矩形(家具/检测区域)
|
|
|
|
+ * @param src_rect - 输入矩形 { left, top, width, height }
|
|
|
|
+ * @param pRadar - 雷达中心坐标 { x, y }
|
|
|
|
+ * @param angle - 逆时针旋转角度 0, 90, 180, 270
|
|
|
|
+ * @returns 旋转后的矩形 { left, top, width, height }
|
|
|
|
+ */
|
|
|
|
+export function rotateRect_ccw(src_rect: Rect, pRadar: Point, angle: number): Rect {
|
|
|
|
+ if (![0, 90, 180, 270].includes(angle)) angle = 0
|
|
|
|
+
|
|
|
|
+ const { left, top, width, height } = src_rect
|
|
|
|
+ const cx = left + width / 2
|
|
|
|
+ const cy = top + height / 2
|
|
|
|
+
|
|
|
|
+ const dx = cx - pRadar.x
|
|
|
|
+ const dy = cy - pRadar.y
|
|
|
|
+
|
|
|
|
+ let new_dx: number = 0
|
|
|
|
+ let new_dy: number = 0
|
|
|
|
+
|
|
|
|
+ switch (angle) {
|
|
|
|
+ case 0:
|
|
|
|
+ new_dx = dx
|
|
|
|
+ new_dy = dy
|
|
|
|
+ break
|
|
|
|
+ case 90:
|
|
|
|
+ new_dx = dy
|
|
|
|
+ new_dy = -dx
|
|
|
|
+ break
|
|
|
|
+ case 180:
|
|
|
|
+ new_dx = -dx
|
|
|
|
+ new_dy = -dy
|
|
|
|
+ break
|
|
|
|
+ case 270:
|
|
|
|
+ new_dx = -dy
|
|
|
|
+ new_dy = dx
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const new_cx = pRadar.x + new_dx
|
|
|
|
+ const new_cy = pRadar.y + new_dy
|
|
|
|
+
|
|
|
|
+ let new_width = width
|
|
|
|
+ let new_height = height
|
|
|
|
+ if (angle === 90 || angle === 270) {
|
|
|
|
+ new_width = height
|
|
|
|
+ new_height = width
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ left: new_cx - new_width / 2,
|
|
|
|
+ top: new_cy - new_height / 2,
|
|
|
|
+ width: new_width,
|
|
|
|
+ height: new_height,
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
interface Point {
|
|
interface Point {
|
|
x: number
|
|
x: number
|
|
y: number
|
|
y: number
|