NavisworksTransport/UnitTests/CoordinateSystem/RealObjectPlanarPoseSolverTests.cs
tian 869bfd3787 refactor: 清理 fragment/参考姿态残留命名(默认轴约定一致性)
RealObjectRailAxisConventionResolver:
- 头注释改为默认轴约定语义,参数 referenceAxisX/Y/Z → defaultAxisX/Y/Z

PathAnimationManager:
- 字段 _realObjectReference* → _realObjectDefault*(默认轴约定)
- 方法 RealObjectReferenceRotation → RealObjectDefaultConvention、
  ReferenceBasedRealObjectPlanarPose → DefaultConventionRealObjectPlanarPose
- ResolveCurrentRotationBaseline 参数 hasReferenceRotation/referenceRotation → hasDefaultRotation/defaultRotation

RealObjectPlanarPoseSolver:
- TryCreatePlanarPoseFromReferencePose → FromDefaultPose、
  参数 referenceRotation → defaultRotation、fixedReferenceAxis → fixedDefaultAxis
- 属性 SelectedReferenceAxis* → SelectedDefaultAxis*(含测试同步)

测试: 方法名/局部变量 referenceRotation → defaultRotation 同步
  (VirtualObjectReferencePose 虚拟物体资产参考姿态为有效概念,保留)

TestAutomationHttpService: 过时错误文案(fragment 姿态解析失败)→ 盒内/层级链描述

验证: 单元 185/185、集成 25/25
2026-08-06 00:16:00 +08:00

