// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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 Deltares.DamEngine.Data.Geometry; using NUnit.Framework; namespace Deltares.DamEngine.Data.Tests.Geometry; [TestFixture] public class GeometryPointStringTests { [Test] public void GivenGeometryPointStringWithRedundantPoints_WhenRemovingUnnecessaryPoints_ThenCorrectGeometryPointStringReturned() { var geometryPointString = new GeometryPointString(); // The polyline contains only 3 identical points => expected 1 point geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.RemoveUnnecessaryPoints(); Assert.That(geometryPointString.Points, Has.Count.EqualTo(1)); Assert.Multiple(() => { Assert.That(geometryPointString.Points[0].X, Is.EqualTo(2)); Assert.That(geometryPointString.Points[0].Z, Is.EqualTo(3)); }); // The polyline contains 1 straight line with 3 points => expected 2 points geometryPointString.Points.Clear(); geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.Points.Add(new Point2D(3, 3)); geometryPointString.Points.Add(new Point2D(4, 3)); geometryPointString.RemoveUnnecessaryPoints(); Assert.That(geometryPointString.Points, Has.Count.EqualTo(2)); Assert.Multiple(() => { Assert.That(geometryPointString.Points[0].X, Is.EqualTo(2)); Assert.That(geometryPointString.Points[0].Z, Is.EqualTo(3)); Assert.That(geometryPointString.Points[1].X, Is.EqualTo(4)); Assert.That(geometryPointString.Points[1].Z, Is.EqualTo(3)); }); // The polyline contains 1 straight line with 5 points => expected 2 points geometryPointString.Points.Clear(); geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.Points.Add(new Point2D(3, 3)); geometryPointString.Points.Add(new Point2D(4, 3)); geometryPointString.Points.Add(new Point2D(5, 3)); geometryPointString.Points.Add(new Point2D(6, 3)); geometryPointString.RemoveUnnecessaryPoints(); Assert.That(geometryPointString.Points, Has.Count.EqualTo(2)); Assert.Multiple(() => { Assert.That(geometryPointString.Points[0].X, Is.EqualTo(2)); Assert.That(geometryPointString.Points[0].Z, Is.EqualTo(3)); Assert.That(geometryPointString.Points[1].X, Is.EqualTo(6)); Assert.That(geometryPointString.Points[1].Z, Is.EqualTo(3)); }); // The polyline contains 2 straight lines with 5 points => expected 3 points geometryPointString.Points.Clear(); geometryPointString.Points.Add(new Point2D(2, 3)); geometryPointString.Points.Add(new Point2D(3, 4)); geometryPointString.Points.Add(new Point2D(4, 5)); geometryPointString.Points.Add(new Point2D(5, 4)); geometryPointString.Points.Add(new Point2D(6, 3)); geometryPointString.RemoveUnnecessaryPoints(); Assert.That(geometryPointString.Points, Has.Count.EqualTo(3)); Assert.Multiple(() => { Assert.That(geometryPointString.Points[0].X, Is.EqualTo(2)); Assert.That(geometryPointString.Points[0].Z, Is.EqualTo(3)); Assert.That(geometryPointString.Points[1].X, Is.EqualTo(4)); Assert.That(geometryPointString.Points[1].Z, Is.EqualTo(5)); Assert.That(geometryPointString.Points[2].X, Is.EqualTo(6)); Assert.That(geometryPointString.Points[2].Z, Is.EqualTo(3)); }); } }