// Copyright (C) Stichting Deltares 2018. 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 System.Linq; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Standard; namespace Deltares.DamEngine.Data.General.PlLines { public class PlLinePoint : GeometryPoint { public PlLinePoint() : this (0, 0) { } public PlLinePoint(double aX, double aZ) : base(aX, aZ) { } } public class PlLine : PolyLine, ICloneable { private PlLineType plLineType; public PlLineType PLLineType { get { return plLineType; } set { plLineType = value; PLLineTypeSpecified = true; } } public bool PLLineTypeSpecified { get; private set; } public bool IsPhreatic { get; set; } public int BoundaryLayer { get; set; } public PlLine Clone() { PlLine plLine = new PlLine() { IsPhreatic = this.IsPhreatic, BoundaryLayer = this.BoundaryLayer }; foreach (PlLinePoint point in this.Points) { PlLinePoint newPoint = new PlLinePoint() { X = point.X, Y = point.Y, Z = point.Z }; plLine.Points.Add(newPoint); } return plLine; } /// /// Gets the points in the segment between starting x and ending x /// /// /// /// /// /// public IEnumerable GetPointSegmentBetween(double startX, double endX) { if (endX < startX) throw new ArgumentException("End value is smaller then the start value"); return from point in this.PointsOrderdByX where point != null && (point.X > startX && point.X < endX) orderby point.X ascending select point; } /// /// Determines whether the given point is above, beneath or on the surfaceline. /// /// /// public PlLinePointPositionXzType PositionXzOfPointRelatedToPLLine(GeometryPoint point) { // if point is out of scope of the surface line, return beyond if ((point.X < points[0].X) || (point.X > points[points.Count - 1].X)) return PlLinePointPositionXzType.BeyondPLLine; double z = ZFromX(point.X); if (Math.Abs(point.Z - z) < GeometryPoint.Precision) { return PlLinePointPositionXzType.OnPLLine; } else { if (point.Z > z) { return PlLinePointPositionXzType.AbovePLLine; } else { return PlLinePointPositionXzType.BelowPLLine; } } } private IEnumerable PointsOrderdByX { get { return this.Points.OrderBy(p => p.X); } } } }