// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System.Collections.Generic;
using System.Linq;
using Deltares.Dam.Data;
using Deltares.Geometry;
using NUnit.Framework;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class PLLineTest
{
[SetUp]
public void TestFixtureSetup() {}
[SetUp]
public void TestSetup() {}
[Test]
public void TestCreate()
{
var plLine = new PLLine();
Assert.That(plLine, Is.Not.Null);
}
[Test]
public void TestPointEqualsWithTolerance()
{
var plLinePoint1 = new PLLinePoint(1.1, 2.1);
var plLinePoint2 = new PLLinePoint(1.1, 2.100001);
Assert.That(plLinePoint2.LocationEquals(plLinePoint1, 0.0001), Is.True);
Assert.That(plLinePoint2.LocationEquals(plLinePoint1, 0.0000001), Is.False);
}
[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
});
IEnumerable result = surfaceLine.GetPointSegmentBetween(0.4, 13);
Assert.That(result.Count(), Is.EqualTo(4));
result = surfaceLine.GetPointSegmentBetween(0.6, 11);
Assert.That(result.Count(), Is.EqualTo(4));
result = surfaceLine.GetPointSegmentBetween(10, 10);
Assert.That(result.Count(), Is.EqualTo(0));
result = surfaceLine.GetPointSegmentBetween(15, 16);
Assert.That(result.Count(), Is.EqualTo(0));
}
[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.That(plLine.PositionXzOfPointRelatedToPLLine(pointAbove) == PLLinePointPositionXzType.AbovePLLine, Is.True);
var pointBelow = new GeometryPoint(1, 0, -1);
Assert.That(plLine.PositionXzOfPointRelatedToPLLine(pointBelow) == PLLinePointPositionXzType.BelowPLLine, Is.True);
var pointOn = new GeometryPoint(1, 0, 0);
Assert.That(plLine.PositionXzOfPointRelatedToPLLine(pointOn) == PLLinePointPositionXzType.OnPLLine, Is.True);
var pointAboveBeyond = new GeometryPoint(100, 0, 1);
Assert.That(plLine.PositionXzOfPointRelatedToPLLine(pointAboveBeyond) == PLLinePointPositionXzType.BeyondPLLine, Is.True);
var pointBelowBeyond = new GeometryPoint(100, 0, -1);
Assert.That(plLine.PositionXzOfPointRelatedToPLLine(pointBelowBeyond) == PLLinePointPositionXzType.BeyondPLLine, Is.True);
var pointOnBeyond = new GeometryPoint(100, 0, 0);
Assert.That(plLine.PositionXzOfPointRelatedToPLLine(pointOnBeyond) == PLLinePointPositionXzType.BeyondPLLine, Is.True);
}
}
}