All files / lib/services/base edges.service.ts

98.43% Statements 629/639
87.06% Branches 101/116
100% Functions 52/52
98.39% Lines 613/623

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920                                                                49x 49x 49x 503x 503x 503x   503x 503x 503x 485x 485x 485x 485x 485x 485x 485x 485x           49x 49x   49x       80x       20x       21x     21x     21x 21x 21x 307x   21x       25x 25x 355x     25x       12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       828x 828x 828x 828x 828x 828x 828x 828x 828x 828x 828x 828x 828x 828x 828x       983x 983x 983x 983x 983x 983x       1x     3x         1x     2x       7x 7x 7x 6x 1x 1x       7x   7x 28x     7x 28x 28x 28x 28x               28x 28x 28x 711x   711x         711x   28x 711x 28x 28x 28x     7x 28x 28x 28x 10x     7x       479x 479x 479x 479x 479x 479x       384x 384x 384x 384x 384x 384x       3x 3x 3x 3x 3x 3x 3x 3x       1x 1x 1x 1x 1x 1x 1x 1x       7x 7x   7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x   7x 7x 7x 7x 7x 7x 7x   7x 7x 7x 7x   7x 7x   7x 7x   7x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x   7x   7x   7x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x   7x   7x 7x 1x 6x 3x 3x 2x   1x     7x     4x 2x 1x 1x 1x 1x 1x   2x 2x 1x 1x 1x 1x 1x       4x 4x     7x       6x 6x   6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x   6x   6x 6x 3x 3x 1x 2x 1x   1x     6x     3x 1x 1x 2x 2x 2x   3x 3x     6x       99x 99x   99x 99x 99x 99x 99x 99x 99x 99x 99x   99x 99x   99x 99x   99x 99x   99x 99x   99x 99x   99x 99x   99x 99x 372x 372x   99x   99x 99x 372x 372x   99x     99x 88x 11x 10x   99x 99x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x 372x     99x   99x 1x 98x 8x 90x 78x 12x 2x 10x 8x   2x     99x         94x 79x 77x 77x 2x 2x 2x   79x 79x 15x 5x 3x 3x 2x 2x 2x   5x 5x 10x   6x 4x 4x 2x 2x 2x   6x 6x 4x   4x 2x 2x 2x 2x 2x   4x 4x     94x 94x   94x 94x     99x       3x 3x   3x   3x 3x 3x 3x 3x 3x 3x   3x   3x   3x   3x   3x   3x   3x 3x 6x 6x   3x   3x 3x 6x 6x 6x     3x       9x 9x 9x 9x 9x 9x 9x 9x       6x 6x   6x 6x 6x   6x 6x   6x 6x   6x 6x   6x 6x   6x   6x 6x   6x 6x 24x 24x   6x   6x 6x 24x 24x 24x     6x       16x 16x 16x 16x 16x 16x 16x       3x 3x 3x 3x 3x 3x 3x       50x 50x 50x 50x 50x 50x 50x 50x 50x       30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x       196x 196x 196x 196x 196x 196x 196x 196x 196x 196x 196x 196x 196x 196x         131x 131x 131x 131x 131x 131x 131x 131x       161x 161x 161x 161x 161x 161x       10x 10x 10x 10x       500x 500x 500x 500x 500x               226x 226x 226x 226x 226x 226x 226x 226x 226x 226x 226x 226x 226x 226x                 28x 28x 28x 28x 28x 28x 28x 28x       4x 4x 4x 4x 4x 4x 4x       2x 2x 2x 2x 2x 2x 2x       78x 78x 78x 78x         80x 80x 80x 40x 40x   40x         20x 20x 20x 10x 10x   10x                  
import {
    Geom2d_Curve, Geom_Surface, OpenCascadeInstance,
    TopoDS_Edge, TopoDS_Shape, TopoDS_Wire, gp_Circ2d
} from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
import * as Inputs from "../../api/inputs/inputs";
import { Base } from "../../api/inputs/base-inputs";
import { VectorHelperService } from "../../api/vector-helper.service";
import { ConverterService } from "./converter.service";
import { EntitiesService } from "./entities.service";
import { OCCReferencedReturns } from "../../occ-referenced-returns";
import { ShapeGettersService } from "./shape-getters";
import { IteratorService } from "./iterator.service";
import { EnumService } from "./enum.service";
import { GeomService } from "./geom.service";
import { TransformsService } from "./transforms.service";
 
export class EdgesService {
 
    constructor(
        private readonly occ: OpenCascadeInstance,
        private readonly occRefReturns: OCCReferencedReturns,
        private readonly shapeGettersService: ShapeGettersService,
        private readonly entitiesService: EntitiesService,
        private readonly iteratorService: IteratorService,
        private readonly converterService: ConverterService,
        private readonly enumService: EnumService,
        private readonly geomService: GeomService,
        private readonly transformsService: TransformsService,
        private readonly vecHelper: VectorHelperService
    ) { }
 
