Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/PlLinesCreator/SensorPlLineCreatorBaseTest.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/PlLinesCreator/SensorPlLineCreatorBaseTest.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/PlLinesCreator/SensorPlLineCreatorBaseTest.cs (revision 3339) @@ -0,0 +1,142 @@ +// Copyright (C) Stichting Deltares 2019. 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 System; +using System.Collections.Generic; +using Deltares.DamEngine.Calculators.PlLinesCreator; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.General.PlLines; +using Deltares.DamEngine.Data.General.Sensors; +using Deltares.DamEngine.Data.Geometry; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.PlLinesCreator +{ + [TestFixture] + public class SensorPlLineCreatorBaseTest + { + [Test] + public void Constructor_WithArguments_ExpectedValues() + { + // Setup + var sensorLocation = new SensorLocation(); + var sensorDictionary = new Dictionary(); + + // Call + var creator = new TestSensorPlLineCreatorBase(sensorLocation, PlLineType.Pl1, sensorDictionary); + + // Assert + Assert.That(creator, Is.InstanceOf()); + } + + [Test] + public void GetSensorXValue_WithSensorXCoordinateGreaterThanZero_DoesNotOffsetCoordinate() + { + // Setup + var random = new Random(21); + var sensorLocation = new SensorLocation + { + Location = new Location + { + SurfaceLine = CreateSurfaceLine(new[] + { + new GeometryPoint(random.NextDouble(), random.NextDouble()), + new GeometryPoint(random.NextDouble(), random.NextDouble()) + }) + } + }; + var creator = new TestSensorPlLineCreatorBase(sensorLocation, PlLineType.Pl1, new Dictionary()); + + double relativeLocation = random.NextDouble(); + var sensor = new Sensor + { + RelativeLocation = relativeLocation + }; + + // Call + double xCoordinate = creator.PublicGetSensorXValue(sensor); + + // Assert + Assert.That(xCoordinate, Is.EqualTo(relativeLocation)); + } + + [Test] + public void GetSensorXValue_WithSensorXCoordinateLessThanZero_OffsetXCoordinateWithSurfaceLineWidth() + { + // Setup + var random = new Random(21); + SurfaceLine2 surfaceLine = CreateSurfaceLine(new[] + { + new GeometryPoint(random.NextDouble(), random.NextDouble()), + new GeometryPoint(random.NextDouble(), random.NextDouble()) + }); + var sensorLocation = new SensorLocation + { + Location = new Location + { + SurfaceLine = surfaceLine + } + }; + var creator = new TestSensorPlLineCreatorBase(sensorLocation, PlLineType.Pl1, new Dictionary()); + + double relativeLocation = -random.NextDouble(); + var sensor = new Sensor + { + RelativeLocation = relativeLocation + }; + + // Call + double xCoordinate = creator.PublicGetSensorXValue(sensor); + + // Assert + GeometryPointString surfaceLineGeometry = surfaceLine.Geometry; + double expectedXCoordinate = relativeLocation + (surfaceLineGeometry.GetMaxX() - surfaceLineGeometry.GetMinX()); + Assert.That(xCoordinate, Is.EqualTo(expectedXCoordinate)); + } + + + private static SurfaceLine2 CreateSurfaceLine(IEnumerable coordinates) + { + var surfaceLine = new SurfaceLine2(); + surfaceLine.Geometry.Points.AddRange(coordinates); + surfaceLine.Geometry.SyncCalcPoints(); + + return surfaceLine; + } + + private class TestSensorPlLineCreatorBase : SensorPlLineCreatorBase + { + public TestSensorPlLineCreatorBase(SensorLocation sensorLocation, PlLineType type, IDictionary sensorValues) : base(sensorLocation, type, sensorValues) { } + + public double PublicGetSensorXValue(Sensor sensor) + { + return GetSensorXValue(sensor); + } + + public override PlLine CreatePlLine() + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLineCreatorBase.cs =================================================================== diff -u -r1965 -r3339 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLineCreatorBase.cs (.../SensorPlLineCreatorBase.cs) (revision 1965) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLineCreatorBase.cs (.../SensorPlLineCreatorBase.cs) (revision 3339) @@ -187,7 +187,9 @@ /// protected double GetSensorXValue(Sensor sensor) { - return sensor.RelativeLocation; + GeometryPointString surfaceLineGeometry = SensorLocation.SurfaceLine.Geometry; + double shift = surfaceLineGeometry.GetMaxX() - surfaceLineGeometry.GetMinX(); + return GetSensorXLocation(sensor, shift); } /// @@ -232,5 +234,22 @@ /// /// public abstract PlLine CreatePlLine(); + + /// + /// Gets the X coordinate of the sensor location. + /// + /// The to retrieve the X coordinate for. + /// The offset for the X Coordinate + /// The X location of the sensor. + private static double GetSensorXLocation(Sensor sensor, double offset) + { + double sensorXCoordinate = sensor.RelativeLocation; + if (sensorXCoordinate < 0) + { + return sensorXCoordinate + offset; + } + + return sensorXCoordinate; + } } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj =================================================================== diff -u -r3078 -r3339 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 3078) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 3339) @@ -87,6 +87,7 @@ +