// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of the Macro Stability kernel.
//
// The Macro Stability kernel 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;
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);
}
}
}