import * as Inputs from "../../api/inputs/inputs";
export class OCCTWire {
    constructor(occ, och) {
        this.occ = occ;
        this.och = och;
    }
    createPolygonWire(inputs) {
        return this.och.wiresService.createPolygonWire(inputs);
    }
    createPolygons(inputs) {
        const wires = inputs.polygons.map(p => this.createPolygonWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    createPolylineWire(inputs) {
        return this.och.wiresService.createPolylineWire(inputs);
    }
    createPolylines(inputs) {
        const wires = inputs.polylines.map(p => this.createPolylineWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    createLineWire(inputs) {
        return this.och.wiresService.createLineWire(inputs);
    }
    createLines(inputs) {
        const wires = inputs.lines.map(p => this.createLineWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    createBezier(inputs) {
        return this.och.wiresService.createBezier(inputs);
    }
    createBezierWires(inputs) {
        const wires = inputs.bezierWires.map(p => this.createBezier(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    interpolatePoints(inputs) {
        return this.och.wiresService.interpolatePoints(inputs);
    }
    interpolateWires(inputs) {
        const wires = inputs.interpolations.map(p => this.interpolatePoints(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    splitOnPoints(inputs) {
        return this.och.wiresService.splitOnPoints(inputs);
    }
    combineEdgesAndWiresIntoAWire(inputs) {
        return this.och.converterService.combineEdgesAndWiresIntoAWire(inputs);
    }
    createWireFromEdge(inputs) {
        return this.och.wiresService.createWireFromEdges(inputs);
    }
    addEdgesAndWiresToWire(inputs) {
        return this.och.wiresService.addEdgesAndWiresToWire(inputs);
    }
    createBSpline(inputs) {
        return this.och.wiresService.createBSpline(inputs);
    }
    createBSplines(inputs) {
        const wires = inputs.bSplines.map(p => this.createBSpline(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
    createZigZagBetweenTwoWires(inputs) {
        return this.och.wiresService.createZigZagBetweenTwoWires(inputs);
    }
    divideWireByParamsToPoints(inputs) {
        return this.och.wiresService.divideWireByParamsToPoints(inputs);
    }
    divideWiresByParamsToPoints(inputs) {
        return inputs.shapes.map(s => this.divideWireByParamsToPoints(Object.assign(Object.assign({}, inputs), { shape: s })));
    }
    divideWireByEqualDistanceToPoints(inputs) {
        return this.och.wiresService.divideWireByEqualDistanceToPoints(inputs);
    }
    divideWiresByEqualDistanceToPoints(inputs) {
        return inputs.shapes.map(s => this.divideWireByEqualDistanceToPoints(Object.assign(Object.assign({}, inputs), { shape: s })));
    }
    pointOnWireAtParam(inputs) {
        return this.och.wiresService.pointOnWireAtParam(inputs);
    }
    pointOnWireAtLength(inputs) {
        return this.och.wiresService.pointOnWireAtLength(inputs);
    }
    tangentOnWireAtParam(inputs) {
        return this.och.wiresService.tangentOnWireAtParam(inputs);
    }
    tangentOnWireAtLength(inputs) {
        return this.och.wiresService.tangentOnWireAtLength(inputs);
    }
    derivativesOnWireAtLength(inputs) {
        const wire = inputs.shape;
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const absc = new this.occ.GCPnts_AbscissaPoint_2(curve, inputs.length, curve.FirstParameter());
        const param = absc.Parameter();
        const gpPnt = this.och.entitiesService.gpPnt([0, 0, 0]);
        const der1 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der2 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der3 = this.och.entitiesService.gpVec([0, 0, 0]);
        curve.D3(param, gpPnt, der1, der2, der3);
        const der = [[der1.X(), der1.Y(), der1.Z()], [der2.X(), der2.Y(), der2.Z()], [der3.X(), der3.Y(), der3.Z()]];
        der1.delete();
        der2.delete();
        der3.delete();
        curve.delete();
        absc.delete();
        gpPnt.delete();
        return der;
    }
    derivativesOnWireAtParam(inputs) {
        const wire = inputs.shape;
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const gpPnt = this.och.entitiesService.gpPnt([0, 0, 0]);
        const der1 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der2 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der3 = this.och.entitiesService.gpVec([0, 0, 0]);
        const param = this.och.vecHelper.remap(inputs.param, 0, 1, curve.FirstParameter(), curve.LastParameter());
        curve.D3(param, gpPnt, der1, der2, der3);
        const der = [[der1.X(), der1.Y(), der1.Z()], [der2.X(), der2.Y(), der2.Z()], [der3.X(), der3.Y(), der3.Z()]];
        der1.delete();
        der2.delete();
        der3.delete();
        curve.delete();
        gpPnt.delete();
        return der;
    }
    startPointOnWire(inputs) {
        return this.och.wiresService.startPointOnWire(inputs);
    }
    endPointOnWire(inputs) {
        return this.och.wiresService.endPointOnWire(inputs);
    }
    createCircleWire(inputs) {
        return this.och.entitiesService.createCircle(inputs.radius, inputs.center, inputs.direction, Inputs.OCCT.typeSpecificityEnum.wire);
    }
    createEllipseWire(inputs) {
        return this.och.entitiesService.createEllipse(inputs.radiusMinor, inputs.radiusMajor, inputs.center, inputs.direction, Inputs.OCCT.typeSpecificityEnum.wire);
    }
    createSquareWire(inputs) {
        return this.och.wiresService.createSquareWire(inputs);
    }
    createStarWire(inputs) {
        return this.och.wiresService.createStarWire(inputs);
    }
    createChristmasTreeWire(inputs) {
        return this.och.wiresService.createChristmasTreeWire(inputs);
    }
    createParallelogramWire(inputs) {
        return this.och.wiresService.createParallelogramWire(inputs);
    }
    createHeartWire(inputs) {
        return this.och.wiresService.createHeartWire(inputs);
    }
    createNGonWire(inputs) {
        return this.och.wiresService.createNGonWire(inputs);
    }
    createRectangleWire(inputs) {
        return this.och.wiresService.createRectangleWire(inputs);
    }
    createLPolygonWire(inputs) {
        return this.och.wiresService.createLPolygonWire(inputs);
    }
    getWire(inputs) {
        return this.och.shapeGettersService.getWire(inputs);
    }
    getWires(inputs) {
        return this.och.shapeGettersService.getWires(inputs);
    }
    getWireLength(inputs) {
        return this.och.wiresService.getWireLength(inputs);
    }
    getWiresLengths(inputs) {
        return this.och.wiresService.getWiresLengths(inputs);
    }
    getWireCenterOfMass(inputs) {
        return this.och.wiresService.getWireCenterOfMass(inputs);
    }
    getWiresCentersOfMass(inputs) {
        return inputs.shapes.map(w => this.och.wiresService.getWireCenterOfMass({
            shape: w
        }));
    }
    reversedWire(inputs) {
        const wire = inputs.shape;
        const reversed = wire.Reversed();
        const result = this.och.converterService.getActualTypeOfShape(reversed);
        reversed.delete();
        return result;
    }
    reversedWireFromReversedEdges(inputs) {
        const wire = inputs.shape;
        const edges = this.och.edgesService.getEdgesAlongWire({ shape: wire });
        const reversedEdges = edges.map(e => {
            return this.och.converterService.getActualTypeOfShape(e.Reversed());
        });
        const reversed = this.och.converterService.combineEdgesAndWiresIntoAWire({ shapes: reversedEdges.reverse() });
        const result = this.och.converterService.getActualTypeOfShape(reversed);
        reversed.delete();
        reversedEdges.forEach(e => e.delete());
        return result;
    }
    placeWireOnFace(inputs) {
        const wire = inputs.wire;
        const face = inputs.face;
        const srf = this.och.surfaceFromFace({ shape: face });
        const result = this.och.wiresService.placeWire(wire, srf);
        return result;
    }
    placeWiresOnFace(inputs) {
        const wires = inputs.wires;
        const face = inputs.face;
        const srf = this.och.surfaceFromFace({ shape: face });
        const result = wires.map(wire => this.och.wiresService.placeWire(wire, srf));
        return result;
    }
    closeOpenWire(inputs) {
        const wire = inputs.shape;
        const firstPoint = this.och.wiresService.startPointOnWire({ shape: wire });
        const lastPoint = this.och.wiresService.endPointOnWire({ shape: wire });
        const tolerance = 1.0e-7;
        if (this.och.vecHelper.vectorsTheSame(firstPoint, lastPoint, tolerance)) {
            return wire;
        }
        const edgeWire = this.createLineWire({ start: lastPoint, end: firstPoint });
        const result = this.addEdgesAndWiresToWire({ shape: wire, shapes: [edgeWire] });
        edgeWire.delete();
        return result;
    }
    project(inputs) {
        const wire = inputs.wire;
        const gpDir = this.och.entitiesService.gpDir(inputs.direction);
        const proj = new this.occ.BRepProj_Projection_1(wire, inputs.shape, gpDir);
        const shape = proj.Shape();
        gpDir.delete();
        proj.delete();
        return shape;
    }
    wiresToPoints(inputs) {
        const wires = this.getWires({ shape: inputs.shape });
        const allWirePoints = [];
        wires.forEach(w => {
            const edgePoints = this.och.edgesService.edgesToPoints(Object.assign(Object.assign({}, inputs), { shape: w }));
            const flatPoints = edgePoints.flat();
            const dupsRemoved = this.och.vecHelper.removeConsecutiveDuplicates(flatPoints, false);
            allWirePoints.push(dupsRemoved);
        });
        return allWirePoints;
    }
    projectWires(inputs) {
        const shapes = [];
        inputs.wires.forEach(wire => {
            const gpDir = this.och.entitiesService.gpDir(inputs.direction);
            const proj = new this.occ.BRepProj_Projection_1(wire, inputs.shape, gpDir);
            const shape = proj.Shape();
            shapes.push(shape);
            gpDir.delete();
            proj.delete();
        });
        return shapes;
    }
    createWireFromTwoCirclesTan(inputs) {
        return this.och.wiresService.createWireFromTwoCirclesTan(inputs);
    }
}
