// Copyright (C) Stichting Deltares 2024. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI 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 Deltares.Standard.Extensions;
namespace Deltares.Dam.Data;
public struct Geometry2DLayer
{
public Geometry2DBoundaryLine boundaryLine;
public String soilName;
}
public class Geometry2DDataException : Exception
{
public Geometry2DDataException(string message) : base(message) {}
}
public class Geometry2DData
{
private readonly List layers = new List();
public int LayerCount
{
get
{
return layers.Count;
}
}
public double Tolerance { get; set; } = 0.0000000001;
public void AddLayer(Geometry2DLayer layer)
{
layers.Add(layer);
}
public Geometry2DLayer GetLayer(int index)
{
return layers[index];
}
public void Validate()
{
if (layers.Count > 1)
{
double limitLeft = layers[0].boundaryLine.Points[0].X;
double limitRight = layers[0].boundaryLine.Points[layers[0].boundaryLine.Points.Count - 1].X;
foreach (Geometry2DLayer layer in layers)
{
if (!layer.boundaryLine.Points[0].X.AlmostEquals(limitLeft, Tolerance) ||
!layer.boundaryLine.Points[layer.boundaryLine.Points.Count - 1].X.AlmostEquals(limitRight, Tolerance))
{
throw new Geometry2DDataException("Boundary lines are not aligned");
}
}
}
}
}