Skip to content

Commit cdcbc2c

Browse files
committed
[test] add more tests related to polyline
1 parent 845d0c8 commit cdcbc2c

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

iso2mesh/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
highordertet,
122122
ismember_rows,
123123
ray2surf,
124+
bbxflatsegment,
125+
orderloopedge,
124126
)
125127

126128
from .utils import (
@@ -192,6 +194,8 @@
192194
surfboolean,
193195
meshresample,
194196
domeshsimplify,
197+
slicesurf,
198+
slicesurf3,
195199
)
196200

197201
from .line import (
@@ -437,5 +441,9 @@
437441
"savejnii",
438442
"loadh5",
439443
"saveh5",
444+
"slicesurf",
445+
"slicesurf3",
446+
"bbxflatsegment",
447+
"orderloopedge",
440448
]
441449
__license__ = """GNU General Public License v3 and later"""

iso2mesh/geometry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ def extrudecurve(
515515
"""
516516
from scipy.interpolate import splev, splrep
517517

518+
xy = np.array(xy)
519+
yz = np.array(yz)
520+
518521
# Compute interpolation points along the xy curve
519522
xrange = np.max(xy[:, 0]) - np.min(xy[:, 0])
520523
dx = xrange / Nx

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"Data format",
4242
],
4343
platforms="any",
44-
install_requires=["numpy>=1.8.0", "matplotlib", "jdata>=0.8.0", "bjdata"],
44+
install_requires=["numpy>=1.8.0", "matplotlib", "jdata>=0.8.2", "bjdata"],
4545
classifiers=[
4646
"Development Status :: 4 - Beta",
4747
"Intended Audience :: Developers",

test/run_test.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,5 +1683,74 @@ def test_plotmesh_elemselector(self):
16831683
self.assertEqual(np.round(np.sum(facecolors, axis=0), 4).tolist(), expected_fc)
16841684

16851685

1686+
class TestUtilities(unittest.TestCase):
1687+
"""Test suite for utility and helper functions"""
1688+
1689+
def setUp(self):
1690+
"""Set up test fixtures"""
1691+
self.polyline = np.array(
1692+
[[0, 0], [1, 0], [2, 1], [3, 1], [4, 0], [5, 0]], dtype=float
1693+
)
1694+
1695+
def test_polylinelen_polyline_length(self):
1696+
"""Test polyline length calculation"""
1697+
result = polylinelen(self.polyline)[0]
1698+
1699+
self.assertEqual(
1700+
np.round(result, 8).tolist(), [1.0, 1.41421356, 1.0, 1.41421356, 1.0]
1701+
)
1702+
1703+
def test_polylinesimplify_polyline_simplification(self):
1704+
"""Test polyline simplification"""
1705+
tolerance = 0.1
1706+
result = polylinesimplify(self.polyline, 3.14)
1707+
1708+
self.assertLessEqual(result[0].tolist(), [[0, 0], [5, 0]])
1709+
self.assertLessEqual(result[1], 5)
1710+
1711+
def test_polylineinterp_polyline_interpolation(self):
1712+
"""Test polyline interpolation"""
1713+
# Interpolate at specific length
1714+
polylen = polylinelen(self.polyline)[0]
1715+
loc = [1.3, 2.7]
1716+
result = polylineinterp(polylen, loc)
1717+
1718+
self.assertEqual(result[0].tolist(), [2, 3])
1719+
self.assertEqual(np.round(result[1], 8).tolist(), [0.21213203, 0.28578644])
1720+
1721+
def test_varargin2struct_argument_parsing(self):
1722+
"""Test argument parsing to structure"""
1723+
# Test with key-value pairs
1724+
result = varargin2struct("key1", "value1", "key2", 42, "key3", [1, 2, 3])
1725+
1726+
self.assertEqual(result["key1"], "value1")
1727+
self.assertEqual(result["key2"], 42)
1728+
1729+
def test_jsonopt_json_options(self):
1730+
"""Test JSON options processing"""
1731+
options = {"option1": "value1", "option2": 42}
1732+
key = "option1"
1733+
default = "default_value"
1734+
1735+
result = jsonopt(key, default, options)
1736+
1737+
if result is not None:
1738+
self.assertEqual(result, "value1")
1739+
1740+
# Test with non-existent key
1741+
result = jsonopt("nonexistent", default, options)
1742+
if result is not None:
1743+
self.assertEqual(result, default)
1744+
1745+
def test_closestnode_closest_node_finding(self):
1746+
"""Test closest node finding"""
1747+
nodes = self.polyline
1748+
query_point = np.array([1.5, 0.5], dtype=float)
1749+
1750+
result = closestnode(nodes, query_point)
1751+
1752+
self.assertEqual(result, (2, 0.5))
1753+
1754+
16861755
if __name__ == "__main__":
16871756
unittest.main()

0 commit comments

Comments
 (0)