diff --git a/libs/MeshKernel/src/Mesh2D.cpp b/libs/MeshKernel/src/Mesh2D.cpp index f96e8d520..ab2970b4f 100644 --- a/libs/MeshKernel/src/Mesh2D.cpp +++ b/libs/MeshKernel/src/Mesh2D.cpp @@ -186,7 +186,7 @@ void Mesh2D::DoAdministrationGivenFaceNodesMapping(const std::vector> std::vector local_edges; std::vector local_nodes; std::vector local_node_indices; + std::vector numEdgeFacesCache; + numEdgeFacesCache.reserve(m_maximumNumberOfEdgesPerFace); + std::vector polygonNodesCache; for (UInt f = 0; f < m_facesNodes.size(); ++f) { local_edges.clear(); @@ -596,22 +599,16 @@ void Mesh2D::FindFacesGivenFaceNodesMapping(const std::vector> } m_facesEdges.emplace_back(local_edges); + m_numFacesNodes.emplace_back(static_cast(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); } } diff --git a/libs/MeshKernel/src/Operations.cpp b/libs/MeshKernel/src/Operations.cpp index 6659c0f4b..d03b70be9 100644 --- a/libs/MeshKernel/src/Operations.cpp +++ b/libs/MeshKernel/src/Operations.cpp @@ -1159,7 +1159,7 @@ namespace meshkernel if (std::abs(det) < eps) { - return {isCrossing, intersectionPoint, crossProduct, ratioFirstSegment, ratioSecondSegment}; + return {false, intersectionPoint, crossProduct, ratioFirstSegment, ratioSecondSegment}; } ratioSecondSegment = (y31 * x21 - x31 * y21) / det; @@ -1173,7 +1173,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)); } } diff --git a/libs/MeshKernelApi/tests/src/ApiTest.cpp b/libs/MeshKernelApi/tests/src/ApiTest.cpp index c816b9fe1..b9fb73c99 100644 --- a/libs/MeshKernelApi/tests/src/ApiTest.cpp +++ b/libs/MeshKernelApi/tests/src/ApiTest.cpp @@ -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); +}