From 28f48feb957b1beedf296e3f295c4be4114e7297 Mon Sep 17 00:00:00 2001
From: 于杰 <1210123631@qq.com>
Date: 星期四, 14 八月 2025 13:44:32 +0800
Subject: [PATCH] 解决余料计算时右边界检测不准确的问题
---
north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue | 126 ++++++++++++++++++++++-------------------
1 files changed, 68 insertions(+), 58 deletions(-)
diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
index 03bd17c..8136c3d 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizationRect.vue
@@ -652,17 +652,15 @@
const grayRects = glassDetails.filter(r => r.isRemain);
const nonGrayRects = glassDetails.filter(r => !r.isRemain);
- // 鎸夊潗鏍囨帓搴忥紝浼樺厛鎸墄鍧愭爣锛屽叾娆℃寜y鍧愭爣
+ // 鎸夊潗鏍囨帓搴忥紝浼樺厛鎸墆鍧愭爣锛屽叾娆℃寜x鍧愭爣锛堣繖鏍锋洿绗﹀悎浠庝笂鍒颁笅銆佷粠宸﹀埌鍙崇殑闃呰涔犳儻锛�
grayRects.sort((a, b) => {
- if (a.x !== b.x) return a.x - b.x;
- return a.y - b.y;
+ if (a.y !== b.y) return a.y - b.y;
+ return a.x - b.x;
});
if (grayRects.length === 0) return;
const merged = [];
-
- // 浠庣涓�涓煩褰㈠紑濮�
let current = { ...grayRects[0] };
// 閬嶅巻鎵�鏈変綑鏂欑煩褰㈣繘琛屽悎骞�
@@ -695,6 +693,16 @@
current = { ...next };
}
}
+
+ // 娣诲姞鏈�鍚庝竴涓煩褰�
+ merged.push({
+ x: Math.round(current.x),
+ y: Math.round(current.y),
+ width: Math.round(current.width),
+ height: Math.round(current.height),
+ isRemain: true
+ });
+
// 閲嶆柊鏋勫缓鏁扮粍锛氶潪浣欐枡 + 鍚堝苟鍚庣殑浣欐枡
glassDetails.splice(0, glassDetails.length, ...nonGrayRects, ...merged);
};
@@ -942,60 +950,62 @@
const newRemaining = [];
remainingAreas.forEach(area => {
- // 濡傛灉闅滅鐗╀笌褰撳墠鍖哄煙鏈夐噸鍙�
- if (checkOverlap(area, obstacle)) {
- // 鍒囧垎褰撳墠鍖哄煙涓烘渶澶�4涓柊鍖哄煙
-
- // 宸︿晶鍖哄煙
- if (obstacle.x > area.x) {
- newRemaining.push({
- x: area.x,
- y: area.y,
- width: obstacle.x - area.x,
- height: area.height
- });
- }
-
- // 鍙充晶鍖哄煙
- if (obstacle.x + obstacle.width < area.x + area.width) {
- newRemaining.push({
- x: obstacle.x + obstacle.width,
- y: area.y,
- width: area.x + area.width - (obstacle.x + obstacle.width),
- height: area.height
- });
- }
-
- // 涓婃柟鍖哄煙锛堜粎鍦ㄩ殰纰嶇墿宸﹀彸杈圭晫涔嬮棿鐨勫尯鍩燂級
- if (obstacle.y > area.y) {
- const startX = Math.max(area.x, obstacle.x);
- const endX = Math.min(area.x + area.width, obstacle.x + obstacle.width);
- if (endX > startX) {
- newRemaining.push({
- x: startX,
- y: area.y,
- width: endX - startX,
- height: obstacle.y - area.y
- });
- }
- }
-
- // 涓嬫柟鍖哄煙锛堜粎鍦ㄩ殰纰嶇墿宸﹀彸杈圭晫涔嬮棿鐨勫尯鍩燂級
- if (obstacle.y + obstacle.height < area.y + area.height) {
- const startX = Math.max(area.x, obstacle.x);
- const endX = Math.min(area.x + area.width, obstacle.x + obstacle.width);
- if (endX > startX) {
- newRemaining.push({
- x: startX,
- y: obstacle.y + obstacle.height,
- width: endX - startX,
- height: area.y + area.height - (obstacle.y + obstacle.height)
- });
- }
- }
- } else {
- // 娌℃湁閲嶅彔锛屼繚鐣欏師鍖哄煙
+ // 濡傛灉闅滅鐗╀笌褰撳墠鍖哄煙娌℃湁閲嶅彔锛屼繚鐣欏師鍖哄煙
+ if (!checkOverlap(area, obstacle)) {
newRemaining.push(area);
+ return;
+ }
+
+ // 璁$畻閲嶅彔鍖哄煙鐨勮竟鐣�
+ const overlapLeft = Math.max(area.x, obstacle.x);
+ const overlapRight = Math.min(area.x + area.width, obstacle.x + obstacle.width);
+ const overlapTop = Math.max(area.y, obstacle.y);
+ const overlapBottom = Math.min(area.y + area.height, obstacle.y + obstacle.height);
+
+ // 鐢熸垚鍥涗釜鍙兘鐨勬柊鍖哄煙锛堜笂銆佷笅銆佸乏銆佸彸锛�
+
+ // 涓婃柟鍖哄煙
+ if (overlapTop > area.y) {
+ newRemaining.push({
+ x: area.x,
+ y: area.y,
+ width: area.width,
+ height: overlapTop - area.y
+ });
+ }
+
+ // 涓嬫柟鍖哄煙
+ if (overlapBottom < area.y + area.height) {
+ newRemaining.push({
+ x: area.x,
+ y: overlapBottom,
+ width: area.width,
+ height: area.y + area.height - overlapBottom
+ });
+ }
+
+ // 宸︽柟鍖哄煙锛堜粎鍦ㄩ噸鍙犲尯鍩熺殑鍨傜洿鑼冨洿鍐咃級
+ if (overlapLeft > area.x) {
+ const regionTop = overlapTop;
+ const regionBottom = overlapBottom;
+ newRemaining.push({
+ x: area.x,
+ y: regionTop,
+ width: overlapLeft - area.x,
+ height: regionBottom - regionTop
+ });
+ }
+
+ // 鍙虫柟鍖哄煙锛堜粎鍦ㄩ噸鍙犲尯鍩熺殑鍨傜洿鑼冨洿鍐咃級
+ if (overlapRight < area.x + area.width) {
+ const regionTop = overlapTop;
+ const regionBottom = overlapBottom;
+ newRemaining.push({
+ x: overlapRight,
+ y: regionTop,
+ width: area.x + area.width - overlapRight,
+ height: regionBottom - regionTop
+ });
}
});
--
Gitblit v1.8.0