// Copyright (C) Stichting Deltares 2023. 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.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 }); IEnumerable 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); } } }