Skip to content

Commit

Permalink
Fixed a bug where a face for a bottom facing cell could be triangulat…
Browse files Browse the repository at this point in the history
…ed incorrectly.
  • Loading branch information
wdolinar committed Mar 27, 2023
1 parent 3207894 commit 7a6aaca
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 73 deletions.
2 changes: 1 addition & 1 deletion _package/xms/extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .ugrid_2d_data_extractor import UGrid2dDataExtractor # NOQA: F401
from .ugrid_2d_polyline_data_extractor import UGrid2dPolylineDataExtractor # NOQA: F401

__version__ = '8.0.3'
__version__ = '8.0.4'
57 changes: 57 additions & 0 deletions xmsextractor/ugrid/XmUGridTriangles2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,5 +646,62 @@ void XmUGridTriangles2dUnitTests::testBuildCentroidAndEarcutTriangles()
};
TS_ASSERT_EQUALS(trianglesExpected, trianglesOut);
} // XmUGridTriangles2dUnitTests::testBuildCentroidAndEarcutTriangles
//------------------------------------------------------------------------------
/// \brief Test creating triangles for centroid and earcut cells for a bottom
/// face of a 3D cell (clock-wise ordering).
//------------------------------------------------------------------------------
void XmUGridTriangles2dUnitTests::testBuildCentroidAndEarcutTrianglesBottomFace()
{
// 7----6---------3----2
// | | | |
// | | | |
// | | | |
// | | (8) | |
// | | | |
// | | | |
// | | | |
// | 5---------4 |
// | |
// | |
// | |
// 0-------------------1
// clang-format off
VecPt3d points = {
{ 0, 0, 0}, // 0
{15, 0, 0}, // 1
{15, 15, 0}, // 2
{10, 15, 0}, // 3
{10, 5, 0}, // 4
{ 5, 5, 0}, // 5
{ 5, 15, 0}, // 6
{ 0, 15, 0} // 7
};

// Cell type (5), number of points (3), point numbers, clock-wise from plan view
std::vector<int> cells = {
XMU_POLYGON, 8, 7, 6, 5, 4, 3, 2, 1, 0,
XMU_QUAD, 4, 4, 5, 6, 3
};
// clang-format on

std::shared_ptr<XmUGrid> ugrid = XmUGrid::New(points, cells);
XmUGridTriangles2dImpl ugridTris;

ugridTris.BuildTriangles(*ugrid, XmUGridTriangles2d::PO_CENTROIDS_ONLY);

VecPt3d triPointsOut = ugridTris.GetPoints();
VecPt3d triPointsExpected = points;
triPointsExpected.push_back({7.5, 10, 0});
TS_ASSERT_EQUALS(triPointsExpected, triPointsOut);

VecInt trianglesOut = ugridTris.GetTriangles();
VecInt trianglesExpected = {
// clang-format off
7, 6, 5, 4, 3, 2, 0, 7, 5, 4, 2, 1, 1, 0, 5, 5, 4, 1, // earcut
4, 5, 8, 5, 6, 8, 6, 3, 8, 3, 4, 8 // centroid
// clang-format off
};
TS_ASSERT_EQUALS(trianglesExpected, trianglesOut);
} // XmUGridTriangles2dUnitTests::testBuildCentroidAndEarcutTrianglesBottomFace

#endif
69 changes: 35 additions & 34 deletions xmsextractor/ugrid/XmUGridTriangles2d.t.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#pragma once
//------------------------------------------------------------------------------
/// \file
/// \ingroup extractor
/// \copyright (C) Copyright Aquaveo 2018. Distributed under FreeBSD License
/// (See accompanying file LICENSE or https://aqaveo.com/bsd/license.txt)
//------------------------------------------------------------------------------

#ifdef CXX_TEST

// 3. Standard Library Headers

// 4. External Library Headers
#include <cxxtest/TestSuite.h>

// 5. Shared Headers
#include <xmscore/misc/base_macros.h>
#include <xmscore/misc/boost_defines.h>
#include <xmscore/points/pt.h>

// 6. Non-shared Headers

////////////////////////////////////////////////////////////////////////////////
class XmUGridTriangles2dUnitTests : public CxxTest::TestSuite
{
public:
void testBuildCentroidTrianglesOnTriangle();
void testBuildCentroidTrianglesOnQuad();
void testBuildCentroidTriangles2dCellTypes();
void testBuildEarcutTriangles();
void testBuildCentroidAndEarcutTriangles();
}; // XmUGridTriangles2d

#endif
#pragma once
//------------------------------------------------------------------------------
/// \file
/// \ingroup extractor
/// \copyright (C) Copyright Aquaveo 2018. Distributed under FreeBSD License
/// (See accompanying file LICENSE or https://aqaveo.com/bsd/license.txt)
//------------------------------------------------------------------------------

#ifdef CXX_TEST

// 3. Standard Library Headers

// 4. External Library Headers
#include <cxxtest/TestSuite.h>

// 5. Shared Headers
#include <xmscore/misc/base_macros.h>
#include <xmscore/misc/boost_defines.h>
#include <xmscore/points/pt.h>

// 6. Non-shared Headers

////////////////////////////////////////////////////////////////////////////////
class XmUGridTriangles2dUnitTests : public CxxTest::TestSuite
{
public:
void testBuildCentroidTrianglesOnTriangle();
void testBuildCentroidTrianglesOnQuad();
void testBuildCentroidTriangles2dCellTypes();
void testBuildEarcutTriangles();
void testBuildCentroidAndEarcutTriangles();
void testBuildCentroidAndEarcutTrianglesBottomFace();
}; // XmUGridTriangles2d

#endif
Loading

0 comments on commit 7a6aaca

Please sign in to comment.