// Copyright (C) Stichting Deltares 2025. 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.Collections.Generic;
using Deltares.DamEngine.Data.Geometry;
using NUnit.Framework;
namespace Deltares.DamEngine.Data.Tests.Geometry;
[TestFixture]
public class Routines2DTests
{
[Test]
public void GivenTriangle_WhenDeterminingTheCentroid_ThenReturnMediansIntersection()
{
var polygon = new List
{
new Point2D(-5, -1),
new Point2D(3, -1),
new Point2D(-1, 5)
};
Point2D centroid = Routines2D.ComputeCentroid(polygon);
Assert.Multiple(() =>
{
Assert.That(centroid.X, Is.EqualTo(-1));
Assert.That(centroid.Z, Is.EqualTo(1));
});
}
[Test]
public void GivenRectangle_WhenDeterminingTheCentroid_ThenReturnCenter()
{
var polygon = new List
{
new Point2D(-5, -1),
new Point2D(3, -1),
new Point2D(3, 6),
new Point2D(-5, 6)
};
Point2D centroid = Routines2D.ComputeCentroid(polygon);
Assert.Multiple(() =>
{
Assert.That(centroid.X, Is.EqualTo(-1));
Assert.That(centroid.Z, Is.EqualTo(2.5));
});
}
}