Skip to content

Commit

Permalink
added some point related bindings for curves
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Sep 14, 2023
1 parent cbb97ec commit c1e1852
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bindings/bnd_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ using namespace emscripten;
void initCurveBindings(void*)
{
class_<BND_Curve, base<BND_GeometryBase>>("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)
Expand Down
23 changes: 22 additions & 1 deletion src/bindings/bnd_polyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ BND_Point3dList::BND_Point3dList(const std::vector<ON_3dPoint>& points)
m_polyline.Append(count, pts);
}

BND_Polyline* BND_Polyline::CreateFromPoints(const std::vector<ON_3dPoint>& 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)
Expand Down Expand Up @@ -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<ON_3dPoint>();
m_polyline.Append(point)
}
}
#endif

//////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -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_<BND_Polyline,BND_Point3dList>(m, "Polyline")
Expand Down Expand Up @@ -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_<BND_Polyline, base<BND_Point3dList>>("Polyline")
Expand All @@ -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
6 changes: 6 additions & 0 deletions src/bindings/bnd_polyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ON_3dPoint>& points) { m_polyline.Append(count, points); }
#if defined(ON_PYTHON_COMPILE)
void Append2(int count, const std::vector<ON_3dPoint>& points)
#endif
//public static int ClosestIndexInList(IList<Point3d> list, Point3d testPoint)
//public static Point3d ClosestPointInList(IList<Point3d> list, Point3d testPoint)

};

class BND_Polyline : public BND_Point3dList
Expand Down Expand Up @@ -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<ON_3dPoint>& points)
};

0 comments on commit c1e1852

Please sign in to comment.