    getCornerPointsOfEdgesForShape(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Inputs.Base.Point3[] {
        const edges = this.shapeGettersService.getEdges(inputs);
        let points: Inputs.Base.Point3[] = [];
        edges.forEach((edge) => {
            const param1 = { current: 0 };
            const param2 = { current: 0 };
            const crvHandle = this.occRefReturns.BRep_Tool_Curve_2(edge, param1, param2);
 
            try {
                const crv = crvHandle.get();
                if (crv) {
                    const pt1 = crv.Value(param1.current);
                    const pt2 = crv.Value(param2.current);
                    const pt1g: Inputs.Base.Point3 = [pt1.X(), pt1.Y(), pt1.Z()];
                    const pt2g: Inputs.Base.Point3 = [pt2.X(), pt2.Y(), pt2.Z()];
                    pt1.delete();
                    pt2.delete();
                    points.push(pt1g);
                    points.push(pt2g);
                }
            } catch (ex) {
                console.log(ex);
            }
        });
        Eif (points.length > 0) {
            points = this.vecHelper.removeAllDuplicateVectors(points) as Inputs.Base.Point3[];
        }
        return points;
    }
 
    getCircularEdgesAlongWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Edge[] {
        return this.getEdgesAlongWire(inputs).filter(edge => this.isEdgeCircular({ shape: edge }));
    }
 
    getLinearEdgesAlongWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Edge[] {
        return this.getEdgesAlongWire(inputs).filter(edge => this.isEdgeLinear({ shape: edge }));
    }
 
    getEdgesAlongWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Edge[] {
        Iif (inputs.shape && this.enumService.getShapeTypeEnum(inputs.shape) === Inputs.OCCT.shapeTypeEnum.edge) {
            return [inputs.shape];
        }
        Iif (!inputs.shape || inputs.shape.IsNull()) {
            throw (new Error("Shape is not provided or is of incorrect type"));
        }
        const edges: TopoDS_Edge[] = [];
        const wireWithFixedEdges = this.fixEdgeOrientationsAlongWire(inputs);
        this.iteratorService.forEachEdgeAlongWire(wireWithFixedEdges, (i, edge) => {
            edges.push(edge);
        });
        return edges;
    }
 
    fixEdgeOrientationsAlongWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
        const edges = [];
        this.iteratorService.forEachEdgeAlongWire(inputs.shape, (i, edge) => {
            edges.push(edge);
        });
        // rebuilding wire from edges along wire fixes edge directions
        return this.converterService.combineEdgesAndWiresIntoAWire({ shapes: edges });
    }
 
    arcThroughThreePoints(inputs: Inputs.OCCT.ArcEdgeThreePointsDto) {
        const gpPnt1 = this.entitiesService.gpPnt(inputs.start);
        const gpPnt2 = this.entitiesService.gpPnt(inputs.middle);
        const gpPnt3 = this.entitiesService.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;
    }
 
    arcThroughTwoPointsAndTangent(inputs: Inputs.OCCT.ArcEdgeTwoPointsTangentDto) {
        const gpPnt1 = this.entitiesService.gpPnt(inputs.start);
        const gpVec = this.entitiesService.gpVec(inputs.tangentVec);
        const gpPnt2 = this.entitiesService.gpPnt(inputs.end);
        const segment = new this.occ.GC_MakeArcOfCircle_5(gpPnt1, gpVec, gpPnt2);
        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();
        gpVec.delete();
        gpPnt2.delete();
        segment.delete();
        hcurve.delete();
        makeEdge.delete();
        return shape;
    }
 
    arcFromCircleAndTwoAngles(inputs: Inputs.OCCT.ArcEdgeCircleTwoAnglesDto<TopoDS_Edge>) {
        const circle = this.getGpCircleFromEdge({ shape: inputs.circle });
        const radAlpha1 = this.vecHelper.degToRad(inputs.alphaAngle1);
        const radAlpha2 = this.vecHelper.degToRad(inputs.alphaAngle2);
        const arc = new this.occ.GC_MakeArcOfCircle_1(circle, radAlpha1, radAlpha2, inputs.sense);
        const hcurve = new this.occ.Handle_Geom_Curve_2(arc.Value().get());
        const makeEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(hcurve);
        const shape = makeEdge.Edge();
        circle.delete();
        arc.delete();
        hcurve.delete();
        makeEdge.delete();
        return shape;
    }
 
    arcFromCirclePointAndAngle(inputs: Inputs.OCCT.ArcEdgeCirclePointAngleDto<TopoDS_Edge>) {
        const circle = this.getGpCircleFromEdge({ shape: inputs.circle });
        const radAlpha = this.vecHelper.degToRad(inputs.alphaAngle);
        const point = this.entitiesService.gpPnt(inputs.point);
        const arc = new this.occ.GC_MakeArcOfCircle_2(circle, point, radAlpha, inputs.sense);
        const hcurve = new this.occ.Handle_Geom_Curve_2(arc.Value().get());
        const makeEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(hcurve);
        const shape = makeEdge.Edge();
        circle.delete();
        arc.delete();
        point.delete();
        hcurve.delete();
        makeEdge.delete();
        return shape;
    }
 
    lineEdge(inputs: Inputs.OCCT.LineDto) {
        const gpPnt1 = this.entitiesService.gpPnt(inputs.start);
        const gpPnt2 = this.entitiesService.gpPnt(inputs.end);
        const segment = new this.occ.GC_MakeSegment_1(gpPnt1, gpPnt2);
        const segVal = segment.Value();
        const seg = segVal.get();
        const hcurve = new this.occ.Handle_Geom_Curve_2(seg);
        const edgeMaker = new this.occ.BRepBuilderAPI_MakeEdge_24(hcurve);
        const edge = edgeMaker.Edge();
        edgeMaker.delete();
        hcurve.delete();
        gpPnt1.delete();
        gpPnt2.delete();
        segVal.delete();
        seg.delete();
        return edge;
    }
 
