From cc36835cc158607ff0d1fd74aefde41e87ffe5ce Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 26 Nov 2024 13:18:55 +0100 Subject: [PATCH 1/4] Added BND_Extrusion::CreateWithPlane cite #636, cite #568 --- CHANGELOG.md | 11 ++++++----- src/bindings/bnd_beam.cpp | 12 ++++++++++++ src/bindings/bnd_beam.h | 1 + src/bindings/bnd_plane.cpp | 17 ++++++++++++++++- src/bindings/bnd_plane.h | 5 ++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95cbe800..f8d10218 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,23 +13,24 @@ diff: - (js, py) DimensionStyle.Id - (js, py) Several delete methods for File3dm Tables: File3dmMaterialTable::Delete, BND_File3dmLayerTable::Delete, BND_File3dmDimStyleTable::Delete - (js, py) Added tests for various ::Delete methods. +- (js, py) Extrusion::CreateWithPlane #636 - (py) Added python 3.13 target #654 +- (py) BND_MeshingParameters::Decode now supports more properties - (js) Layer.Index #655 -- (dotnet) Linux release builds in an Amazon Linux 2023 container - (js) BND_PointCloud::CreateFromThreeJSON #642 -- (py) BND_MeshingParameters::Decode now supports more properties - +- (js) Added several methods and properties for Planes #568 +- (dotnet) Linux release builds in an Amazon Linux 2023 container ### Changed - (py) switching from pybind11 to nanobind. WIP. This affects a lot of the src/binding files, which now include many `#if defined()`. When the switch is complete these will be cleaned up. -- (js) File3dm.objects().deleteItem(id) -> File3dm.objects().delete(id) - (py) File3dmObjectTable now accepts negative indexing #651 @StudioWEngineers +- (js) File3dm.objects().deleteItem(id) -> File3dm.objects().delete(id) ### Fixed -- (js, py) Changes to ViewInfo.Viewport would not set. - (py) uuid conversion in c++ was broken +- (js, py) Changes to ViewInfo.Viewport would not set. - (js) BND_Mesh::CreateFromThreeJSON did not pay attention to vertex colors #641 - (js) BND_PointCloud::CreateFromThreeJSON did not pay attention to RGBA (4 channel) colors #641 diff --git a/src/bindings/bnd_beam.cpp b/src/bindings/bnd_beam.cpp index 5cde50ca..e12d5c20 100644 --- a/src/bindings/bnd_beam.cpp +++ b/src/bindings/bnd_beam.cpp @@ -14,6 +14,16 @@ BND_Extrusion* BND_Extrusion::Create(const BND_Curve& planarCurve, double height return new BND_Extrusion(ext, nullptr); } +BND_Extrusion* BND_Extrusion::CreateWithPlane(const BND_Curve& planarCurve, const class BND_Plane& plane, double height, bool cap) +{ + const ON_Plane& on_plane_ref = plane.ToOnPlane(); + const ON_Plane* on_plane = &on_plane_ref; + ON_Extrusion* ext = ON_Extrusion::CreateFrom3dCurve(*planarCurve.m_curve, on_plane, height, cap); + if (nullptr == ext) + return nullptr; + return new BND_Extrusion(ext, nullptr); +} + BND_Extrusion* BND_Extrusion::CreateBoxExtrusion(const BND_Box& box, bool cap) { if (!box.m_box.IsValid()) return nullptr; @@ -197,6 +207,7 @@ void initExtrusionBindings(rh3dmpymodule& m) { py::class_(m, "Extrusion") .def_static("Create", &BND_Extrusion::Create, py::arg("planarCurve"), py::arg("height"), py::arg("cap")) + .def_static("CreateWithPlane", &BND_Extrusion::CreateWithPlane, py::arg("planarCurve"), py::arg("plane"), py::arg("height"), py::arg("cap")) .def_static("CreateBoxExtrusion", &BND_Extrusion::CreateBoxExtrusion, py::arg("box"), py::arg("cap")) .def_static("CreateCylinderExtrusion", &BND_Extrusion::CreateCylinderExtrusion, py::arg("cylinder"), py::arg("capBottom"), py::arg("capTop")) .def_static("CreatePipeExtrusion", &BND_Extrusion::CreatePipeExtrusion, py::arg("cylinder"), py::arg("otherRadius"), py::arg("capBottom"), py::arg("capTop")) @@ -240,6 +251,7 @@ void initExtrusionBindings(void*) class_>("Extrusion") .constructor<>() .class_function("create", &BND_Extrusion::Create, allow_raw_pointers()) + .class_function("createWithPlane", &BND_Extrusion::CreateWithPlane, allow_raw_pointers()) .class_function("createBoxExtrusion", &BND_Extrusion::CreateBoxExtrusion, allow_raw_pointers()) .class_function("createCylinderExtrusion", &BND_Extrusion::CreateCylinderExtrusion, allow_raw_pointers()) .class_function("createPipeExtrusion", &BND_Extrusion::CreatePipeExtrusion, allow_raw_pointers()) diff --git a/src/bindings/bnd_beam.h b/src/bindings/bnd_beam.h index 452fe735..d3abdd42 100644 --- a/src/bindings/bnd_beam.h +++ b/src/bindings/bnd_beam.h @@ -16,6 +16,7 @@ class BND_Extrusion : public BND_Surface public: static BND_Extrusion* Create(const class BND_Curve& planarCurve, double height, bool cap); + static BND_Extrusion* CreateWithPlane(const class BND_Curve& planarCurve, const class BND_Plane& plane, double height, bool cap); static BND_Extrusion* CreateBoxExtrusion(const class BND_Box& box, bool cap); static BND_Extrusion* CreateCylinderExtrusion(const class BND_Cylinder& cylinder, bool capBottom, bool capTop); static BND_Extrusion* CreatePipeExtrusion(const class BND_Cylinder& cylinder, double otherRadius, bool capTop, bool capBottom); diff --git a/src/bindings/bnd_plane.cpp b/src/bindings/bnd_plane.cpp index 1440bf46..db1c1d27 100644 --- a/src/bindings/bnd_plane.cpp +++ b/src/bindings/bnd_plane.cpp @@ -240,7 +240,22 @@ void initPlaneBindings(void*) .field("zAxis", &BND_Plane::m_zaxis); class_("Plane") - .class_function("worldXY", &BND_PlaneHelper::WorldXY); + + .class_function("worldXY", &BND_Plane::WorldXY) + .class_function("worldYZ", &BND_Plane::WorldYZ) + .class_function("worldZX", &BND_Plane::WorldZX) + .class_function("unset", &BND_Plane::Unset) + .property("origin", &BND_Plane::m_origin) + .property("xAxis", &BND_Plane::m_xaxis) + .property("yAxis", &BND_Plane::m_yaxis) + .property("zAxis", &BND_Plane::m_zaxis) + .function("pointAtUV", &BND_Plane::PointAtUV) + .function("pointAtUVW", &BND_Plane::PointAtUVW) + .function("rotate", &BND_Plane::Rotate) + .function("toJSON", &BND_Plane::toJSON) + .function("encode", &BND_Plane::Encode) + .class_function("decode", &BND_Plane::Decode) + ; } #endif diff --git a/src/bindings/bnd_plane.h b/src/bindings/bnd_plane.h index 7e05415b..dd69d6d7 100644 --- a/src/bindings/bnd_plane.h +++ b/src/bindings/bnd_plane.h @@ -29,7 +29,7 @@ class BND_Plane ON_3dPoint PointAtUV(double u, double v) const; ON_3dPoint PointAtUVW(double u, double v, double w) const; -#if defined(__EMSCRIPTEN__) +#if defined(ON_WASM_COMPILE) emscripten::val toJSON(emscripten::val key); emscripten::val Encode() const; static BND_Plane* Decode(emscripten::val jsonObject); @@ -50,5 +50,8 @@ class BND_PlaneHelper { public: static BND_Plane WorldXY(); + static BND_Plane WorldYZ(); + static BND_Plane WorldZX(); + static BND_Plane Unset(); }; From dfe8cbf7066fd2ea65770e7a5344457621db9ee4 Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 26 Nov 2024 13:46:48 +0100 Subject: [PATCH 2/4] adding Extrusion tests --- tests/javascript/extrusion.test.js | 25 +++++++++++++++++++++++++ tests/python/test_Extrusion.py | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/javascript/extrusion.test.js create mode 100644 tests/python/test_Extrusion.py diff --git a/tests/javascript/extrusion.test.js b/tests/javascript/extrusion.test.js new file mode 100644 index 00000000..aa5131f9 --- /dev/null +++ b/tests/javascript/extrusion.test.js @@ -0,0 +1,25 @@ +const rhino3dm = require('rhino3dm') + +let rhino +beforeEach( async() => { + rhino = await rhino3dm() + }) + +// objective: to test that creating and extrusion vs creating an extrusion with a place yield similar extrusions in different places +test('createExtrusion', async () => { + + const circle1 = new rhino.Circle(1.0); + const extrusion1 = rhino.Extrusion.create(circle1.toNurbsCurve(), 10.0, true) + const plane = new rhino.Plane.worldXY() + plane.origin = [10,10,10] + const circle2 = new rhino.Circle(1.0); + circle2.plane = plane + const extrusion2 = rhino.Extrusion.createWithPlane(circle2.toNurbsCurve(), plane, 10.0, true) + + const bb1 = extrusion1.getBoundingBox() + const bb2 = extrusion2.getBoundingBox() + + expect(bb1.volume).toBeCloseTo(bb2.volume, 5) + expect(bb1.center === bb2.center).toBe(false) + +}) \ No newline at end of file diff --git a/tests/python/test_Extrusion.py b/tests/python/test_Extrusion.py new file mode 100644 index 00000000..ea1a9fb6 --- /dev/null +++ b/tests/python/test_Extrusion.py @@ -0,0 +1,25 @@ +import rhino3dm +import unittest + +#objective: to test that creating and extrusion vs creating an extrusion with a place yield similar extrusions in different places +class TestExtrusion(unittest.TestCase): + def test_createExtrusion(self): + + circle1 = rhino3dm.Circle( 1 ) + extrusion1 = rhino3dm.Extrusion.Create(circle1.ToNurbsCurve(), 10, True) + plane = rhino3dm.Plane.WorldXY() + plane.Origin = rhino3dm.Point3d(10, 10, 10) + circle2 = rhino3dm.Circle( 1 ) + circle2.Plane = plane + extrusion2 = rhino3dm.Extrusion.CreateWithPlane(circle2.ToNurbsCurve(), plane, 10, True) + + bb1 = extrusion1.GetBoundingBox() + bb2 = extrusion2.GetBoundingBox() + + self.assertAlmostEqual( bb1.Volume, bb2.Volume, 5 ) + self.assertFalse( bb1.Center == bb2.Center ) + +if __name__ == '__main__': + print("running tests") + unittest.main() + print("tests complete") \ No newline at end of file From fc4562db070264a59fd2f387d4a7d2d8b675b657 Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 26 Nov 2024 14:11:17 +0100 Subject: [PATCH 3/4] cleaned up Plane js bindings --- src/bindings/bnd_plane.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/bindings/bnd_plane.cpp b/src/bindings/bnd_plane.cpp index db1c1d27..5a098133 100644 --- a/src/bindings/bnd_plane.cpp +++ b/src/bindings/bnd_plane.cpp @@ -240,21 +240,10 @@ void initPlaneBindings(void*) .field("zAxis", &BND_Plane::m_zaxis); class_("Plane") - - .class_function("worldXY", &BND_Plane::WorldXY) - .class_function("worldYZ", &BND_Plane::WorldYZ) - .class_function("worldZX", &BND_Plane::WorldZX) - .class_function("unset", &BND_Plane::Unset) - .property("origin", &BND_Plane::m_origin) - .property("xAxis", &BND_Plane::m_xaxis) - .property("yAxis", &BND_Plane::m_yaxis) - .property("zAxis", &BND_Plane::m_zaxis) - .function("pointAtUV", &BND_Plane::PointAtUV) - .function("pointAtUVW", &BND_Plane::PointAtUVW) - .function("rotate", &BND_Plane::Rotate) - .function("toJSON", &BND_Plane::toJSON) - .function("encode", &BND_Plane::Encode) - .class_function("decode", &BND_Plane::Decode) + .class_function("worldXY", &BND_PlaneHelper::WorldXY) + .class_function("worldYZ", &BND_PlaneHelper::WorldYZ) + .class_function("worldZX", &BND_PlaneHelper::WorldZX) + .class_function("unset", &BND_PlaneHelper::WorldZX) ; } From 7642d85869f5f767db3662e99cb37135da495f1e Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 26 Nov 2024 14:20:35 +0100 Subject: [PATCH 4/4] implementations --- src/bindings/bnd_plane.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bindings/bnd_plane.cpp b/src/bindings/bnd_plane.cpp index 5a098133..b62df029 100644 --- a/src/bindings/bnd_plane.cpp +++ b/src/bindings/bnd_plane.cpp @@ -199,6 +199,21 @@ BND_Plane BND_PlaneHelper::WorldXY() return BND_Plane::WorldXY(); } +BND_Plane BND_PlaneHelper::WorldYZ() +{ + return BND_Plane::WorldYZ(); +} + +BND_Plane BND_PlaneHelper::WorldZX() +{ + return BND_Plane::WorldZX(); +} + +BND_Plane BND_PlaneHelper::Unset() +{ + return BND_Plane::Unset(); +} + #if defined(ON_PYTHON_COMPILE) void initPlaneBindings(rh3dmpymodule& m) @@ -243,7 +258,7 @@ void initPlaneBindings(void*) .class_function("worldXY", &BND_PlaneHelper::WorldXY) .class_function("worldYZ", &BND_PlaneHelper::WorldYZ) .class_function("worldZX", &BND_PlaneHelper::WorldZX) - .class_function("unset", &BND_PlaneHelper::WorldZX) + .class_function("unset", &BND_PlaneHelper::Unset) ; }