diff --git a/libs/MeshKernel/src/Polygon.cpp b/libs/MeshKernel/src/Polygon.cpp index 43f05856c..71af2d8f2 100644 --- a/libs/MeshKernel/src/Polygon.cpp +++ b/libs/MeshKernel/src/Polygon.cpp @@ -37,12 +37,6 @@ void meshkernel::Polygon::Initialise() throw ConstraintError("Polygon nodes contains invalid nodes"); } - if (m_projection == Projection::spherical) - { - // TODO SHould this be called for spherical accurate too? - TranslateSphericalCoordinates(m_nodes); - } - m_boundingBox.Reset(m_nodes); } @@ -84,7 +78,7 @@ bool meshkernel::Polygon::ContainsCartesianOrSpherical(const Point& point) const for (size_t n = 0; n < m_nodes.size() - 1; n++) { - const auto crossProductValue = crossProduct(m_nodes[n], m_nodes[n + 1], m_nodes[n], point, m_projection); + const auto crossProductValue = crossProduct(m_nodes[n], m_nodes[n + 1], m_nodes[n], point, Projection::cartesian); if (IsEqual(crossProductValue, 0.0)) { @@ -180,6 +174,10 @@ bool meshkernel::Polygon::ContainsSphericalAccurate(const Point& point) const bool meshkernel::Polygon::Contains(const Point& pnt) const { + if (pnt.x > -1.8) + { + std::cout << "debug" << std::endl; + } if (!pnt.IsValid()) { diff --git a/libs/MeshKernel/tests/src/Mesh2DTest.cpp b/libs/MeshKernel/tests/src/Mesh2DTest.cpp index b54483cd8..6a52d89ff 100644 --- a/libs/MeshKernel/tests/src/Mesh2DTest.cpp +++ b/libs/MeshKernel/tests/src/Mesh2DTest.cpp @@ -992,7 +992,7 @@ TEST(Mesh2D, DeleteMesh_WhenFacesAreIntersectedSpherical_ShouldNotDeleteFaces) // Prepare const auto mesh = MakeRectangularMeshForTesting(4, 4, 3, 3, meshkernel::Projection::spherical, meshkernel::Point{0, 0}); - // a polygon including all nodes of a face, but also intersecting + // a polygon including all nodes of a face, but also intersecting one std::vector polygonNodes{ {1.87622950819672, -0.299180327868853}, {1.86885245901639, 0.187704918032786}, @@ -1012,3 +1012,30 @@ TEST(Mesh2D, DeleteMesh_WhenFacesAreIntersectedSpherical_ShouldNotDeleteFaces) // Assert EXPECT_EQ(mesh->GetNumFaces(), 9); } + +TEST(Mesh2D, DeleteMesh_WithLargeSphericalPolygon_ShouldDeleteInnerMeshFaces) +{ + // Prepare + const auto mesh = MakeRectangularMeshForTesting(4, + 4, + 2.0, + 2.0, + meshkernel::Projection::spherical, + meshkernel::Point{-3.0, 48.5}); + + // a large polygon + std::vector polygonNodes{ + {-2.29490103397341, 50.0126381093058}, + {179.33620776839, 50.3853885542098}, + {180.05965832319, -3.87340305583453}, + {-2.24988148655834, -3.14995250103394}, + {-2.29490103397341, 50.0126381093058}}; + + auto polygon = meshkernel::Polygons(polygonNodes, meshkernel::Projection::spherical); + + // Execute + mesh->DeleteMesh(polygon, 0, false); + + // Assert + EXPECT_EQ(mesh->GetNumFaces(), 7); +}