primitives-1d_polyline.js

import {Wire} from "../modeling";
import {Plane, Vector} from "../math";
import oc from "../opencascade/initializer";

/**
 * Creates a polyline that connects all points into a single object.
 * @memberof primitives-1D
 * @alias Polyline
 * @param {Object} parameters - The parameters for the polyline.
 * @param {Plane} [parameters.plane=Plane.XY] - The plane in which the polyline is constructed.
 * @param {Vector[]} parameters.points - The points connected by the polyline.
 * @returns {Wire} An `Wire` object representing the constructed `Polyline`.
 */
const Polyline = ({plane = Plane.XY, points}) => {
  const builder = new oc.BRepBuilderAPI_MakeWire_1();
  const globalPoints = points.map((point) => plane.toWorldCoordinates(new oc.gp_Pnt_3(point.x, point.y, point.z)));
  for (let index = 0; index < globalPoints.length - 1; index++) {
    builder.Add_1(new oc.BRepBuilderAPI_MakeEdge_3(globalPoints[index], globalPoints[index + 1]).Edge());
  }
  return new Wire(builder.Wire());
};

export {Polyline};