// Copyright (C) Stichting Deltares 2021. 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.
namespace Deltares.DamEngine.Data.Geometry
{
///
/// Represents the possible directions of the curve
///
public enum CurveDirection
{
///
/// Unknown as direction
///
Unknown = -1,
///
/// 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;
}
///
/// Gets or sets the head point of the curve.
///
public virtual Point2D HeadPoint
{
get
{
return headPoint;
}
set
{
headPoint = value;
}
}
///
/// Gets or sets the end point of the curve.
///
public virtual Point2D EndPoint
{
get
{
return endPoint;
}
set
{
endPoint = value;
}
}
///
/// The unique name of the object.
///
public override string Name
{
get
{
if (!string.IsNullOrEmpty(base.Name))
{
return base.Name;
}
string text = "";
if (HeadPoint != null)
{
text += HeadPoint.ToString().Trim();
}
text += "-";
if (EndPoint != null)
{
text += EndPoint.ToString().Trim();
}
return text;
}
set
{
base.Name = value;
}
}
///
/// 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()
{
var point = HeadPoint;
HeadPoint = EndPoint;
EndPoint = point;
}
///
/// 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)
{
if (aDirection == CurveDirection.Forward)
{
return headPoint;
}
return 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)
{
if (aDirection == CurveDirection.Forward)
{
return endPoint;
}
return headPoint;
}
///
/// 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;
}
///
/// 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);
}
///
/// Returns a string that represents the current object.
///
///
/// A string that represents the current object.
///
/// 2
public override string ToString()
{
return string.Empty;
}
///
/// 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; }
}
}