163 lines
6.9 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NavisworksTransport.Utils.CoordinateSystem;
using System;
using System.Numerics;
namespace NavisworksTransport.UnitTests.CoordinateSystem
{
[TestClass]
public class RealObjectPlanarPoseSolverTests
{
[TestMethod]
public void ShouldChooseClosestCandidateAxis_FromRotatedDefaultPose()
{
Quaternion defaultRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)(Math.PI / 6.0));
Vector3 desiredForward = new Vector3(1.0f, 0.2f, 0.1f);
Vector3 desiredUp = Vector3.UnitZ;
bool ok = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
defaultRotation,
desiredForward,
desiredUp,
out RealObjectPlanarPoseSolution solution);
Assert.IsTrue(ok);
AssertVector(solution.SelectedDefaultAxisLocal, 1.0, 0.0, 0.0);
Vector3 transformedSelectedAxis = Vector3.Normalize(Vector3.Transform(solution.SelectedDefaultAxisLocal, solution.BaselineRotation));
AssertVector(transformedSelectedAxis, desiredForward.X / desiredForward.Length(), desiredForward.Y / desiredForward.Length(), desiredForward.Z / desiredForward.Length(), 1e-4);
}
[TestMethod]
public void ShouldPreferNegativeAxisWhenItMatchesForwardBest()
{
bool ok = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
Quaternion.Identity,
new Vector3(-0.1f, -1.0f, 0.05f),
Vector3.UnitZ,
out RealObjectPlanarPoseSolution solution);
Assert.IsTrue(ok);
AssertVector(solution.SelectedDefaultAxisLocal, 0.0, -1.0, 0.0);
}
[TestMethod]
public void ShouldRespectDesiredUpPlane_WhenDesiredForwardHasVerticalComponent()
{
Vector3 desiredForward = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f));
bool ok = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
Quaternion.Identity,
desiredForward,
Vector3.UnitY,
out RealObjectPlanarPoseSolution solution);
Assert.IsTrue(ok);
Vector3 transformedSelectedAxis = Vector3.Normalize(Vector3.Transform(solution.SelectedDefaultAxisLocal, solution.BaselineRotation));
AssertVector(transformedSelectedAxis, desiredForward.X, desiredForward.Y, desiredForward.Z, 1e-4);
}
[TestMethod]
public void ShouldPreserveDefaultOrthogonalityByApplyingSingleRotationDelta()
{
Quaternion defaultRotation = Quaternion.Normalize(
Quaternion.CreateFromYawPitchRoll(
(float)(Math.PI / 7.0),
(float)(Math.PI / 9.0),
(float)(Math.PI / 11.0)));
Vector3 desiredForward = Vector3.Normalize(new Vector3(-0.3f, 0.8f, 0.52f));
bool ok = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
defaultRotation,
desiredForward,
Vector3.UnitZ,
out RealObjectPlanarPoseSolution solution);
Assert.IsTrue(ok);
Vector3 transformedX = Vector3.Normalize(Vector3.Transform(Vector3.UnitX, solution.BaselineRotation));
Vector3 transformedY = Vector3.Normalize(Vector3.Transform(Vector3.UnitY, solution.BaselineRotation));
Vector3 transformedZ = Vector3.Normalize(Vector3.Transform(Vector3.UnitZ, solution.BaselineRotation));
Assert.AreEqual(1.0, transformedX.Length(), 1e-4);
Assert.AreEqual(1.0, transformedY.Length(), 1e-4);
Assert.AreEqual(1.0, transformedZ.Length(), 1e-4);
Assert.AreEqual(0.0, Vector3.Dot(transformedX, transformedY), 1e-4);
Assert.AreEqual(0.0, Vector3.Dot(transformedY, transformedZ), 1e-4);
Assert.AreEqual(0.0, Vector3.Dot(transformedZ, transformedX), 1e-4);
}
[TestMethod]
public void FixedDefaultAxis_ShouldKeepAxisFamilyAcrossTurn()
{
Quaternion defaultRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI);
Vector3 desiredForwardStart = Vector3.Normalize(new Vector3(-0.95f, 0.0f, 0.31f));
Vector3 desiredForwardTurn = Vector3.Normalize(new Vector3(0.22f, 0.0f, 0.97f));
Vector3 desiredUp = Vector3.UnitY;
bool startOk = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
defaultRotation,
desiredForwardStart,
desiredUp,
out RealObjectPlanarPoseSolution startSolution);
Assert.IsTrue(startOk);
bool turnOk = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
defaultRotation,
desiredForwardTurn,
desiredUp,
startSolution.SelectedDefaultAxisDirection,
out RealObjectPlanarPoseSolution turnSolution);
Assert.IsTrue(turnOk);
Assert.AreEqual(startSolution.SelectedDefaultAxisDirection, turnSolution.SelectedDefaultAxisDirection);
Vector3 transformedSelectedAxis = Vector3.Normalize(
Vector3.Transform(turnSolution.SelectedDefaultAxisLocal, turnSolution.BaselineRotation));
AssertVector(
transformedSelectedAxis,
desiredForwardTurn.X,
desiredForwardTurn.Y,
desiredForwardTurn.Z,
1e-4);
}
[TestMethod]
public void FixedPositiveX_ShouldNotSwitchToZ_WhenPathLeansTowardZ()
{
Quaternion defaultRotation = Quaternion.Identity;
Vector3 desiredForward = Vector3.Normalize(new Vector3(-0.690f, 0.0f, 0.724f));
Vector3 desiredUp = Vector3.UnitY;
bool ok = RealObjectPlanarPoseSolver.TryCreatePlanarPoseFromDefaultPose(
defaultRotation,
desiredForward,
desiredUp,
LocalAxisDirection.PositiveX,
out RealObjectPlanarPoseSolution solution);
Assert.IsTrue(ok);
Assert.AreEqual(LocalAxisDirection.PositiveX, solution.SelectedDefaultAxisDirection);
AssertVector(solution.SelectedDefaultAxisLocal, 1.0, 0.0, 0.0);
Vector3 transformedSelectedAxis = Vector3.Normalize(
Vector3.Transform(solution.SelectedDefaultAxisLocal, solution.BaselineRotation));
AssertVector(
transformedSelectedAxis,
desiredForward.X,
desiredForward.Y,
desiredForward.Z,
1e-4);
}
private static void AssertVector(Vector3 vector, double x, double y, double z, double tolerance = 1e-6)
{
Assert.AreEqual(x, vector.X, tolerance);
Assert.AreEqual(y, vector.Y, tolerance);
Assert.AreEqual(z, vector.Z, tolerance);
}
}
}