//-----------------------------------------------------------------------
//
// Copyright (c) 2010 Deltares. All rights reserved.
//
// Tom The
// tom.the@deltares.nl
// 04-06-2010
//
// Tests for CoordinateSystemConverter object
//
//-----------------------------------------------------------------------
using Deltares.Geometry;
using Deltares.Geotechnics;
using Deltares.Geotechnics.GeotechnicalGeometry;
using Deltares.Dam.Data;
using Deltares.Geotechnics.SurfaceLines;
using NUnit.Framework;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class CoordinateSystemConverterTest
{
///
/// Create result Surface line
///
///
private SurfaceLine2 CreateResultingLocalSurfaceLine()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(0.0000, 0.0000, 0.0000));
surfaceline.Geometry.Points.Add(new GeometryPoint(27.9508, 0.0000, 2.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(55.9017, 0.0000, 5.00000));
surfaceline.Geometry.Points.Add(new GeometryPoint(83.8525, 0.0000, 7.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(111.8034, 0.0000, 10.0000));
return surfaceline;
}
private SurfaceLine2 DefaultTestSurfaceLine()
{
return new SurfaceLine2
{
Name = "SL1",
Geometry = new LocalizedGeometryPointString(),
};
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlpha0Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(10000.0000, 2000.0000, 0.0000));
surfaceline.Geometry.Points.Add(new GeometryPoint(10027.9508, 2000.0000, 2.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(10055.9017, 2000.0000, 5.00000));
surfaceline.Geometry.Points.Add(new GeometryPoint(10083.8525, 2000.0000, 7.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(10111.8034, 2000.0000, 10.0000));
return surfaceline;
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlpha90Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(2000.0000, 10000.0000, 0.0000));
surfaceline.Geometry.Points.Add(new GeometryPoint(2000.0000, 10027.9508, 2.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(2000.0000, 10055.9017, 5.00000));
surfaceline.Geometry.Points.Add(new GeometryPoint(2000.0000, 10083.8525, 7.50000));
surfaceline.Geometry.Points.Add(new GeometryPoint(2000.0000, 10111.8034, 10.0000));
return surfaceline;
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(10000.0, 20000.0, 0.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(10012.5, 20025.0, 2.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(10025.0, 20050.0, 5.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(10037.5, 20075.0, 7.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(10050.0, 20100.0, 10.0));
return surfaceline;
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlphaBetween90and180Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(-10000.0, 20000.0, 0.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10012.5, 20025.0, 2.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10025.0, 20050.0, 5.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10037.5, 20075.0, 7.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10050.0, 20100.0, 10.0));
return surfaceline;
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlphaBetween180and270Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(-10000.0, -20000.0, 0.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10012.5, -20025.0, 2.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10025.0, -20050.0, 5.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10037.5, -20075.0, 7.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(-10050.0, -20100.0, 10.0));
return surfaceline;
}
///
/// Create Surface line
///
///
private SurfaceLine2 CreateGlobalSurfaceLineWithAlphaBetween270and360Degrees()
{
var surfaceline = DefaultTestSurfaceLine();
surfaceline.Geometry.Points.Add(new GeometryPoint(10000.0, -20000.0, 0.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(10012.5, -20025.0, 2.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(10025.0, -20050.0, 5.0));
surfaceline.Geometry.Points.Add(new GeometryPoint(10037.5, -20075.0, 7.5));
surfaceline.Geometry.Points.Add(new GeometryPoint(10050.0, -20100.0, 10.0));
return surfaceline;
}
///
/// Create result PL1-line
///
///
private PL1Line CreateResultingLocalPL1Line()
{
var pl1line = new PL1Line();
pl1line.Points.Add(new GeometryPoint(0.0000, 0.0000, -1.0000));
pl1line.Points.Add(new GeometryPoint(27.9508, 0.0000, 1.50000));
pl1line.Points.Add(new GeometryPoint(55.9017, 0.0000, 4.00000));
pl1line.Points.Add(new GeometryPoint(83.8525, 0.0000, 6.50000));
pl1line.Points.Add(new GeometryPoint(111.8034, 0.0000, 9.0000));
return pl1line;
}
///
/// Create test PL1-line
///
/// a Pl1-line with angle in XY plane between 0 and 90 degrees
private PL1Line CreateGlobalPL1LineWithAlphaBetween0and90Degrees()
{
var pl1line = new PL1Line();
pl1line.Points.Add(new GeometryPoint(10000.0, 20000.0, -1.0));
pl1line.Points.Add(new GeometryPoint(10012.5, 20025.0, 1.5));
pl1line.Points.Add(new GeometryPoint(10025.0, 20050.0, 4.0));
pl1line.Points.Add(new GeometryPoint(10037.5, 20075.0, 6.5));
pl1line.Points.Add(new GeometryPoint(10050.0, 20100.0, 9.0));
return pl1line;
}
private void CheckResultingLocalSurfaceLine(SurfaceLine2 localSurfaceLine)
{
using (SurfaceLine2 expectedLocalSurfaceLine = CreateResultingLocalSurfaceLine())
{
Assert.IsTrue(expectedLocalSurfaceLine.Geometry.Equals(localSurfaceLine.Geometry));
}
}
private void CheckResultingLocalPL1Line(PL1Line localPL1Line)
{
PL1Line expectedLocalPL1Line = CreateResultingLocalPL1Line();
Assert.IsTrue(expectedLocalPL1Line.Equals(localPL1Line));
}
[Test]
[ExpectedException(typeof(CoordinateSystemConverterException))]
public void ThrowsExceptionIfCoordinateSystemConverterNotInitialized()
{
const double cTolerance = 0.0000001;
var coordinateSystemConverter = new CoordinateSystemConverter();
Assert.AreEqual(0.0, coordinateSystemConverter.CosAlpha, cTolerance);
}
[Test]
public void CanConvertPoint()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees())
using (SurfaceLine2 referenceSurfaceline = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees())
{
coordinateSystemConverter.DefineGlobalXYZBasedOnLine(surfaceLine.Geometry);
// Convert to global
GeometryPoint firstPoint = surfaceLine.Geometry.Points[0];
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(firstPoint);
Assert.IsTrue(firstPoint.LocationEquals(new GeometryPoint(0.0000, 0.0000, 0.0000)), "First point not converted correctly to local");
GeometryPoint lastPoint = surfaceLine.Geometry.Points[surfaceLine.Geometry.Count - 1];
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(lastPoint);
Assert.IsTrue(lastPoint.LocationEquals(new GeometryPoint(111.8034, 0.0000, 10.0000)), "Last point not converted correctly to local");
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(firstPoint);
Assert.IsTrue(firstPoint.LocationEquals(referenceSurfaceline.Geometry.Points[0]), "First point not converted correctly to global");
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(lastPoint);
Assert.IsTrue(lastPoint.LocationEquals(referenceSurfaceline.Geometry.Points[referenceSurfaceline.Geometry.Count - 1]), "Last point not converted correctly to global");
}
}
[Test]
public void IsGlobalXYZCorrectlyDefined()
{
const double cTolerance = 0.0000001;
var coordinateSystemConverter = new CoordinateSystemConverter();
using (SurfaceLine2 surfaceline = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees())
{
coordinateSystemConverter.DefineGlobalXYZBasedOnLine(surfaceline.Geometry);
Assert.AreEqual(2.0, coordinateSystemConverter.SinAlpha / coordinateSystemConverter.CosAlpha, cTolerance);
}
}
[Test]
public void ArePropertiesUnchangedWhenSurfacelIneIsConverted()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using (SurfaceLine2 surfaceline = CreateGlobalSurfaceLineWithAlpha0Degrees())
using (SurfaceLine2 localSurfaceLine = CreateGlobalSurfaceLineWithAlpha0Degrees())
{
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(localSurfaceLine.Geometry);
Assert.AreEqual(surfaceline.Name, localSurfaceLine.Name);
}
}
[Test]
public void CanConvertSurfaceLineWithAlpha0Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using (SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlpha0Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlpha0Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertSurfaceLineWithAlpha90Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlpha90Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlpha90Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertSurfaceLineWithAlphaBetween0and90Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlphaBetween0and90Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertSurfaceLineWithAlphaBetween90and180Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween90and180Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlphaBetween90and180Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertSurfaceLineWithAlphaBetween180and270Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween180and270Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlphaBetween180and270Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertSurfaceLineWithAlphaBetween270and360Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
using(SurfaceLine2 surfaceLine = CreateGlobalSurfaceLineWithAlphaBetween270and360Degrees())
using (SurfaceLine2 expectedGlobalSurfaceLine = CreateGlobalSurfaceLineWithAlphaBetween270and360Degrees())
{
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(surfaceLine.Geometry);
CheckResultingLocalSurfaceLine(surfaceLine);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(surfaceLine.Geometry);
Assert.IsTrue(expectedGlobalSurfaceLine.Geometry.Equals(surfaceLine.Geometry));
}
}
[Test]
public void CanConvertPL1LineWithAlphaBetween0and90Degrees()
{
var coordinateSystemConverter = new CoordinateSystemConverter();
PL1Line pl1Line = CreateGlobalPL1LineWithAlphaBetween0and90Degrees();
PL1Line expectedGlobalPL1Line = CreateGlobalPL1LineWithAlphaBetween0and90Degrees();
coordinateSystemConverter.DefineGlobalXYZBasedOnLine(pl1Line);
// Convert to global
coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(pl1Line);
CheckResultingLocalPL1Line(pl1Line);
// Convert to local
coordinateSystemConverter.ConvertLocalXZToGlobalXYZ(pl1Line);
Assert.IsTrue(expectedGlobalPL1Line.Equals(pl1Line));
}
}
}