Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1522: Bug Fix, missing circumcenters calculations #382

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions libs/MeshKernel/src/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ void Mesh2D::FindFacesGivenFaceNodesMapping(const std::vector<std::vector<UInt>>
std::vector<UInt> local_edges;
std::vector<Point> local_nodes;
std::vector<UInt> local_node_indices;
std::vector<UInt> numEdgeFacesCache;
numEdgeFacesCache.reserve(m_maximumNumberOfEdgesPerFace);
std::vector<Point> polygonNodesCache;
for (UInt f = 0; f < m_facesNodes.size(); ++f)
{
local_edges.clear();
Expand Down Expand Up @@ -596,23 +599,18 @@ void Mesh2D::FindFacesGivenFaceNodesMapping(const std::vector<std::vector<UInt>>
}

m_facesEdges.emplace_back(local_edges);
m_numFacesNodes.emplace_back(static_cast<UInt>(local_edges.size()));
for (const auto& e : local_edges)
{
if (m_edgesNumFaces[e] > 2)
if (m_edgesNumFaces[e] > 2u)
{
throw AlgorithmError("FindFacesGivenMappings: m_edgesNumFaces > 2.");
}
m_edgesFaces[e][m_edgesNumFaces[e]] = f;
m_edgesNumFaces[e] += 1;
}

local_nodes.emplace_back(local_nodes.front());

auto [face_area, center_of_mass, direction] = Polygon::FaceAreaAndCenterOfMass(local_nodes, m_projection);

m_faceArea.emplace_back(face_area);
m_facesMassCenters.emplace_back(center_of_mass);
}
ComputeCircumcentersMassCentersAndFaceAreas(true);
}

void Mesh2D::ComputeCircumcentersMassCentersAndFaceAreas(bool computeMassCenters)
Expand Down
10 changes: 3 additions & 7 deletions libs/MeshKernel/src/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,13 +1153,9 @@ namespace meshkernel

auto const det = x43 * y21 - y43 * x21;

double maxValue = std::max(std::max(std::abs(x21), std::abs(y21)),
std::max(std::abs(x43), std::abs(y43)));
const double eps = std::max(0.00001 * maxValue, std::numeric_limits<double>::denorm_min());

if (std::abs(det) < eps)
if (IsEqual(det, 0.0))
Copy link
Contributor

@BillSenior BillSenior Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way that IsEqual is implemented in the master, this will (IsEqual(det, 0.0)) always return false (unless det == 0.0) So I think the previous version was the better check in this case

{
return {isCrossing, intersectionPoint, crossProduct, ratioFirstSegment, ratioSecondSegment};
return {false, intersectionPoint, crossProduct, ratioFirstSegment, ratioSecondSegment};
}

ratioSecondSegment = (y31 * x21 - x31 * y21) / det;
Expand All @@ -1173,7 +1169,7 @@ namespace meshkernel
crossProduct = -det;
if (adimensionalCrossProduct)
{
crossProduct = -det / (std::sqrt(x21 * x21 + y21 * y21) * std::sqrt(x43 * x43 + y43 * y43) + 1e-8);
crossProduct = -det / (std::sqrt(x21 * x21 + y21 * y21) * std::sqrt(x43 * x43 + y43 * y43));
}
}

Expand Down
8 changes: 8 additions & 0 deletions libs/MeshKernelApi/tests/src/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4248,3 +4248,11 @@ TEST(Mesh2D, UndoConnectMeshes)
ASSERT_EQ(meshkernel::ExitCode::Success, errorCode);
ASSERT_EQ(undoMkId, mk_id);
}

TEST(Mesh2D, SetMeshWithFaceInformation)
{
// Prepare
int meshKernelId;
const int isGeographic = 0;
meshkernelapi::mkernel_allocate_state(isGeographic, meshKernelId);
}
Loading