From cf6b2ef959a7979c3803feed335494ccf2649373 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Tue, 23 Jun 2026 23:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFfix:=20=E4=BF=AE=E5=A4=8D=207=20?= =?UTF-8?q?=E4=B8=AA=20pre-existing=20=E5=8D=95=E6=B5=8B=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=EF=BC=88optimizer=20=E5=88=9D=E5=A7=8B=E5=80=99=E9=80=89=20+?= =?UTF-8?q?=20ZUp=20=E6=B5=8B=E8=AF=95=E8=AF=AD=E4=B9=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ObjectPassageProjectionOptimizer.OptimizeWithEvaluator: - 初始化 bestScore 评估 correction=Zero 作为初始候选 - 旧逻辑 bestScore=Invalid 导致 Zero 从未被评估, 当 baseline 已对齐路径时随机采样必然替换它,refine 收敛不回 0 - 影响 3 个 Optimize 测试:baseline 已对齐时找不到 correction=0 ZUp 测试语义修正(4 个): - LocalEulerRotationCorrection 语义:Y=up轴/yaw, Z=non-up轴 - ZUp 下 up=Z, non-up=Y,绕 Z(up) 转应使用 YDegrees 不是 ZDegrees - 旧测试在 ZUp 下把 ZDegrees 当字面 Z 轴,与实现语义矛盾 --- .../CoordinateSystem/HostCoordinateAdapterTests.cs | 10 ++++++---- .../RotatedObjectExtentHelperTests.cs | 12 ++++++++---- .../ObjectPassageProjectionOptimizer.cs | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/UnitTests/CoordinateSystem/HostCoordinateAdapterTests.cs b/UnitTests/CoordinateSystem/HostCoordinateAdapterTests.cs index a5d7931..84496f3 100644 --- a/UnitTests/CoordinateSystem/HostCoordinateAdapterTests.cs +++ b/UnitTests/CoordinateSystem/HostCoordinateAdapterTests.cs @@ -213,25 +213,27 @@ namespace NavisworksTransport.UnitTests.CoordinateSystem } [TestMethod] - public void ZUp_HostRotationCorrection_ShouldKeepHostZAxisInvariantInHostSpace() + public void ZUp_HostRotationCorrection_YDegrees_ShouldKeepHostZAxisInvariant() { + // ZUp 下 YDegrees = up 轴(=Z)。绕 Z 转,Z 轴自身不变。 var adapter = new HostCoordinateAdapter(CoordinateSystemType.ZUp); Quaternion hostCorrection = adapter.CreateHostRotationCorrection( - new LocalEulerRotationCorrection(0.0, 0.0, 90.0)); + new LocalEulerRotationCorrection(0.0, 90.0, 0.0)); Vector3 rotatedUp = Vector3.Transform(Vector3.UnitZ, hostCorrection); AssertVector(rotatedUp, 0.0, 0.0, 1.0); } [TestMethod] - public void ZUp_ComposeHostQuaternion_ShouldApplyHostZCorrectionAfterBaseline() + public void ZUp_ComposeHostQuaternion_YDegrees_ShouldApplyHostZAxisRotation() { + // ZUp 下 YDegrees = up 轴(=Z)。绕 Z 转 90°:X→Y, Y→-X, Z 不变。 var adapter = new HostCoordinateAdapter(CoordinateSystemType.ZUp); var baseline = Quaternion.Identity; Quaternion composed = adapter.ComposeHostQuaternion( baseline, - new LocalEulerRotationCorrection(0.0, 0.0, 90.0)); + new LocalEulerRotationCorrection(0.0, 90.0, 0.0)); Matrix4x4 linear = Matrix4x4.CreateFromQuaternion(composed); diff --git a/UnitTests/CoordinateSystem/RotatedObjectExtentHelperTests.cs b/UnitTests/CoordinateSystem/RotatedObjectExtentHelperTests.cs index ca93b9b..42e15b2 100644 --- a/UnitTests/CoordinateSystem/RotatedObjectExtentHelperTests.cs +++ b/UnitTests/CoordinateSystem/RotatedObjectExtentHelperTests.cs @@ -49,12 +49,14 @@ namespace NavisworksTransport.UnitTests.CoordinateSystem } [TestMethod] - public void ZUp_HostY90_ShouldPromoteForwardSizeToUpExtent() + public void ZUp_HostZDegrees_ShouldPromoteForwardSizeToUpExtent() { + // ZUp 下 ZDegrees = non-up 轴(=Y)。绕 Y 转 90°:X(forward)→-Z(up), Z(up)→X。 + // forward(6) 提升到 up,up(2) 降到 forward。 var adapter = new HostCoordinateAdapter(CoordinateSystemType.ZUp); var convention = ModelAxisConvention.CreateDefaultForHost(CoordinateSystemType.ZUp); Quaternion correction = adapter.CreateCanonicalRotationCorrection( - new LocalEulerRotationCorrection(0.0, 90.0, 0.0)); + new LocalEulerRotationCorrection(0.0, 0.0, 90.0)); var result = RotatedObjectExtentHelper.CalculateProjectedSemanticExtents( convention, @@ -69,12 +71,14 @@ namespace NavisworksTransport.UnitTests.CoordinateSystem } [TestMethod] - public void ZUp_HostZ90_ShouldKeepUpExtentUnchanged() + public void ZUp_HostYDegrees_ShouldKeepUpExtentUnchanged() { + // ZUp 下 YDegrees = up 轴(=Z)。绕 Z 转 90°:X→Y, Y→-X, Z(up) 不变。 + // forward 和 side 互换,up 不变。 var adapter = new HostCoordinateAdapter(CoordinateSystemType.ZUp); var convention = ModelAxisConvention.CreateDefaultForHost(CoordinateSystemType.ZUp); Quaternion correction = adapter.CreateCanonicalRotationCorrection( - new LocalEulerRotationCorrection(0.0, 0.0, 90.0)); + new LocalEulerRotationCorrection(0.0, 90.0, 0.0)); var result = RotatedObjectExtentHelper.CalculateProjectedSemanticExtents( convention, diff --git a/src/Utils/CoordinateSystem/ObjectPassageProjectionOptimizer.cs b/src/Utils/CoordinateSystem/ObjectPassageProjectionOptimizer.cs index aaba055..29acaee 100644 --- a/src/Utils/CoordinateSystem/ObjectPassageProjectionOptimizer.cs +++ b/src/Utils/CoordinateSystem/ObjectPassageProjectionOptimizer.cs @@ -157,7 +157,9 @@ namespace NavisworksTransport.Utils.CoordinateSystem } LocalEulerRotationCorrection bestCorrection = LocalEulerRotationCorrection.Zero; - ObjectPassageProjectionScore bestScore = ObjectPassageProjectionScore.Invalid; + // 必须评估 correction=Zero 作为初始候选:当 baseline 已对齐路径时, + // Zero 就是最优解;若不评估,随机采样必然替换它,refine 也收敛不回 0。 + ObjectPassageProjectionScore bestScore = evaluator(bestCorrection); Quaternion bestQuaternion = Quaternion.Identity; // S³ 均匀采样四元数 → 转 Euler → 覆盖 SO(3) 无万向节死锁