Skip to content

Commit f9c85d4

Browse files
committed
GRIDEDIT-1699 Removed unnecessary and incorrect code
Updated unit test after removal of incorrect code
1 parent 49e18e2 commit f9c85d4

File tree

3 files changed

+24
-162
lines changed

3 files changed

+24
-162
lines changed

libs/MeshKernel/src/Polygon.cpp

Lines changed: 2 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "MeshKernel/Constants.hpp"
3333
#include "MeshKernel/Exceptions.hpp"
3434
#include "MeshKernel/LandBoundary.hpp"
35+
#include "MeshKernel/MeshFaceCenters.hpp"
3536
#include "MeshKernel/Operations.hpp"
3637
#include "MeshKernel/Polygon.hpp"
3738
#include "MeshKernel/Vector.hpp"
@@ -751,147 +752,8 @@ std::tuple<double, meshkernel::Point, meshkernel::TraversalDirection> meshkernel
751752
double area = 0.0;
752753

753754
const double minArea = 1e-8;
754-
const auto numberOfPointsOpenedPolygon = static_cast<UInt>(polygon.size()) - 1;
755755

756-
const double updateStepSize = 0.1;
757-
758-
Point centreOfMass(0.0, 0.0);
759-
760-
for (UInt n = 0; n < numberOfPointsOpenedPolygon; ++n)
761-
{
762-
centreOfMass += polygon[n];
763-
}
764-
765-
centreOfMass *= 1.0 / static_cast<double>(numberOfPointsOpenedPolygon);
766-
// Will be non-unity for spherical coordinates only
767-
const double xTransformation = projection == Projection::cartesian ? 1.0 : 1.0 / std::cos(centreOfMass.y * constants::conversion::degToRad);
768-
const double circumcentreTolerance = constants::geometric::circumcentreTolerance * (projection == Projection::cartesian ? 1.0 : 1.0 / (constants::geometric::earth_radius * constants::conversion::degToRad));
769-
770-
if (numberOfPointsOpenedPolygon == constants::geometric::numNodesInTriangle)
771-
{
772-
773-
Point midPoint1 = 0.5 * (polygon[0] + polygon[1]);
774-
Point midPoint2 = 0.5 * (polygon[1] + polygon[2]);
775-
Point midPoint3 = 0.5 * (polygon[2] + polygon[0]);
776-
777-
Vector edgeVector1 = static_cast<Vector>(NormalVector(polygon[0], polygon[1], midPoint1, projection));
778-
Vector edgeVector2 = static_cast<Vector>(NormalVector(polygon[1], polygon[2], midPoint2, projection));
779-
Vector edgeVector3 = static_cast<Vector>(NormalVector(polygon[2], polygon[0], midPoint3, projection));
780-
781-
edgeVector1.normalise();
782-
edgeVector2.normalise();
783-
edgeVector3.normalise();
784-
785-
Vector edgeVectorSum = edgeVector1 + edgeVector2 + edgeVector3;
786-
787-
double edgeVectorSumLength = edgeVectorSum.length();
788-
789-
for (UInt i = 1; i <= MaximumNumberOfCircumcentreIterations; ++i)
790-
{
791-
Vector delta1 = GetDelta(midPoint1, centreOfMass, projection);
792-
Vector delta2 = GetDelta(midPoint2, centreOfMass, projection);
793-
Vector delta3 = GetDelta(midPoint3, centreOfMass, projection);
794-
795-
double ds = dot(delta1, edgeVector1) + dot(delta2, edgeVector2) + dot(delta3, edgeVector3);
796-
797-
if (projection != Projection::cartesian)
798-
{
799-
ds *= constants::conversion::radToDeg * constants::geometric::inverse_earth_radius;
800-
}
801-
802-
centreOfMass.x -= updateStepSize * ds * edgeVectorSum.x() * xTransformation;
803-
centreOfMass.y -= updateStepSize * ds * edgeVectorSum.y();
804-
805-
if (ds * edgeVectorSumLength < circumcentreTolerance || i == MaximumNumberOfCircumcentreIterations)
806-
{
807-
break;
808-
}
809-
}
810-
}
811-
else if (numberOfPointsOpenedPolygon == constants::geometric::numNodesInQuadrilateral)
812-
{
813-
814-
Point midPoint1 = 0.5 * (polygon[0] + polygon[1]);
815-
Point midPoint2 = 0.5 * (polygon[1] + polygon[2]);
816-
Point midPoint3 = 0.5 * (polygon[2] + polygon[3]);
817-
Point midPoint4 = 0.5 * (polygon[3] + polygon[0]);
818-
819-
Vector edgeVector1 = static_cast<Vector>(NormalVector(polygon[0], polygon[1], midPoint1, projection));
820-
Vector edgeVector2 = static_cast<Vector>(NormalVector(polygon[1], polygon[2], midPoint2, projection));
821-
Vector edgeVector3 = static_cast<Vector>(NormalVector(polygon[2], polygon[3], midPoint3, projection));
822-
Vector edgeVector4 = static_cast<Vector>(NormalVector(polygon[3], polygon[0], midPoint4, projection));
823-
824-
edgeVector1.normalise();
825-
edgeVector2.normalise();
826-
edgeVector3.normalise();
827-
edgeVector4.normalise();
828-
829-
Vector edgeVectorSum = edgeVector1 + edgeVector2 + edgeVector3 + edgeVector4;
830-
831-
if (projection != Projection::cartesian)
832-
{
833-
edgeVectorSum.x() *= constants::conversion::radToDeg * constants::geometric::inverse_earth_radius;
834-
}
835-
836-
double edgeVectorSumLength = edgeVectorSum.length();
837-
838-
for (UInt i = 1; i <= MaximumNumberOfCircumcentreIterations; ++i)
839-
{
840-
Vector delta1 = GetDelta(midPoint1, centreOfMass, projection);
841-
Vector delta2 = GetDelta(midPoint2, centreOfMass, projection);
842-
Vector delta3 = GetDelta(midPoint3, centreOfMass, projection);
843-
Vector delta4 = GetDelta(midPoint4, centreOfMass, projection);
844-
845-
double ds = dot(delta1, edgeVector1) + dot(delta2, edgeVector2) + dot(delta3, edgeVector3) + dot(delta4, edgeVector4);
846-
847-
if (projection != Projection::cartesian)
848-
{
849-
ds *= constants::conversion::radToDeg * constants::geometric::inverse_earth_radius;
850-
}
851-
852-
centreOfMass.x -= updateStepSize * ds * edgeVectorSum.x() * xTransformation;
853-
centreOfMass.y -= updateStepSize * ds * edgeVectorSum.y();
854-
855-
if (ds * edgeVectorSumLength < circumcentreTolerance)
856-
{
857-
break;
858-
}
859-
}
860-
}
861-
else
862-
{
863-
for (UInt j = 1; j <= MaximumNumberOfCircumcentreIterations; ++j)
864-
{
865-
Vector edgeVectorSum(0.0, 0.0);
866-
double ds = 0.0;
867-
868-
for (UInt i = 0; i < numberOfPointsOpenedPolygon; ++i)
869-
{
870-
const auto nextNode = NextCircularForwardIndex(i, numberOfPointsOpenedPolygon);
871-
872-
Point midPoint = 0.5 * (polygon[i] + polygon[nextNode]);
873-
Vector edgeVector = static_cast<Vector>(NormalVector(polygon[i], polygon[nextNode], midPoint, projection));
874-
Vector delta = GetDelta(midPoint, centreOfMass, projection);
875-
876-
edgeVector.normalise();
877-
ds += dot(delta, edgeVector);
878-
edgeVectorSum += edgeVector;
879-
}
880-
881-
if (projection != Projection::cartesian)
882-
{
883-
ds *= constants::conversion::radToDeg * constants::geometric::inverse_earth_radius;
884-
}
885-
886-
centreOfMass.x -= updateStepSize * ds * edgeVectorSum.x() * xTransformation;
887-
centreOfMass.y -= updateStepSize * ds * edgeVectorSum.y();
888-
889-
if (ds * edgeVectorSum.length() < circumcentreTolerance)
890-
{
891-
break;
892-
}
893-
}
894-
}
756+
Point centreOfMass(algo::ComputeMassCentre(polygon));
895757

