//-----------------------------------------------------------------------
//
// Copyright (c) 2009 Deltares. All rights reserved.
//
// B.S.T.I.M. The
// tom.the@deltares.nl
// 18-05-2009
// Contains tests for class Deltares.Dam.Data.PLLine
//-----------------------------------------------------------------------
using System.Linq;
using Deltares.Geometry;
namespace Deltares.Dam.Tests
{
using NUnit.Framework;
using Deltares.Dam.Data;
[TestFixture]
public class PLLineTest
{
[TestFixtureSetUp]
public void TestFixtureSetup()
{
}
[SetUp]
public void TestSetup()
{
}
[Test]
public void TestCreate()
{
PLLine plLine = new PLLine();
Assert.IsNotNull(plLine);
}
[Test]
public void TestPointEqualsWithTolerance()
{
var plLinePoint1 = new PLLinePoint(1.1, 2.1);
var plLinePoint2 = new PLLinePoint(1.1, 2.100001);
Assert.IsTrue(plLinePoint2.LocationEquals(plLinePoint1, 0.0001));
Assert.IsFalse(plLinePoint2.LocationEquals(plLinePoint1, 0.0000001));
}
[Test]
public void GetPointSegmentBetweenReturnsCorrectPoints()
{
var surfaceLine = new PLLine();
surfaceLine.Points.Add(new PLLinePoint() { X = 0.4, Z = 0.9 });
surfaceLine.Points.Add(new PLLinePoint() { X = 1, Z = 1 });
surfaceLine.Points.Add(new PLLinePoint() { X = 2, Z = 3 });
surfaceLine.Points.Add(new PLLinePoint() { X = 4, Z = 5 });
surfaceLine.Points.Add(new PLLinePoint() { X = 10, Z = 12 });
surfaceLine.Points.Add(new PLLinePoint() { X = 13, Z = 13 });
var result = surfaceLine.GetPointSegmentBetween(0.4, 13);
Assert.AreEqual(4, result.Count());
result = surfaceLine.GetPointSegmentBetween(0.6, 11);
Assert.AreEqual(4, result.Count());
result = surfaceLine.GetPointSegmentBetween(10, 10);
Assert.AreEqual(0, result.Count());
result = surfaceLine.GetPointSegmentBetween(15, 16);
Assert.AreEqual(0, result.Count());
}
[Test]
public void TestPositionXzOfPointRelatedToPLLine()
{
var plLine = new PLLine();
plLine.Points.Add(new PLLinePoint() { X = 0.0, Z = 0.0 });
plLine.Points.Add(new PLLinePoint() { X = 10, Z = 0.0 });
var pointAbove = new GeometryPoint(1, 0, 1);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointAbove) == PLLinePointPositionXzType.AbovePLLine);
var pointBelow = new GeometryPoint(1, 0, -1);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointBelow) == PLLinePointPositionXzType.BelowPLLine);
var pointOn = new GeometryPoint(1, 0, 0);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointOn) == PLLinePointPositionXzType.OnPLLine);
var pointAboveBeyond = new GeometryPoint(100, 0, 1);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointAboveBeyond) == PLLinePointPositionXzType.BeyondPLLine);
var pointBelowBeyond = new GeometryPoint(100, 0, -1);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointBelowBeyond) == PLLinePointPositionXzType.BeyondPLLine);
var pointOnBeyond = new GeometryPoint(100, 0, 0);
Assert.IsTrue(plLine.PositionXzOfPointRelatedToPLLine(pointOnBeyond) == PLLinePointPositionXzType.BeyondPLLine);
}
}
}