import { typeSpecificityEnum } from "../../occ-helper";
export class OCCTEdge {
    constructor(occ, och) {
        this.occ = occ;
        this.och = och;
    }
    makeEdgeFromGeom2dCurveAndSurface(inputs) {
        const curve2d = new this.occ.Handle_Geom2d_Curve_2(inputs.curve);
        const surface = new this.occ.Handle_Geom_Surface_2(inputs.surface);
        const makeEdge = new this.occ.BRepBuilderAPI_MakeEdge_30(curve2d, surface);
        const shape = makeEdge.Shape();
        const result = this.och.getActualTypeOfShape(shape);
        curve2d.delete();
        surface.delete();
        makeEdge.delete();
        shape.delete();
        return result;
    }
    line(inputs) {
        return this.och.lineEdge(inputs);
    }
    arcThroughThreePoints(inputs) {
        const gpPnt1 = this.och.gpPnt(inputs.start);
        const gpPnt2 = this.och.gpPnt(inputs.middle);
        const gpPnt3 = this.och.gpPnt(inputs.end);
        const segment = new this.occ.GC_MakeArcOfCircle_4(gpPnt1, gpPnt2, gpPnt3);
        const hcurve = new this.occ.Handle_Geom_Curve_2(segment.Value().get());
        const makeEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(hcurve);
        const shape = makeEdge.Edge();
        gpPnt1.delete();
        gpPnt2.delete();
        gpPnt3.delete();
        segment.delete();
        hcurve.delete();
        makeEdge.delete();
        return shape;
    }
    createCircleEdge(inputs) {
        return this.och.createCircle(inputs.radius, inputs.center, inputs.direction, typeSpecificityEnum.edge);
    }
    createEllipseEdge(inputs) {
        return this.och.createEllipse(inputs.radiusMinor, inputs.radiusMajor, inputs.center, inputs.direction, typeSpecificityEnum.edge);
    }
    removeInternalEdges(inputs) {
        const fusor = new this.occ.ShapeUpgrade_UnifySameDomain_2(inputs.shape, true, true, false);
        fusor.Build();
        const shape = fusor.Shape();
        fusor.delete();
        return shape;
    }
    getEdge(inputs) {
        if (!inputs.shape || (inputs.shape.ShapeType && inputs.shape.ShapeType() > this.occ.TopAbs_ShapeEnum.TopAbs_WIRE) || inputs.shape.IsNull()) {
            throw (new Error("Edge can not be found for shape that is not provided or is of incorrect type"));
        }
        if (!inputs.index) {
            inputs.index = 0;
        }
        let innerEdge = {};
        let foundEdge = false;
        this.och.forEachEdge(inputs.shape, (i, s) => {
            if (i === inputs.index) {
                innerEdge = s;
                foundEdge = true;
            }
        });
        if (!foundEdge) {
            throw (new Error(`Edge can not be found for shape on index ${inputs.index}`));
        }
        else {
            return innerEdge;
        }
    }
    pointOnEdgeAtParam(inputs) {
        return this.och.pointOnEdgeAtParam(inputs);
    }
    tangentOnEdgeAtParam(inputs) {
        return this.och.tangentOnEdgeAtParam(inputs);
    }
    startPointOnEdge(inputs) {
        return this.och.startPointOnEdge(Object.assign({}, inputs));
    }
    endPointOnEdge(inputs) {
        return this.och.endPointOnEdge(Object.assign({}, inputs));
    }
    pointOnEdgeAtLength(inputs) {
        return this.och.pointOnEdgeAtLength(inputs);
    }
    tangentOnEdgeAtLength(inputs) {
        return this.och.tangentOnEdgeAtLength(inputs);
    }
    divideEdgeByParamsToPoints(inputs) {
        return this.och.divideEdgeByParamsToPoints(inputs);
    }
    divideEdgeByEqualDistanceToPoints(inputs) {
        return this.och.divideEdgeByEqualDistanceToPoints(inputs);
    }
    getEdges(inputs) {
        return this.och.getEdges(inputs);
    }
    getEdgeLength(inputs) {
        return this.och.getEdgeLength(inputs);
    }
    getEdgesLengths(inputs) {
        return this.och.getEdgesLengths(inputs);
    }
    getEdgeCenterOfMass(inputs) {
        return this.och.getLinearCenterOfMass(inputs);
    }
    getEdgesCentersOfMass(inputs) {
        return this.och.getShapesCentersOfMass(inputs);
    }
    getCornerPointsOfEdgesForShape(inputs) {
        const points = this.och.getCornerPointsOfEdgesForShape(inputs);
        return points;
    }
}
