Skip to content

Commit

Permalink
Remove TranslateSphericalCoordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacarniato committed Oct 23, 2023
1 parent 4b02a5d commit 91f969b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
12 changes: 5 additions & 7 deletions libs/MeshKernel/src/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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())
{
Expand Down
29 changes: 28 additions & 1 deletion libs/MeshKernel/tests/src/Mesh2DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<meshkernel::Point> polygonNodes{
{1.87622950819672, -0.299180327868853},
{1.86885245901639, 0.187704918032786},
Expand All @@ -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<meshkernel::Point> 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);
}

0 comments on commit 91f969b

Please sign in to comment.