From c1e185201585c0c88d3ef24882b66b26a041e47f Mon Sep 17 00:00:00 2001 From: fraguada Date: Thu, 14 Sep 2023 16:09:37 +0200 Subject: [PATCH] added some point related bindings for curves --- src/bindings/bnd_curve.cpp | 1 + src/bindings/bnd_polyline.cpp | 23 ++++++++++++++++++++++- src/bindings/bnd_polyline.h | 6 ++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bindings/bnd_curve.cpp b/src/bindings/bnd_curve.cpp index 233e5e6e9..ef36a90f6 100644 --- a/src/bindings/bnd_curve.cpp +++ b/src/bindings/bnd_curve.cpp @@ -350,6 +350,7 @@ using namespace emscripten; void initCurveBindings(void*) { class_>("Curve") + .class_function("createControlPointCurve", &BND_Curve::CreateControlPointCurve, allow_raw_pointers()) .property("domain", &BND_Curve::GetDomain, &BND_Curve::SetDomain) .property("dimension", &BND_GeometryBase::Dimension) .function("changeDimension", &BND_Curve::ChangeDimension) diff --git a/src/bindings/bnd_polyline.cpp b/src/bindings/bnd_polyline.cpp index 44f61f4af..79f32ccc0 100644 --- a/src/bindings/bnd_polyline.cpp +++ b/src/bindings/bnd_polyline.cpp @@ -7,6 +7,15 @@ BND_Point3dList::BND_Point3dList(const std::vector& points) m_polyline.Append(count, pts); } +BND_Polyline* BND_Polyline::CreateFromPoints(const std::vector& points) +{ + int count = (int)points.size(); + const ON_3dPoint* pts = points.data(); + BND_Polyline* rc = new BND_Polyline(); + rc->m_polyline.Append(count, pts); + return rc; +} + ON_3dPoint BND_Point3dList::GetPoint(int index) const { #if defined(ON_PYTHON_COMPILE) @@ -126,7 +135,16 @@ BND_LineCurve* BND_Polyline::SegmentAt(int index) const return new BND_LineCurve(m_polyline[index], m_polyline[index+1]); } - +#if defined(ON_PYTHON_COMPILE) +void BND_Point3dList::Append2 (int count, pybind11::object points) +{ + for (auto item : points) + { + ON_3dPoint point = item.cast(); + m_polyline.Append(point) + } +} +#endif ////////////////////////////////////////////////////////////////////////////////////////////// @@ -152,6 +170,7 @@ void initPolylineBindings(pybind11::module& m) .def("SetAllX", &BND_Point3dList::SetAllX, py::arg("x")) .def("SetAllY", &BND_Point3dList::SetAllY, py::arg("y")) .def("SetAllZ", &BND_Point3dList::SetAllZ, py::arg("z")) + .def("Append", &BND_Point3dList::Append2, py::arg("count"), py::arg("points")) ; py::class_(m, "Polyline") @@ -200,6 +219,7 @@ void initPolylineBindings(void*) .function("setAllX", &BND_Point3dList::SetAllX) .function("setAllY", &BND_Point3dList::SetAllY) .function("setAllZ", &BND_Point3dList::SetAllZ) + .function("append", &BND_Point3dList::Append) ; class_>("Polyline") @@ -222,6 +242,7 @@ void initPolylineBindings(void*) .class_function("createInscribedPolygon", &BND_Polyline::CreateInscribedPolygon, allow_raw_pointers()) .class_function("createCircumscribedPolygon", &BND_Polyline::CreateCircumscribedPolygon, allow_raw_pointers()) .class_function("createStarPolygon", &BND_Polyline::CreateStarPolygon, allow_raw_pointers()) + .class_function("createFromPoints", &BND_Polyline::CreateFromPoints, allow_raw_pointers()) ; } #endif diff --git a/src/bindings/bnd_polyline.h b/src/bindings/bnd_polyline.h index 0241877e0..f675734f0 100644 --- a/src/bindings/bnd_polyline.h +++ b/src/bindings/bnd_polyline.h @@ -33,8 +33,13 @@ class BND_Point3dList void SetAllX(double xValue); void SetAllY(double yValue); void SetAllZ(double zValue); + void Append(int count, const std::vector& points) { m_polyline.Append(count, points); } + #if defined(ON_PYTHON_COMPILE) + void Append2(int count, const std::vector& points) + #endif //public static int ClosestIndexInList(IList list, Point3d testPoint) //public static Point3d ClosestPointInList(IList list, Point3d testPoint) + }; class BND_Polyline : public BND_Point3dList @@ -69,4 +74,5 @@ class BND_Polyline : public BND_Point3dList static BND_Polyline* CreateInscribedPolygon(class BND_Circle& circle, int sideCount); static BND_Polyline* CreateCircumscribedPolygon(class BND_Circle& circle, int sideCount); static BND_Polyline* CreateStarPolygon(class BND_Circle& circle, double radius, int cornerCount); + static BND_Polyline* CreateFromPoints(const std::vector& points) };