    getEdgeLength(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
        const edge = inputs.shape;
        const gprops = new this.occ.GProp_GProps_1();
        this.occ.BRepGProp.LinearProperties(edge, gprops, false, false);
        const mass = gprops.Mass();
        gprops.delete();
        return mass;
    }
 
    getEdgesLengths(inputs: Inputs.OCCT.ShapesDto<TopoDS_Edge>): number[] {
        Iif (inputs.shapes === undefined) {
            throw (Error(("Shapes are not defined")));
        }
        return inputs.shapes.map(edge => this.getEdgeLength({ shape: edge }));
    }
 
 
    getEdgesCentersOfMass(inputs: Inputs.OCCT.ShapesDto<TopoDS_Edge>): Base.Point3[] {
        Iif (inputs.shapes === undefined) {
            throw (Error(("Shapes are not defined")));
        }
        return inputs.shapes.map(edge => this.geomService.getLinearCenterOfMass({ shape: edge }));
    }
 
    edgesToPoints(inputs: Inputs.OCCT.EdgesToPointsDto<TopoDS_Shape>): Inputs.Base.Point3[][] {
        const shapeType = this.enumService.getShapeTypeEnum(inputs.shape);
        let edges = [];
        if (shapeType === Inputs.OCCT.shapeTypeEnum.edge) {
            edges = [inputs.shape];
        } else if (shapeType === Inputs.OCCT.shapeTypeEnum.wire) {
            edges = this.getEdgesAlongWire({ shape: inputs.shape });
        } else E{
            edges = this.shapeGettersService.getEdges({ shape: inputs.shape });
        }
        const allEdgePoints: Base.Point3[][] = [];
        // collect original start points to adjust edge directions later
        const edgeStartPoints = edges.map(e => {
            return this.startPointOnEdge({ shape: e });
        });
        // this messes up directions as curve that is being built picks up some default direction
        edges.forEach((myEdge) => {
            const edgePoints: Base.Point3[] = [];
            const aLocation = new this.occ.TopLoc_Location_1();
            const adaptorCurve = new this.occ.BRepAdaptor_Curve_2(myEdge);
            const tangDef = new this.occ.GCPnts_TangentialDeflection_2(
                adaptorCurve,
                inputs.angularDeflection,
                inputs.curvatureDeflection,
                inputs.minimumOfPoints,
                inputs.uTolerance,
                inputs.minimumLength
            );
            const nrPoints = tangDef.NbPoints();
            const tangDefValues = [];
            for (let j = 0; j < nrPoints; j++) {
                const tangDefVal = tangDef.Value(j + 1);
 
                edgePoints.push([
                    tangDefVal.X(),
                    tangDefVal.Y(),
                    tangDefVal.Z()
                ] as Base.Point3);
                tangDefValues.push(tangDefVal);
            }
            allEdgePoints.push(edgePoints);
            tangDefValues.forEach(v => v.delete());
            aLocation.delete();
            adaptorCurve.delete();
            tangDef.delete();
        });
        // this fixes the directions of the point arrays based on original start points
        allEdgePoints.forEach((ep, index) => {
            const distBetweenStarts = this.vecHelper.distanceBetweenPoints(ep[0], edgeStartPoints[index]);
            const distBetweenStartAndEnd = this.vecHelper.distanceBetweenPoints(edgeStartPoints[index], ep[ep.length - 1]);
            if (distBetweenStartAndEnd < distBetweenStarts) {
                ep.reverse();
            }
        });
        return allEdgePoints;
    }
 
    startPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Base.Point3 {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const pt = this.geomService.pointOnCurveAtParam({ shape: curve, param: 0 });
        curve.delete();
        return pt;
    }
 
    endPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Base.Point3 {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const pt = this.geomService.pointOnCurveAtParam({ shape: curve, param: 1 });
        curve.delete();
        return pt;
    }
 
    makeEdgeFromGeom2dCurveAndSurfaceBounded(inputs: Inputs.OCCT.CurveAndSurfaceDto<Geom2d_Curve, Geom_Surface>, umin: number, umax: number): TopoDS_Edge {
        const curve2d = new this.occ.Handle_Geom2d_Curve_2(inputs.curve as Geom2d_Curve);
        const surface = new this.occ.Handle_Geom_Surface_2(inputs.surface as Geom_Surface);
        const res = new this.occ.BRepBuilderAPI_MakeEdge_31(curve2d, surface, umin, umax);
        const resShape = res.Shape();
        const r = this.converterService.getActualTypeOfShape(resShape);
        resShape.delete();
        res.delete();
        return r;
    }
 
    makeEdgeFromGeom2dCurveAndSurface(inputs: Inputs.OCCT.CurveAndSurfaceDto<Geom2d_Curve, Geom_Surface>): TopoDS_Edge {
        const curve2d = new this.occ.Handle_Geom2d_Curve_2(inputs.curve as Geom2d_Curve);
        const surface = new this.occ.Handle_Geom_Surface_2(inputs.surface as Geom_Surface);
        const res = new this.occ.BRepBuilderAPI_MakeEdge_30(curve2d, surface);
        const resShape = res.Shape();
        const r = this.converterService.getActualTypeOfShape(resShape);
        resShape.delete();
        res.delete();
        return r;
    }
 
