primitives-2d_circle.js

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

/**
 * Creates a circle based on the specified parameters.
 * @memberof primitives-2D
 * @alias Circle
 * @param {Object} parameters - The parameters for the circle.
 * @param {Plane} [parameters.plane=Plane.XY] - The plane in which the circle is constructed.
 * @param {Vector} [parameters.center=Vector.ZERO] - The center of the circle.
 * @param {number} parameters.radius - The radius of the circle.
 * @returns {Face} A `Face` object representing the constructed circle.
 */
const Circle = ({plane = Plane.XY, center = Vector.ZERO, radius}) => {
  const axis = plane.wrapped.Position().Ax2();
  const localOffset = plane.toWorldCoordinates(center.wrapped);
  const circle = new oc.gp_Circ_2(axis, radius);
  const edge = new oc.BRepBuilderAPI_MakeEdge_8(circle).Edge();
  const builder = new oc.BRepBuilderAPI_MakeWire_1();
  builder.Add_1(edge);
  return new Face(new oc.BRepBuilderAPI_MakeFace_15(builder.Wire(), true).Face()).translate(new Vector({wrapped: localOffset}));
};

export {Circle};