NavisworksTransport/UnitTests/CoordinateSystem/RailPreservedPoseTests.cs

146 lines
6.3 KiB
C#

using Autodesk.Navisworks.Api;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NavisworksTransport.Core.Animation;
using NavisworksTransport.Utils.CoordinateSystem;
namespace NavisworksTransport.UnitTests.CoordinateSystem
{
[TestClass]
public class RailPreservedPoseTests
{
[TestMethod]
public void ResolvePreservedPoseRotation_ShouldPreferActualGeometryRotationForRealObjects()
{
Rotation3D fallbackRotation = new Rotation3D(0.0, 0.0, 0.0, 1.0);
Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678);
Rotation3D resolved = PathAnimationManager.ResolvePreservedPoseRotation(
preferActualGeometryRotation: true,
hasActualGeometryRotation: true,
actualGeometryRotation: actualGeometryRotation,
fallbackRotation: fallbackRotation);
Assert.AreEqual(actualGeometryRotation.A, resolved.A, 1e-9);
Assert.AreEqual(actualGeometryRotation.B, resolved.B, 1e-9);
Assert.AreEqual(actualGeometryRotation.C, resolved.C, 1e-9);
Assert.AreEqual(actualGeometryRotation.D, resolved.D, 1e-9);
}
[TestMethod]
public void ResolvePreservedPoseRotation_ShouldFallbackWhenActualGeometryRotationUnavailable()
{
Rotation3D fallbackRotation = new Rotation3D(0.0, 0.0, 0.38268343, 0.92387953);
Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678);
Rotation3D resolved = PathAnimationManager.ResolvePreservedPoseRotation(
preferActualGeometryRotation: true,
hasActualGeometryRotation: false,
actualGeometryRotation: actualGeometryRotation,
fallbackRotation: fallbackRotation);
Assert.AreEqual(fallbackRotation.A, resolved.A, 1e-9);
Assert.AreEqual(fallbackRotation.B, resolved.B, 1e-9);
Assert.AreEqual(fallbackRotation.C, resolved.C, 1e-9);
Assert.AreEqual(fallbackRotation.D, resolved.D, 1e-9);
}
[TestMethod]
public void ShouldPreservePathRotationForFrames_ShouldEnableHoistingWhenTranslationModeHasLockedRotation()
{
bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames(
PathType.Hoisting,
ObjectStartPlacementMode.PreserveInitialPose,
hasPreservedRotation: true);
Assert.IsTrue(shouldPreserve);
}
[TestMethod]
public void ShouldPreservePathRotationForFrames_ShouldEnableRailWhenTranslationModeHasLockedRotation()
{
bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames(
PathType.Rail,
ObjectStartPlacementMode.PreserveInitialPose,
hasPreservedRotation: true);
Assert.IsTrue(shouldPreserve);
}
[TestMethod]
public void ShouldPreservePathRotationForFrames_ShouldDisableGroundEvenInTranslationMode()
{
bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames(
PathType.Ground,
ObjectStartPlacementMode.PreserveInitialPose,
hasPreservedRotation: true);
Assert.IsFalse(shouldPreserve);
}
[TestMethod]
public void ShouldPreservePathRotationForFrames_ShouldDisableWhenLockedRotationMissing()
{
bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames(
PathType.Hoisting,
ObjectStartPlacementMode.PreserveInitialPose,
hasPreservedRotation: false);
Assert.IsFalse(shouldPreserve);
}
[TestMethod]
public void ShouldAllowFragmentPlanarFallback_ShouldDisableHoisting()
{
Assert.IsFalse(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Hoisting));
Assert.IsTrue(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Ground));
Assert.IsTrue(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Rail));
}
[TestMethod]
public void ResolveCurrentRotationBaseline_ShouldPreferActualGeometryForHoisting()
{
Rotation3D trackedRotation = new Rotation3D(0.0, 0.0, 0.0, 1.0);
Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678);
Rotation3D resolved = PathAnimationManager.ResolveCurrentRotationBaseline(
PathType.Hoisting,
isRealObjectMode: true,
hasTrackedRotation: true,
trackedRotation: trackedRotation,
hasReferenceRotation: false,
referenceRotation: Rotation3D.Identity,
transformRotation: Rotation3D.Identity,
hasActualGeometryRotation: true,
actualGeometryRotation: actualGeometryRotation);
Assert.AreEqual(actualGeometryRotation.A, resolved.A, 1e-9);
Assert.AreEqual(actualGeometryRotation.B, resolved.B, 1e-9);
Assert.AreEqual(actualGeometryRotation.C, resolved.C, 1e-9);
Assert.AreEqual(actualGeometryRotation.D, resolved.D, 1e-9);
}
[TestMethod]
public void ResolveCurrentRotationBaseline_ShouldKeepTrackedRotationForGround()
{
Rotation3D trackedRotation = new Rotation3D(0.0, 0.0, 0.38268343, 0.92387953);
Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678);
Rotation3D resolved = PathAnimationManager.ResolveCurrentRotationBaseline(
PathType.Ground,
isRealObjectMode: true,
hasTrackedRotation: true,
trackedRotation: trackedRotation,
hasReferenceRotation: false,
referenceRotation: Rotation3D.Identity,
transformRotation: Rotation3D.Identity,
hasActualGeometryRotation: true,
actualGeometryRotation: actualGeometryRotation);
Assert.AreEqual(trackedRotation.A, resolved.A, 1e-9);
Assert.AreEqual(trackedRotation.B, resolved.B, 1e-9);
Assert.AreEqual(trackedRotation.C, resolved.C, 1e-9);
Assert.AreEqual(trackedRotation.D, resolved.D, 1e-9);
}
}
}