From 08e173f154da72a539589f02af771cdd492a0aab Mon Sep 17 00:00:00 2001 From: fraguada <fraguada@gmail.com> Date: Fri, 24 Jan 2025 17:28:52 +0100 Subject: [PATCH] some changes related to findings from testing the python samples in rhino-dev-samples --- src/bindings/bindings.cpp | 2 +- src/bindings/bnd_extensions.cpp | 4 ++-- tests/python/test_PointCloud.py | 42 +++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/bindings/bindings.cpp b/src/bindings/bindings.cpp index 92bb00ac..49197d85 100644 --- a/src/bindings/bindings.cpp +++ b/src/bindings/bindings.cpp @@ -96,7 +96,7 @@ std::string ToStdString(const py::str& str) BND_TUPLE CreateTuple(int count) { #if defined(ON_PYTHON_COMPILE) - BND_TUPLE rc = py::make_tuple(count); + BND_TUPLE rc = py::tuple(count); #else emscripten::val rc(emscripten::val::array()); #endif diff --git a/src/bindings/bnd_extensions.cpp b/src/bindings/bnd_extensions.cpp index d93ead30..7b3d0e08 100644 --- a/src/bindings/bnd_extensions.cpp +++ b/src/bindings/bnd_extensions.cpp @@ -2010,12 +2010,12 @@ void initExtensionsBindings(rh3dmpymodule& m) .def_static("Read", &BND_ONXModel::Read, py::arg("path")) .def_static("ReadNotes", &BND_ONXModel::ReadNotes, py::arg("path")) .def_static("ReadArchiveVersion", &BND_ONXModel::ReadArchiveVersion, py::arg("path")) -/* +#if !defined(NANOBIND) .def_static("FromByteArray", [](py::buffer b) { py::buffer_info info = b.request(); return BND_ONXModel::FromByteArray(static_cast<int>(info.size), info.ptr); }) - */ + #endif .def("Write", &BND_ONXModel::Write, py::arg("path"), py::arg("version")=0) .def_property("StartSectionComments", &BND_ONXModel::GetStartSectionComments, &BND_ONXModel::SetStartSectionComments) .def_property("ApplicationName", &BND_ONXModel::GetApplicationName, &BND_ONXModel::SetApplicationName) diff --git a/tests/python/test_PointCloud.py b/tests/python/test_PointCloud.py index df745d8d..1f9379be 100644 --- a/tests/python/test_PointCloud.py +++ b/tests/python/test_PointCloud.py @@ -1,7 +1,8 @@ import rhino3dm import unittest -#objective: to test that passing a list of points or a Point3dList to the PointCloud ctor returns the same Point Cloud + +# objective: to test that passing a list of points or a Point3dList to the PointCloud ctor returns the same Point Cloud class TestPointCloud(unittest.TestCase): def test_ctor(self): @@ -15,9 +16,42 @@ def test_ctor(self): pcFromArray = rhino3dm.PointCloud(pointArray) pcFromList = rhino3dm.PointCloud(pointList) - self.assertEqual( pcFromArray.ClosestPoint(rhino3dm.Point3d(0,0,0)), pcFromArray.ClosestPoint(rhino3dm.Point3d(0,0,0)) ) + self.assertEqual( + pcFromArray.ClosestPoint(rhino3dm.Point3d(0, 0, 0)), + pcFromArray.ClosestPoint(rhino3dm.Point3d(0, 0, 0)), + ) + + def test_members(self): + + pc = rhino3dm.PointCloud() + + # pc.Add(rhino3dm.Point3d(0, 0, 0)) + # pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 0, 1)) + # pc.Add(rhino3dm.Point3d(0, 0, 0), (255, 0, 0, 0)) + # pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 1, 1), (255, 0, 0, 0)) + # pc.Add(rhino3dm.Point3d(0, 0, 0), 1.234) + pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 1, 1), (255, 0, 0, 0), 1.234) + print(len(pc)) + pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 1, 1), (255, 0, 0, 0), 1.234) + print(len(pc)) + pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 1, 1), (255, 0, 0, 0), 1.234) + print(len(pc)) + pc.Add(rhino3dm.Point3d(0, 0, 0), rhino3dm.Vector3d(0, 1, 1), (255, 0, 0, 0), 1.234) + print(len(pc)) + + pts = pc.GetPoints() + print(pts) + nrmls = pc.GetNormals() + print(nrmls) + cols = pc.GetColors() + print(cols) + vals = pc.GetValues() + print(vals) + + + -if __name__ == '__main__': +if __name__ == "__main__": print("running tests") unittest.main() - print("tests complete") \ No newline at end of file + print("tests complete")