    constraintTanLinesFromTwoPtsToCircle(inputs: Inputs.OCCT.ConstraintTanLinesFromTwoPtsToCircleDto<TopoDS_Edge>): TopoDS_Shape[] {
        const cirDir = this.getCircularEdgePlaneDirection({ shape: inputs.circle });
        const cirPos = this.getCircularEdgeCenterPoint({ shape: inputs.circle });
 
        const alignOpt = new Inputs.OCCT.AlignDto<TopoDS_Shape>();
        alignOpt.fromDirection = cirDir;
        alignOpt.toDirection = [0, 0, 1];
        alignOpt.fromOrigin = cirPos;
        alignOpt.toOrigin = [0, 0, 0];
        alignOpt.shape = inputs.circle;
        const circleAligned = this.transformsService.align(alignOpt);
        const ptVertex1 = this.entitiesService.makeVertex(inputs.point1);
        alignOpt.shape = ptVertex1;
        const ptVertex1Aligned = this.transformsService.align(alignOpt);
        ptVertex1.delete();
        const pt1Aligned = this.converterService.vertexToPoint({ shape: ptVertex1Aligned });
        ptVertex1Aligned.delete();
        const pt2d1 = this.entitiesService.gpPnt2d([pt1Aligned[0], pt1Aligned[1]]);
 
        const ptVertex2 = this.entitiesService.makeVertex(inputs.point2);
        alignOpt.shape = ptVertex2;
        const ptVertex2Aligned = this.transformsService.align(alignOpt);
        ptVertex2.delete();
        const pt2Aligned = this.converterService.vertexToPoint({ shape: ptVertex2Aligned });
        ptVertex2Aligned.delete();
        const pt2d2 = this.entitiesService.gpPnt2d([pt2Aligned[0], pt2Aligned[1]]);
 
        const circle = this.getGpCircle2dFromEdge({ shape: circleAligned });
        circleAligned.delete();
        const qCircle = new this.occ.GccEnt_QualifiedCirc(circle, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
        circle.delete();
 
        const lin1 = new this.occ.GccAna_Lin2d2Tan_2(qCircle, pt2d1, inputs.tolerance);
        const lin2 = new this.occ.GccAna_Lin2d2Tan_2(qCircle, pt2d2, inputs.tolerance);
 
        qCircle.delete();
        const solutions1 = [];
 
        for (let i = 1; i <= lin1.NbSolutions(); i++) {
            const sol = lin1.ThisSolution(i);
            const location = sol.Location();
            const edgeLine = this.lineEdge({ start: [location.X(), location.Y(), 0], end: pt1Aligned });
            alignOpt.fromDirection = [0, 0, 1];
            alignOpt.toDirection = cirDir;
            alignOpt.fromOrigin = [0, 0, 0];
            alignOpt.toOrigin = cirPos;
            alignOpt.shape = edgeLine;
            const aligned = this.transformsService.align(alignOpt);
            solutions1.push(aligned);
            sol.delete();
            location.delete();
            edgeLine.delete();
        }
        lin1.delete();
 
        const solutions2 = [];
 
        for (let i = 1; i <= lin2.NbSolutions(); i++) {
            const sol = lin2.ThisSolution(i);
            const location = sol.Location();
            const edgeLine = this.lineEdge({ start: [location.X(), location.Y(), 0], end: pt2Aligned });
            alignOpt.fromDirection = [0, 0, 1];
            alignOpt.toDirection = cirDir;
            alignOpt.fromOrigin = [0, 0, 0];
            alignOpt.toOrigin = cirPos;
            alignOpt.shape = edgeLine;
            const aligned = this.transformsService.align(alignOpt);
            solutions2.push(aligned);
            sol.delete();
            location.delete();
            edgeLine.delete();
        }
        lin2.delete();
 
        let resultingSol = [];
        if (inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
            resultingSol = [...solutions1, ...solutions2];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
            resultingSol = [solutions1[1], solutions2[0]];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2) {
            resultingSol = [solutions1[0], solutions2[1]];
        } else {
            resultingSol = [...solutions1, ...solutions2];
        }
 
        if (resultingSol.length === 2 && inputs.circleRemainder !== Inputs.OCCT.circleInclusionEnum.none) {
            let startPoint;
            let endPoint;
            if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2) {
                if (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide1) {
                    startPoint = this.startPointOnEdge({ shape: resultingSol[1] });
                    endPoint = this.startPointOnEdge({ shape: resultingSol[0] });
                } else Eif (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide2) {
                    startPoint = this.startPointOnEdge({ shape: resultingSol[0] });
                    endPoint = this.startPointOnEdge({ shape: resultingSol[1] });
                }
            } else Eif (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
                if (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide1) {
                    startPoint = this.startPointOnEdge({ shape: resultingSol[0] });
                    endPoint = this.startPointOnEdge({ shape: resultingSol[1] });
                } else Eif (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide2) {
                    startPoint = this.startPointOnEdge({ shape: resultingSol[1] });
                    endPoint = this.startPointOnEdge({ shape: resultingSol[0] });
                }
            }
 
            const edge = this.arcFromCircleAndTwoPoints({ circle: inputs.circle, start: startPoint, end: endPoint, sense: true });
            resultingSol.splice(1, 0, edge);
        }
 
        return resultingSol;
    }
 
