// Copyright (C) Stichting Deltares 2017. 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 System.Xml.Serialization; 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; [XmlIgnore] public PLLineType PLLineType { get { return plLineType; } set { plLineType = value; PLLineTypeSpecified = true; } } [XmlIgnore] 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); } } } }