using System;
using Deltares.Geometry;
using Deltares.Geotechnics.Exception;
using Deltares.Mathematics;
namespace Deltares.DeltaModel
{
///
/// This class represents a , for which it is not possible to move it
/// beyond its previous and next points' X coordinates.
///
public class SurfaceLineGeometryPoint : GeometryPoint
{
private GeometryPoint next;
private GeometryPoint previous;
public SurfaceLineGeometryPoint(double x, double y, double z) : base(x, y, z) {}
///
/// Parameterless constructor is used in deserialization.
///
private SurfaceLineGeometryPoint()
: base(Double.NaN, Double.NaN, Double.NaN) {}
private SurfaceLineGeometryPoint(SurfaceLineGeometryPoint point)
: base(point) {}
///
/// Sets the next point for this point.
///
/// Thrown when the point passed has an which is less than of this point.
public GeometryPoint Next
{
private get
{
return next;
}
set
{
if (null == value || Double.IsNaN(X) || value.X.IsGreaterThanOrEqualTo(X))
{
next = value;
}
else
{
throw new PointLocationIncorrectException();
}
}
}
///
/// Sets the next point for this point.
///
/// Thrown when the point passed has an which is greater than of this point.
public GeometryPoint Previous
{
private get
{
return previous;
}
set
{
if (null == value || Double.IsNaN(X) || value.X.IsLessThanOrEqualTo(X))
{
previous = value;
}
else
{
throw new PointLocationIncorrectException();
}
}
}
public override double X
{
get
{
return base.X;
}
set
{
base.X = CutOffX(value);
}
}
public override object Clone()
{
return new SurfaceLineGeometryPoint(this)
{
next = next,
previous = previous
};
}
private double CutOffX(double value)
{
var newX = value;
if (next != null && !Double.IsNaN(next.X))
{
newX = Math.Min(value, next.X);
}
if (previous != null && !Double.IsNaN(previous.X))
{
newX = Math.Max(newX, previous.X);
}
return newX;
}
}
}