896758
area = ComputeArea(polygon, projection);
897759
TraversalDirection direction = area > 0.0 ? TraversalDirection::AntiClockwise : TraversalDirection::Clockwise;

libs/MeshKernel/tests/src/TriangleInterpolationTests.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,24 @@ TEST(TriangleInterpolation, InterpolateOnFacesUsingSphericalAccurateOption)
179179
// test internal results
180180
constexpr double tolerance = 1e-9;
181181

182-
EXPECT_NEAR(-27.108687793186, results[0], tolerance);
183-
EXPECT_NEAR(-26.009302073210, results[1], tolerance);
184-
EXPECT_NEAR(-26.761021461739, results[2], tolerance);
185-
EXPECT_NEAR(-26.492752218595, results[3], tolerance);
186-
EXPECT_NEAR(-26.993455423167, results[4], tolerance);
187-
EXPECT_NEAR(-26.896716929007, results[5], tolerance);
188-
EXPECT_NEAR(-27.332328906260, results[6], tolerance);
189-
EXPECT_NEAR(-28.374122977078, results[7], tolerance);
190-
EXPECT_NEAR(-22.330730000764, results[8], tolerance);
191-
EXPECT_NEAR(-30.427555910275, results[9], tolerance);
192-
EXPECT_NEAR(-22.404382839536, results[10], tolerance);
193-
EXPECT_NEAR(-13.366066103195, results[11], tolerance);
194-
EXPECT_NEAR(-19.083446809814, results[12], tolerance);
195-
EXPECT_NEAR(-33.575137706741, results[13], tolerance);
196-
EXPECT_NEAR(-35.307890160711, results[14], tolerance);
197-
EXPECT_NEAR(-32.536063087366, results[15], tolerance);
198-
EXPECT_NEAR(-28.308466343407, results[16], tolerance);
199-
EXPECT_NEAR(-26.425479106911, results[17], tolerance);
200-
EXPECT_NEAR(-26.989475394568, results[18], tolerance);
201-
EXPECT_NEAR(-29.549005090353, results[19], tolerance);
182+
EXPECT_NEAR(-27.108706771384, results[0], tolerance);
183+
EXPECT_NEAR(-26.009304907814, results[1], tolerance);
184+
EXPECT_NEAR(-26.761017862316, results[2], tolerance);
185+
EXPECT_NEAR(-26.492756376222, results[3], tolerance);
186+
EXPECT_NEAR(-26.993450824473, results[4], tolerance);
187+
EXPECT_NEAR(-26.896717604451, results[5], tolerance);
188+
EXPECT_NEAR(-27.332328048991, results[6], tolerance);
189+
EXPECT_NEAR(-28.374153123483, results[7], tolerance);
190+
EXPECT_NEAR(-22.330677494619, results[8], tolerance);
191+
EXPECT_NEAR(-30.427553277301, results[9], tolerance);
192+
EXPECT_NEAR(-22.404457686668, results[10], tolerance);
193+
EXPECT_NEAR(-13.366173846988, results[11], tolerance);
194+
EXPECT_NEAR(-19.083347703857, results[12], tolerance);
195+
EXPECT_NEAR(-33.575109615314, results[13], tolerance);
196+
EXPECT_NEAR(-35.307909396654, results[14], tolerance);
197+
EXPECT_NEAR(-32.536083626614, results[15], tolerance);
198+
EXPECT_NEAR(-28.308474234385, results[16], tolerance);
199+
EXPECT_NEAR(-26.425478326615, results[17], tolerance);
200+
EXPECT_NEAR(-26.989472301758, results[18], tolerance);
201+
EXPECT_NEAR(-29.548994620034, results[19], tolerance);
202202
}

