// 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 Deltares.DamEngine.Data.Geometry;
namespace Deltares.DamEngine.Data.Geotechnics
{
///
/// All extension-methods for .
///
public static class SurfaceLine2Extensions
{
///
/// Returns all that require to be sorted on X
/// ascending.
///
/// The evaluated surfaceline.
/// Collection of characteristic points, ordered by type from the point
/// expecting the lowest X coordinate in the set through to the one expecting the
/// highest X coordinate.
public static IEnumerable GetCharacteristicPointsRequiringAscendingX(this SurfaceLine2 line)
{
return line.CharacteristicPoints.Where(p =>
!double.IsNaN(p.X) && // Note: This probably shall no longer apply to SurfaceLine2
p.CharacteristicPointType != CharacteristicPointType.None &&
p.CharacteristicPointType != CharacteristicPointType.TrafficLoadInside &&
p.CharacteristicPointType != CharacteristicPointType.TrafficLoadOutside).
OrderBy(p => p.CharacteristicPointType);
}
///
/// Checks whether the specified line has the given annotation.
///
/// The surface line to be checked.
/// The type.
///
///
public static bool HasAnnotation(this SurfaceLine2 line, CharacteristicPointType type)
{
return line.CharacteristicPoints.GetGeometryPoint(type) != null;
}
///
/// Determines whether the specified characteristic point type is defined (has
/// the given annotation and its X coordinate is not ).
///
/// The evaluated surfaceline.
/// Type of the characteristic point.
/// true if input parameter is defined
///
public static bool IsDefined(this SurfaceLine2 line, CharacteristicPointType characteristicPointType)
{
// TODO: GRASP: Information Expert -> CharacteristicPoint class should be responsible for this logic.
return line.HasAnnotation(characteristicPointType) &&
!Double.IsNaN(line.CharacteristicPoints.GetGeometryPoint(characteristicPointType).X);
}
///
/// Gets the absolute height ([m]) of the dike.
///
/// Height of dike, or null if
/// is not defined for the surface line.
public static double? GetDikeHeight(this SurfaceLine2 line)
{
var dikeTopAtRiver = line.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtRiver);
if (dikeTopAtRiver != null)
{
return dikeTopAtRiver.Z;
}
return null;
}
///
/// If shoulder is present then the toe of the shoulder ()
/// is returned, else the toe of the dike ()
/// is returned.
///
/// Toe of the dike, or null if none of the required characteristic
/// annotations can be found.
public static GeometryPoint GetDikeToeInward(this SurfaceLine2 line)
{
return line.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) ??
line.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder);
}
///
/// Gets the length of the dike.
///
/// dike length or null in case toe points are null
public static double? GetDikeLength(this SurfaceLine2 line)
{
var dikeToeAtRiver = line.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtRiver);
var dikeToeAtPolder = line.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder);
if (dikeToeAtRiver != null && dikeToeAtPolder != null)
{
return Math.Abs(dikeToeAtRiver.X - dikeToeAtPolder.X);
}
return null;
}
///
/// Checks if a surfaceline has all characteristic point types required to describe
/// a dike.
///
/// Surfaceline to be checked.
/// True if there are characteristic points defined that describe a dike;
/// False otherwise.
public static bool HasDike(this SurfaceLine2 line)
{
return IsDefined(line, CharacteristicPointType.DikeToeAtRiver) &&
IsDefined(line, CharacteristicPointType.DikeTopAtRiver) &&
IsDefined(line, CharacteristicPointType.DikeTopAtPolder) &&
IsDefined(line, CharacteristicPointType.DikeToeAtPolder);
}
}
}