    constraintTanLinesFromPtToCircle(inputs: Inputs.OCCT.ConstraintTanLinesFromPtToCircleDto<TopoDS_Edge>): TopoDS_Shape[] {
        const cirDir = this.getCircularEdgePlaneDirection({ shape: inputs.circle });
        const cirPos = this.getCircularEdgeCenterPoint({ shape: inputs.circle });
 
        const alignOpt = new Inputs.OCCT.AlignDto<TopoDS_Shape>();
        alignOpt.fromDirection = cirDir;
        alignOpt.toDirection = [0, 0, 1];
        alignOpt.fromOrigin = cirPos;
        alignOpt.toOrigin = [0, 0, 0];
        alignOpt.shape = inputs.circle;
        const circleAligned = this.transformsService.align(alignOpt);
        const ptVertex = this.entitiesService.makeVertex(inputs.point);
        alignOpt.shape = ptVertex;
        const ptVertexAligned = this.transformsService.align(alignOpt);
        ptVertex.delete();
        const ptAligned = this.converterService.vertexToPoint({ shape: ptVertexAligned });
        ptVertexAligned.delete();
        const pt2d = this.entitiesService.gpPnt2d([ptAligned[0], ptAligned[1]]);
        const circle = this.getGpCircle2dFromEdge({ shape: circleAligned });
        circleAligned.delete();
        const qCircle = new this.occ.GccEnt_QualifiedCirc(circle, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
        circle.delete();
        const lin = new this.occ.GccAna_Lin2d2Tan_2(qCircle, pt2d, inputs.tolerance);
        qCircle.delete();
        const solutions = [];
        for (let i = 1; i <= lin.NbSolutions(); i++) {
            const sol = lin.ThisSolution(i);
            const location = sol.Location();
            const edgeLine = this.lineEdge({ start: [location.X(), location.Y(), 0], end: ptAligned });
            alignOpt.fromDirection = [0, 0, 1];
            alignOpt.toDirection = cirDir;
            alignOpt.fromOrigin = [0, 0, 0];
            alignOpt.toOrigin = cirPos;
            alignOpt.shape = edgeLine;
            const aligned = this.transformsService.align(alignOpt);
            solutions.push(aligned);
            sol.delete();
            location.delete();
            edgeLine.delete();
        }
        lin.delete();
 
        let resultingSol = [];
        if (inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
            resultingSol = [...solutions];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
            resultingSol = [solutions[0]];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2) {
            resultingSol = [solutions[1]];
        } else {
            resultingSol = [...solutions];
        }
 
        if (resultingSol.length === 2 && inputs.circleRemainder !== Inputs.OCCT.circleInclusionEnum.none) {
            let startPoint;
            let endPoint;
            if (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide1) {
                startPoint = this.startPointOnEdge({ shape: resultingSol[1] });
                endPoint = this.startPointOnEdge({ shape: resultingSol[0] });
            } else Eif (inputs.circleRemainder === Inputs.OCCT.circleInclusionEnum.keepSide2) {
                startPoint = this.startPointOnEdge({ shape: resultingSol[0] });
                endPoint = this.startPointOnEdge({ shape: resultingSol[1] });
            }
            const edge = this.arcFromCircleAndTwoPoints({ circle: inputs.circle, start: startPoint, end: endPoint, sense: true });
            resultingSol.splice(1, 0, edge);
        }
 
        return resultingSol;
    }
 
    constraintTanLinesOnTwoCircles(inputs: Inputs.OCCT.ConstraintTanLinesOnTwoCirclesDto<TopoDS_Edge>): TopoDS_Shape[] {
        const cirDir = this.getCircularEdgePlaneDirection({ shape: inputs.circle1 });
        const cirPos = this.getCircularEdgeCenterPoint({ shape: inputs.circle1 });
 
        const alignOpt = new Inputs.OCCT.AlignDto<TopoDS_Shape>();
        alignOpt.fromDirection = cirDir;
        alignOpt.toDirection = [0, 0, 1];
        alignOpt.fromOrigin = cirPos;
        alignOpt.toOrigin = [0, 0, 0];
        alignOpt.shape = inputs.circle1;
        const circle1Aligned = this.transformsService.align(alignOpt);
        alignOpt.shape = inputs.circle2;
        const circle2Aligned = this.transformsService.align(alignOpt);
 
        const circle1 = this.getGpCircle2dFromEdge({ shape: circle1Aligned });
        const circle2 = this.getGpCircle2dFromEdge({ shape: circle2Aligned });
 
        circle1Aligned.delete();
        circle2Aligned.delete();
 
        const qCircle1 = new this.occ.GccEnt_QualifiedCirc(circle1, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
        const qCircle2 = new this.occ.GccEnt_QualifiedCirc(circle2, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
 
        circle1.delete();
        circle2.delete();
 
        const lin1 = new this.occ.GccAna_Lin2d2Tan_3(qCircle1, qCircle2, inputs.tolerance);
        const lin2 = new this.occ.GccAna_Lin2d2Tan_3(qCircle2, qCircle1, inputs.tolerance);
 
        qCircle1.delete();
        qCircle2.delete();
 
        const lin1Sols = [];
        for (let i = 1; i <= lin1.NbSolutions(); i++) {
            const sol = lin1.ThisSolution(i);
            lin1Sols.push(sol);
        }
        lin1.delete();
 
        const lin2Sols = [];
        for (let i = 1; i <= lin2.NbSolutions(); i++) {
            const sol = lin2.ThisSolution(i);
            lin2Sols.push(sol);
        }
        lin2.delete();
 
        let adjustLin2Sol;
        if (lin2Sols.length === 4) {
            adjustLin2Sol = [lin2Sols[2], lin2Sols[1], lin2Sols[0], lin2Sols[3]];
        } else if (lin2Sols.length === 2) {
            adjustLin2Sol = [lin2Sols[1], lin2Sols[0]];
        }
        const solutions = [];
        for (let i = 0; i < lin1Sols.length; i++) {
            const sol1 = lin1Sols[i];
            const sol2 = adjustLin2Sol[i];
            const locationStart = sol1.Location();
            const startPoint = [locationStart.X(), locationStart.Y(), 0] as Inputs.Base.Point3;
            const locationEnd = sol2.Location();
            const endPoint = [locationEnd.X(), locationEnd.Y(), 0] as Inputs.Base.Point3;
            const edgeLine = this.lineEdge({ start: startPoint, end: endPoint });
            alignOpt.fromDirection = [0, 0, 1];
            alignOpt.toDirection = cirDir;
            alignOpt.fromOrigin = [0, 0, 0];
            alignOpt.toOrigin = cirPos;
            alignOpt.shape = edgeLine;
            const aligned = this.transformsService.align(alignOpt);
            solutions.push(aligned);
            edgeLine.delete();
            sol1.delete();
            sol2.delete();
            locationStart.delete();
            locationEnd.delete();
        }
 
        let resultingSol = [];
 
        if (inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
            resultingSol = [...solutions];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1 && solutions.length === 4) {
            resultingSol = [solutions[1], solutions[3]];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 && solutions.length === 4) {
            resultingSol = [solutions[0], solutions[2]];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1 && solutions.length === 2) {
            resultingSol = [];
        } else if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 && solutions.length === 2) {
            resultingSol = [solutions[0], solutions[1]];
        } else {
            resultingSol = [...solutions];
        }
 
        if (resultingSol.length === 2 && inputs.circleRemainders !== Inputs.OCCT.twoCircleInclusionEnum.none) {
            let startPoint1;
            let startPoint2;
            let endPoint1;
            let endPoint2;
            if (inputs.circleRemainders === Inputs.OCCT.twoCircleInclusionEnum.outside) {
                if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 || inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[1] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[0] });
                } else Eif (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[0] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[1] });
                }
                endPoint1 = this.endPointOnEdge({ shape: resultingSol[0] });
                endPoint2 = this.endPointOnEdge({ shape: resultingSol[1] });
            } else if (inputs.circleRemainders === Inputs.OCCT.twoCircleInclusionEnum.inside) {
                if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 || inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[0] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[1] });
                } else Eif (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[1] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[0] });
                }
                endPoint1 = this.endPointOnEdge({ shape: resultingSol[1] });
                endPoint2 = this.endPointOnEdge({ shape: resultingSol[0] });
            } else if (inputs.circleRemainders === Inputs.OCCT.twoCircleInclusionEnum.insideOutside) {
 
                if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 || inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[0] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[1] });
                } else Eif (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[1] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[0] });
                }
                endPoint1 = this.endPointOnEdge({ shape: resultingSol[0] });
                endPoint2 = this.endPointOnEdge({ shape: resultingSol[1] });
            } else Eif (inputs.circleRemainders === Inputs.OCCT.twoCircleInclusionEnum.outsideInside) {
 
                if (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide2 || inputs.positionResult === Inputs.OCCT.positionResultEnum.all) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[1] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[0] });
                } else Eif (inputs.positionResult === Inputs.OCCT.positionResultEnum.keepSide1) {
                    startPoint1 = this.startPointOnEdge({ shape: resultingSol[0] });
                    startPoint2 = this.startPointOnEdge({ shape: resultingSol[1] });
                }
                endPoint1 = this.endPointOnEdge({ shape: resultingSol[1] });
                endPoint2 = this.endPointOnEdge({ shape: resultingSol[0] });
            }
 
            const edge1 = this.arcFromCircleAndTwoPoints({ circle: inputs.circle1, start: startPoint1, end: startPoint2, sense: true });
            const edge2 = this.arcFromCircleAndTwoPoints({ circle: inputs.circle2, start: endPoint1, end: endPoint2, sense: true });
 
            resultingSol.unshift(edge1);
            resultingSol.push(edge2);
        }
 
        return resultingSol;
    }
 
    constraintTanCirclesOnCircleAndPnt(inputs: Inputs.OCCT.ConstraintTanCirclesOnCircleAndPntDto<TopoDS_Edge>): TopoDS_Shape[] {
        const cirDir = this.getCircularEdgePlaneDirection({ shape: inputs.circle });
        const cirPos = this.getCircularEdgeCenterPoint({ shape: inputs.circle });
 
        const { alignOpt, circle1Aligned: circleAligned } = this.alignCircle(cirDir, cirPos, inputs.circle);
 
        const ptVertex = this.entitiesService.makeVertex(inputs.point);
        alignOpt.shape = ptVertex;
        const ptVertexAligned = this.transformsService.align(alignOpt);
        ptVertex.delete();
        const ptAligned = this.converterService.vertexToPoint({ shape: ptVertexAligned });
        ptVertexAligned.delete();
        const pt2d = this.entitiesService.gpPnt2d([ptAligned[0], ptAligned[1]]);
 
        const circle = this.getGpCircle2dFromEdge({ shape: circleAligned });
 
        circleAligned.delete();
 
        const qCircle = new this.occ.GccEnt_QualifiedCirc(circle, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
 
        circle.delete();
 
        const lin1 = new this.occ.GccAna_Circ2d2TanRad_3(qCircle, pt2d, inputs.radius, inputs.tolerance);
 
        qCircle.delete();
 
        const lin1Sols: gp_Circ2d[] = [];
        for (let i = 1; i <= lin1.NbSolutions(); i++) {
            const sol = lin1.ThisSolution(i);
            lin1Sols.push(sol);
        }
        lin1.delete();
 
        const solutions = [];
        for (let i = 0; i < lin1Sols.length; i++) {
            const sol = lin1Sols[i];
            const res = this.reconstructCircleAndAlignBack(lin1Sols, sol, alignOpt, cirDir, cirPos);
            solutions.push(res);
        }
 
        return solutions;
    }
 
    private alignCircle(cirDir: Base.Vector3, cirPos: Base.Point3, circle: TopoDS_Edge) {
        const alignOpt = new Inputs.OCCT.AlignDto<TopoDS_Shape>();
        alignOpt.fromDirection = cirDir;
        alignOpt.toDirection = [0, 0, 1];
        alignOpt.fromOrigin = cirPos;
        alignOpt.toOrigin = [0, 0, 0];
        alignOpt.shape = circle;
        const circle1Aligned = this.transformsService.align(alignOpt);
        return { alignOpt, circle1Aligned };
    }
 
    constraintTanCirclesOnTwoCircles(inputs: Inputs.OCCT.ConstraintTanCirclesOnTwoCirclesDto<TopoDS_Edge>): TopoDS_Shape[] {
        const cirDir = this.getCircularEdgePlaneDirection({ shape: inputs.circle1 });
        const cirPos = this.getCircularEdgeCenterPoint({ shape: inputs.circle1 });
 
        const { alignOpt, circle1Aligned } = this.alignCircle(cirDir, cirPos, inputs.circle1);
        alignOpt.shape = inputs.circle2;
        const circle2Aligned = this.transformsService.align(alignOpt);
 
        const circle1 = this.getGpCircle2dFromEdge({ shape: circle1Aligned });
        const circle2 = this.getGpCircle2dFromEdge({ shape: circle2Aligned });
 
        circle1Aligned.delete();
        circle2Aligned.delete();
 
        const qCircle1 = new this.occ.GccEnt_QualifiedCirc(circle1, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
        const qCircle2 = new this.occ.GccEnt_QualifiedCirc(circle2, this.enumService.getGccEntPositionFromEnum(Inputs.OCCT.gccEntPositionEnum.unqualified));
 
        circle1.delete();
        circle2.delete();
 
        const lin1 = new this.occ.GccAna_Circ2d2TanRad_1(qCircle1, qCircle2, inputs.radius, inputs.tolerance);
 
        qCircle1.delete();
        qCircle2.delete();
 
        const lin1Sols: gp_Circ2d[] = [];
        for (let i = 1; i <= lin1.NbSolutions(); i++) {
            const sol = lin1.ThisSolution(i);
            lin1Sols.push(sol);
        }
        lin1.delete();
 
        const solutions = [];
        for (let i = 0; i < lin1Sols.length; i++) {
            const sol = lin1Sols[i];
            const res = this.reconstructCircleAndAlignBack(lin1Sols, sol, alignOpt, cirDir, cirPos);
            solutions.push(res);
        }
 
        return solutions;
    }
 
    divideEdgeByParamsToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Edge>): Inputs.Base.Point3[] {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const points = this.geomService.divideCurveToNrSegments({ ...inputs, shape: curve }, curve.FirstParameter(), curve.LastParameter());
        curve.delete();
        wire.delete();
        return points;
    }
 
    divideEdgeByEqualDistanceToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Edge>): Base.Point3[] {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const points = this.geomService.divideCurveByEqualLengthDistance({ ...inputs, shape: curve });
        curve.delete();
        wire.delete();
        return points;
    }
 
    pointOnEdgeAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Edge>): Base.Point3 {
        const edge = inputs.shape;
        const { uMin, uMax } = this.getEdgeBounds(edge);
        const curve = this.converterService.getGeomCurveFromEdge(edge, uMin, uMax);
        const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
        const param = this.vecHelper.remap(inputs.param, 0, 1, uMin, uMax);
        curve.D0(param, gpPnt);
        const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
        gpPnt.delete();
        return pt;
    }
 
    private reconstructCircleAndAlignBack(lin1Sols: gp_Circ2d[], sol: gp_Circ2d, alignOpt: Inputs.OCCT.AlignDto<TopoDS_Shape>, dir: Base.Vector3, pos: Base.Point3) {
        const locationStart = sol.Location();
        const startPoint = [locationStart.X(), locationStart.Y(), 0] as Inputs.Base.Point3;
        const circle = this.entitiesService.createCircle(sol.Radius(), startPoint, [0, 0, 1], Inputs.OCCT.typeSpecificityEnum.edge) as TopoDS_Edge;
        alignOpt.fromDirection = [0, 0, 1];
        alignOpt.toDirection = dir;
        alignOpt.fromOrigin = [0, 0, 0];
        alignOpt.toOrigin = pos;
        alignOpt.shape = circle;
        const aligned = this.transformsService.align(alignOpt);
        circle.delete();
        sol.delete();
        locationStart.delete();
        return aligned;
    }
 
    arcFromCircleAndTwoPoints(inputs: Inputs.OCCT.ArcEdgeCircleTwoPointsDto<TopoDS_Edge>) {
        const circle = this.getGpCircleFromEdge({ shape: inputs.circle });
        const gpPnt1 = this.entitiesService.gpPnt(inputs.start);
        const gpPnt2 = this.entitiesService.gpPnt(inputs.end);
        const arc = new this.occ.GC_MakeArcOfCircle_3(circle, gpPnt1, gpPnt2, inputs.sense);
        const hcurve = new this.occ.Handle_Geom_Curve_2(arc.Value().get());
        const makeEdge = new this.occ.BRepBuilderAPI_MakeEdge_24(hcurve);
        const shape = makeEdge.Edge();
        circle.delete();
        gpPnt1.delete();
        gpPnt2.delete();
        arc.delete();
        hcurve.delete();
        makeEdge.delete();
        return shape;
    }
 
 
    getCircularEdgePlaneDirection(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Inputs.Base.Vector3 {
        const circle = this.getGpCircleFromEdge(inputs);
        const axis = circle.Position();
        const dir = axis.Direction();
        const result = [dir.X(), dir.Y(), dir.Z()] as Inputs.Base.Vector3;
        dir.delete();
        axis.delete();
        circle.delete();
        return result;
    }
 
    getCircularEdgeCenterPoint(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Inputs.Base.Point3 {
        const circle = this.getGpCircleFromEdge(inputs);
        const location = circle.Location();
        const result = [location.X(), location.Y(), location.Z()] as Inputs.Base.Point3;
        location.delete();
        circle.delete();
        return result;
    }
 
    getCircularEdgeRadius(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): number {
        const circle = this.getGpCircleFromEdge(inputs);
        const radius = circle.Radius();
        circle.delete();
        return radius;
    }
 
    private getGpCircleFromEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
        const curve = new this.occ.BRepAdaptor_Curve_2(inputs.shape);
        try {
            const circle = curve.Circle();
            curve.delete();
            return circle;
        } catch (ex) {
            curve.delete();
            throw new Error("Edge is not a circular edge.");
        }
    }
 
    getGpCircle2dFromEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
        const curve = new this.occ.BRepAdaptor_Curve_2(inputs.shape);
        try {
            const circle = curve.Circle();
            const ax = circle.Position();
            const location = circle.Location();
            const ax2d = this.entitiesService.gpAx2d([location.X(), location.Y()], [1, 0]);
            const radius = circle.Radius();
            const circle2d = new this.occ.gp_Circ2d_2(ax2d, radius, true);
            curve.delete();
            circle.delete();
            ax.delete();
            location.delete();
            ax2d.delete();
            return circle2d;
        } catch (ex) {
            curve.delete();
            throw new Error("Edge is not a circular edge.");
        }
    }
 
 
    tangentOnEdgeAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Edge>): Base.Vector3 {
        const edge = inputs.shape;
        const { uMin, uMax } = this.getEdgeBounds(edge);
        const curve = this.converterService.getGeomCurveFromEdge(edge, uMin, uMax);
        const param = this.vecHelper.remap(inputs.param, 0, 1, uMin, uMax);
        const vec = curve.DN(param, 1);
        const vector: Base.Vector3 = [vec.X(), vec.Y(), vec.Z()];
        vec.delete();
        return vector;
    }
 
    pointOnEdgeAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Edge>): Base.Point3 {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const res = this.geomService.pointOnCurveAtLength({ ...inputs, shape: curve });
        curve.delete();
        wire.delete();
        return res;
    }
 
    tangentOnEdgeAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Edge>): Base.Point3 {
        const edge = inputs.shape;
        const wire = this.converterService.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
        const res = this.geomService.tangentOnCurveAtLength({ ...inputs, shape: curve });
        wire.delete();
        curve.delete();
        return res;
    }
 
    getEdgeBounds(edge: TopoDS_Edge): { uMin: number, uMax: number } {
        const p1 = { current: 0 };
        const p2 = { current: 0 };
        this.occRefReturns.BRep_Tool_Range_1(edge, p1, p2);
        return { uMin: p1.current, uMax: p2.current };
    }
 
 
    private isEdgeCircular(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
        const curve = new this.occ.BRepAdaptor_Curve_2(inputs.shape);
        try {
            curve.Circle();
            curve.delete();
            return true;
        } catch (ex) {
            return false;
        }
    }
 
    private isEdgeLinear(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
        const curve = new this.occ.BRepAdaptor_Curve_2(inputs.shape);
        try {
            curve.Line();
            curve.delete();
            return true;
        } catch (ex) {
            return false;
        }
    }
 
 
 
 
 
}