libs/MeshKernelApi/tests/src/ApiTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,9 @@ TEST_F(CartesianApiTestFixture, Mesh2DCountObtuseTriangles_OnMesh2DWithOneObtuse
15181518
ASSERT_EQ(1, numObtuseTriangles);
15191519
const double tolerance = 1e-6;
15201520
std::vector computedCoordinatesX(coordinatesObtuseTrianglesX.data(), coordinatesObtuseTrianglesX.data() + numObtuseTriangles);
1521-
ASSERT_NEAR(computedCoordinatesX[0], 0.51976223782641451, tolerance);
1521+
ASSERT_NEAR(computedCoordinatesX[0], 0.6666666666666666, tolerance);
15221522
std::vector computedCoordinatesY(coordinatesObtuseTrianglesY.data(), coordinatesObtuseTrianglesY.data() + numObtuseTriangles);
1523-
ASSERT_NEAR(computedCoordinatesY[0], 0.7855148461473761, tolerance);
1523+
ASSERT_NEAR(computedCoordinatesY[0], 0.6666666666666666, tolerance);
15241524
}
15251525

15261526
TEST_F(CartesianApiTestFixture, Mesh2DDeleteSmallFlowEdgesAndSmallTriangles_OnMesh2DWithOneObtuseTriangle_ShouldDeleteOneEdge)

0 commit comments

Comments
 (0)