From 2144172c7b961d4112850692ed77b46f1ae5d373 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 05 十二月 2025 19:34:53 +0800
Subject: [PATCH] 20251205

---
 src/lujing/Lunjingguihua.java |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/lujing/Lunjingguihua.java b/src/lujing/Lunjingguihua.java
index 45ecc9c..3b1c99b 100644
--- a/src/lujing/Lunjingguihua.java
+++ b/src/lujing/Lunjingguihua.java
@@ -284,10 +284,32 @@
             Vector2D baseDir = new Vector2D(longest.end.x - longest.start.x,
                                             longest.end.y - longest.start.y).normalize();
             Vector2D perp = baseDir.rotate90CCW();
+            Vector2D baseStartVec = new Vector2D(longest.start.x, longest.start.y);
+            double baseProjection = perp.dot(baseStartVec); // keep offsets relative to the longest edge start
 
-            Envelope env = safeArea.getEnvelopeInternal();
-            double minProj = perp.dot(new Vector2D(env.getMinX(), env.getMinY()));
-            double maxProj = perp.dot(new Vector2D(env.getMaxX(), env.getMaxY()));
+            double minProj = Double.POSITIVE_INFINITY;
+            double maxProj = Double.NEGATIVE_INFINITY;
+            Coordinate[] supportCoords = safeArea.getCoordinates();
+            if (supportCoords != null && supportCoords.length > 0) {
+                for (Coordinate coord : supportCoords) {
+                    double projection = perp.dot(new Vector2D(coord.x, coord.y)) - baseProjection;
+                    if (projection < minProj) {
+                        minProj = projection;
+                    }
+                    if (projection > maxProj) {
+                        maxProj = projection;
+                    }
+                }
+            } else {
+                Envelope env = safeArea.getEnvelopeInternal();
+                minProj = perp.dot(new Vector2D(env.getMinX(), env.getMinY())) - baseProjection;
+                maxProj = perp.dot(new Vector2D(env.getMaxX(), env.getMaxY())) - baseProjection;
+            }
+            if (minProj > maxProj) {
+                double tmp = minProj;
+                minProj = maxProj;
+                maxProj = tmp;
+            }
             double first = minProj - width / 2.0;
 
             Geometry originalPoly = createPolygonFromCoordinates(polygon);

--
Gitblit v1.10.0