// Copyright (C) Stichting Deltares 2024. 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.Collections.Generic; namespace Deltares.DamEngine.Data.Geometry; /// /// Represents the possible directions of the curve /// public enum CurveDirection { /// /// Forward as direction /// Forward = 0, /// /// Reverse as direction /// Reverse = 1 } /// /// Contains the collection of all the curves data. /// public class GeometryCurve : GeometryObject { private Point2D endPoint; private Point2D headPoint; /// /// Initializes a new instance of the class. /// public GeometryCurve() {} /// /// Initializes a new instance of the class. /// /// The head point. /// The end point. public GeometryCurve(Point2D headPoint, Point2D endPoint) { this.headPoint = headPoint; this.endPoint = endPoint; } /// /// The unique name of the object. /// public override string Name { get { if (!string.IsNullOrEmpty(base.Name)) { return base.Name; } var text = ""; if (HeadPoint != null) { text += HeadPoint.ToString()?.Trim(); } text += "-"; if (EndPoint != null) { text += EndPoint.ToString()?.Trim(); } base.Name = text; return base.Name; } set => base.Name = value; } /// /// Gets or sets the head point of the curve. /// public virtual Point2D HeadPoint { get => headPoint; set => headPoint = value; } /// /// Gets or sets the end point of the curve. /// public virtual Point2D EndPoint { get => endPoint; set => endPoint = value; } /// /// Gets or sets the surface at the Left. /// public virtual GeometrySurface SurfaceAtLeft { get; set; } /// /// Gets or sets the surface at the Right. /// public virtual GeometrySurface SurfaceAtRight { get; set; } /// /// Locations the equals. /// /// a curve. /// public bool LocationEquals(GeometryCurve aCurve) { return (headPoint.LocationEquals(aCurve.HeadPoint) && endPoint.LocationEquals(aCurve.EndPoint)) || (headPoint.LocationEquals(aCurve.EndPoint) && endPoint.LocationEquals(aCurve.HeadPoint)); } /// /// Swaps and . /// public void Reverse() { (HeadPoint, EndPoint) = (EndPoint, HeadPoint); } /// /// Returns the head point in given direction /// /// Direction is either Forward or Reverse or Unknown /// Returns the head point in the given direction public Point2D GetHeadPoint(CurveDirection aDirection) { return aDirection == CurveDirection.Forward ? headPoint : endPoint; } /// /// Gets the end point in the given direction /// /// Direction is either Forward or Reverse or Unknown /// Returns the end point in the given direction public Point2D GetEndPoint(CurveDirection aDirection) { return aDirection == CurveDirection.Forward ? endPoint : headPoint; } /// /// Determines whether the curve contains the specified point within the given tolerance. /// /// The point. /// The tolerance. /// public bool ContainsPoint(Point2D point, double tolerance = GeometryConstants.Accuracy * 0.5) { return HeadPoint != null && EndPoint != null && Routines2D.DoesPointExistInLine(HeadPoint, EndPoint, point, tolerance); } /// /// Assigns the surfaces from the curve. /// /// public void AssignSurfacesFromCurve(GeometryCurve aCurve) { if (aCurve.SurfaceAtLeft != SurfaceAtLeft) { SurfaceAtLeft = aCurve.SurfaceAtLeft; } if (aCurve.SurfaceAtRight != SurfaceAtRight) { SurfaceAtRight = aCurve.SurfaceAtRight; } } /// /// Clones the curve. /// /// Returns a clone public GeometryCurve Clone(List points) { Point2D clonedHeadPoint = points.Find(p => p.LocationEquals(HeadPoint)); Point2D clonedEndPoint = points.Find(p => p.LocationEquals(EndPoint)); var curve = new GeometryCurve(clonedHeadPoint, clonedEndPoint) { Name = Name }; return curve; } /// /// Gets the geometry bounds. /// /// public override GeometryBounds GetGeometryBounds() { if (HeadPoint != null && EndPoint != null) { var head = new GeometryBounds(HeadPoint.X, HeadPoint.X, HeadPoint.Z, HeadPoint.Z); var end = new GeometryBounds(EndPoint.X, EndPoint.X, EndPoint.Z, EndPoint.Z); return head + end; } return null; } /// /// Returns a string that represents the current object. /// /// /// A string that represents the current object. /// /// 2 public override string ToString() { return string.Empty; } }