import oc from "../opencascade/initializer";
import {Face} from "../modeling";
import {Plane, Vector} from "../math";
/**
* Creates a ellipse based on the specified parameters.
* @memberof primitives-2D
* @alias Ellipse
* @param {Object} parameters - The parameters for the ellipse.
* @param {Plane} [parameters.plane=Plane.XY] - The plane in which the ellipse is constructed.
* @param {Vector} [parameters.center=Vector.ZERO] - The center of the ellipse.
* @param {number} parameters.xRadius - The radius of the ellipse along the X-axis.
* @param {number} parameters.yRadius - The radius of the ellipse along the Y-axis.
* @returns {Face} A `Face` object representing the constructed ellipse.
*/
const Ellipse = ({plane = Plane.XY, center = Vector.ZERO, xRadius, yRadius}) => {
const globalCenter = plane.toWorldCoordinates(new oc.gp_Pnt_3(center.x, center.y, center.z));
let ellipse;
if (yRadius > xRadius) {
const axis = new oc.gp_Ax1_2(globalCenter, plane.wrapped.Axis().Direction());
ellipse = new oc.gp_Elips_2(plane.wrapped.Position().Ax2(), yRadius, xRadius).Rotated(axis, (90 * 2 * Math.PI) / 360);
} else {
ellipse = new oc.gp_Elips_2(plane.wrapped.Position().Ax2(), xRadius, yRadius);
}
ellipse.SetLocation(globalCenter);
const edge = new oc.BRepBuilderAPI_MakeEdge_12(ellipse).Edge();
const builder = new oc.BRepBuilderAPI_MakeWire_1();
builder.Add_1(edge);
return new Face(new oc.BRepBuilderAPI_MakeFace_15(builder.Wire(), true).Face());
};
export {Ellipse};