// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU 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 Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Ringtoets.Common.IO.Properties;
namespace Ringtoets.Common.IO.SurfaceLines
{
///
/// Definition of the surface line, which is the top level geometry of a dike.
///
public class SurfaceLine
{
///
/// Initializes a new instance of the class.
///
public SurfaceLine()
{
Name = string.Empty;
Points = new Point3D[0];
}
///
/// Gets or sets the name of the surface line.
///
public string Name { get; set; }
///
/// Gets the 3D points describing the geometry of the surface line.
///
public Point3D[] Points { get; private set; }
///
/// Sets the geometry of the surface line.
///
/// The collection of points defining the surface line geometry.
/// Thrown when is null.
/// Thrown when either:
///
/// - any element of is null;
/// - the given points are too close to each other;
/// - the given points form a reclining line, one in which the local L-coordinates of the points
/// are not in ascending order.
///
///
public void SetGeometry(IEnumerable points)
{
if (points == null)
{
throw new ArgumentNullException(nameof(points), Resources.SurfaceLine_SetGeometry_Collection_of_points_for_geometry_is_null);
}
if (points.Any(p => p == null))
{
throw new ArgumentException(Resources.SurfaceLine_SetGeometry_A_point_in_the_collection_was_null);
}
if (points.IsZeroLength())
{
throw new ArgumentException(Resources.SurfaceLine_SetGeometry_SurfaceLine_has_zero_length);
}
if (new RoundedPoint2DCollection(2, points.ProjectToLZ()).IsReclining())
{
throw new ArgumentException(Resources.SurfaceLine_SetGeometry_SurfaceLine_has_reclining_geometry);
}
Points = points.Select(p => new Point3D(p)).ToArray();
}
}
}