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

90.15% Statements 678/752
79.13% Branches 220/278
95.58% Functions 65/68
89.78% Lines 633/705

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 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244                                                                  41x 41x       1x 1x         83x 1x   82x 80x 80x 80x   2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x 2x 2x   2x 2x     2x 2x 2x     82x           141x 141x 141x 141x 141x       6x     28x       3x 3x 3x 3x 3x 3x 3x       1x     2x       9x 9x 8x 8x 82x 82x 82x 82x 82x 8x   82x 18x   82x 17x   82x     82x   8x 8x   1x           568x 568x 568x 568x       37x 37x 37x 37x       6x 6x 6x 3x 7x 8x             7x 7x     3x 1x 3x             3x 3x   2x 2x 8x             8x 8x       5x 4x   1x   5x       6x   6x 6x 1x   3x 3x 3x 2x 6x 18x 18x 18x             18x 18x       1x     5x 2x 5x 1x     1x 2x 8x             8x 8x     3x   3x 8x 1x     2x 4x 12x             12x 12x     2x 6x 18x             18x 18x         4x 3x   1x   4x       197x     197x 197x 197x 197x 197x 197x 197x 197x 83x   197x 197x 197x 197x       498x 498x 498x 498x 498x 498x       3x 3x       6x 6x       4x 24x   4x       2x 2x       2x         1x 1x       1x         21x 21x 21x       21x 21x 21x       21x 21x 21x       21x 21x 21x       2x     2x 2x 2x 2x 2x   2x 9x 9x 9x   9x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x   58x 58x 7x 51x 7x 44x 1x 43x 1x   58x 42x   58x     2x 2x       15x     15x 15x 15x 15x 15x   15x 15x   15x 15x   15x 58x 58x 58x 58x 58x 236x 236x 236x 236x 236x 236x 236x 236x 236x     15x 15x       3x     3x 3x 3x 3x   3x 3x 3x 18x 18x     3x 1x   3x 1x     3x             3x 3x 16x 16x 16x   3x 3x       4x     4x 4x 4x 4x 4x   4x 4x 4x   4x 9x 9x     4x 4x 4x   4x 40x 40x       4x       4x         4x 4x 4x 4x   4x 4x   4x 4x 4x 4x 4x       4x   4x 9x   90x 90x 60x 60x 60x 50x       90x 90x 60x 60x 60x 50x     90x 90x               90x 90x               90x   90x 90x 90x 90x 90x         95x 90x   90x 85x       85x 85x   5x             5x                                                                 5x         5x       5x 5x 5x 5x             5x   4x         2x     2x     2x 2x 2x 2x   40x 2x 2x     2x 2x   2x 2x         2x 2x 1x 20x   1x         40x 2x 40x   2x         4x     4x 4x 4x 4x 4x     4x 4x   4x           4x 4x   4x 4x   4x           4x                             4x 90x       4x     4x     4x 90x         4x     4x         4x   4x 4x 4x 4x     4x 4x           4x 9x 90x     90x 90x 40x 40x     90x 90x 40x 40x     90x 90x         90x 90x         90x 90x 90x   90x   90x 90x                   90x   90x 90x 40x         40x 40x       90x 90x           4x 220x     4x       2x 2x   2x 2x   2x 2x 2x 2x   40x 2x 2x     2x 2x   2x 2x         2x 2x 1x 20x   1x         40x 2x 40x   2x       2x     2x 2x 2x 2x   2x 2x   2x 2x   2x 7x 7x 7x 7x 7x 18x 18x 18x 18x 18x 18x 18x   18x     18x 18x 18x 18x     2x 2x       2x     2x 2x 2x 2x 2x 2x 2x       23x     23x 15x 15x         8x 8x           23x 23x 23x       2x     2x 2x 2x 2x   2x 2x 5x 5x 5x   2x 2x       4x     4x 4x 4x 4x 4x 4x 4x   4x   4x 2x   2x   4x   18x 9x 9x 9x 9x   9x 9x 9x 9x   18x 18x 9x   9x   18x 18x 18x   4x 4x       5x     5x 5x 5x 5x 5x   5x 5x 3x   2x   5x   24x 14x 14x 14x 14x   10x 10x 10x 10x     24x 14x   10x   24x   5x       3x     3x 3x   3x   3x 3x   3x 3x   3x 13x 13x 13x 13x 13x 54x 54x 54x 54x 54x     3x       1x     1x 1x 1x 1x 1x       1x     1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x   1x       1x     1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x   1x 1x       168x     168x 168x 168x 168x 168x 168x 168x 168x 168x 168x 168x 168x 168x             187x       1x 1x 1x 1x        
import { GeomAbs_Shape, Geom_Surface, OpenCascadeInstance, TopoDS_Face, TopoDS_Shape, TopoDS_Wire } from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
import * as Inputs from "../../api/inputs/inputs";
import { Base } from "../../api/inputs/inputs";
import { OCCReferencedReturns } from "../../occ-referenced-returns";
import { ShapeGettersService } from "./shape-getters";
import { EntitiesService } from "./entities.service";
import { EnumService } from "./enum.service";
import { WiresService } from "./wires.service";
import { BooleansService } from "./booleans.service";
import { ConverterService } from "./converter.service";
import { FilletsService } from "./fillets.service";
import { TransformsService } from "./transforms.service";
import { VectorHelperService } from "../../api";
import { BaseBitByBit } from "../../base";
 
export class FacesService {
 
    constructor(
        private readonly occ: OpenCascadeInstance,
        private readonly occRefReturns: OCCReferencedReturns,
        private readonly entitiesService: EntitiesService,
        private readonly enumService: EnumService,
        private readonly shapeGettersService: ShapeGettersService,
        private readonly converterService: ConverterService,
        public booleansService: BooleansService,
        private readonly wiresService: WiresService,
        private readonly transformsService: TransformsService,
        private readonly vectorService: VectorHelperService,
        private readonly base: BaseBitByBit,
        public filletsService: FilletsService,
    ) { }
 
    createFaceFromWireOnFace(inputs: Inputs.OCCT.FaceFromWireOnFaceDto<TopoDS_Wire, TopoDS_Face>): TopoDS_Face {
        const result = this.entitiesService.bRepBuilderAPIMakeFaceFromWireOnFace(inputs.face, inputs.wire, inputs.inside);
        return result;
    }
 
    createFacesFromWiresOnFace(inputs: Inputs.OCCT.FacesFromWiresOnFaceDto<TopoDS_Wire, TopoDS_Face>): TopoDS_Face[] {
        const result = this.entitiesService.bRepBuilderAPIMakeFacesFromWiresOnFace(inputs.face, inputs.wires, inputs.inside);
        return result;
    }
 
    createFaceFromWire(inputs: Inputs.OCCT.FaceFromWireDto<TopoDS_Wire>): TopoDS_Face {
        let result: TopoDS_Face;
        if (this.enumService.getShapeTypeEnum(inputs.shape) !== Inputs.OCCT.shapeTypeEnum.wire) {
            throw new Error("Provided input shape is not a wire");
        }
        if (inputs.planar) {
            const wire = this.occ.TopoDS.Wire_1(inputs.shape);
            result = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, inputs.planar);
            wire.delete();
        } else {
            const Degree = 3;
            const NbPtsOnCur = 15;
            const NbIter = 2;
            const Anisotropie = false;
            const Tol2d = 0.00001;
            const Tol3d = 0.0001;
            const TolAng = 0.01;
            const TolCurv = 0.1;
            const MaxDeg = 8;
            const MaxSegments = 9;
 
            const bs = new this.occ.BRepFill_Filling(Degree, NbPtsOnCur, NbIter, Anisotropie, Tol2d, Tol3d, TolAng, TolCurv, MaxDeg, MaxSegments);
            const edges = this.shapeGettersService.getEdges(inputs);
            edges.forEach(e => {
                bs.Add_1(e, this.occ.GeomAbs_Shape.GeomAbs_C0 as GeomAbs_Shape, true);
            });
            bs.Build();
            Iif (!bs.IsDone()) {
                throw new Error("Could not create non planar face");
            }
            result = bs.Face();
            bs.delete();
            edges.forEach(e => e.delete());
        }
 
        return result;
    }
 
 
 
    getFaceArea(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): number {
        const gprops = new this.occ.GProp_GProps_1();
        this.occ.BRepGProp.SurfaceProperties_1(inputs.shape, gprops, false, false);
        const area = gprops.Mass();
        gprops.delete();
        return area;
    }
 
    getFacesAreas(inputs: Inputs.OCCT.ShapesDto<TopoDS_Face>): number[] {
        Iif (inputs.shapes === undefined) {
            throw (Error(("Shapes are not defined")));
        }
        return inputs.shapes.map(face => this.getFaceArea({ shape: face }));
    }
 
    getFaceCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): Base.Point3 {
        const gprops = new this.occ.GProp_GProps_1();
        this.occ.BRepGProp.SurfaceProperties_1(inputs.shape, gprops, false, false);
        const gppnt = gprops.CentreOfMass();
        const pt: Base.Point3 = [gppnt.X(), gppnt.Y(), gppnt.Z()];
        gprops.delete();
        gppnt.delete();
        return pt;
    }
 
    getFacesCentersOfMass(inputs: Inputs.OCCT.ShapesDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shapes === undefined) {
            throw (Error(("Shapes are not defined")));
        }
        return inputs.shapes.map(face => this.getFaceCenterOfMass({ shape: face }));
    }
 
    filterFacePoints(inputs: Inputs.OCCT.FilterFacePointsDto<TopoDS_Face>): Base.Point3[] {
        const points = [];
        if (inputs.points.length > 0) {
            const classifier = new this.occ.BRepClass_FaceClassifier_1();
            inputs.points.forEach(pt => {
                const gpPnt = this.entitiesService.gpPnt(pt);
                classifier.Perform_2(inputs.shape, gpPnt, inputs.tolerance, inputs.useBndBox, inputs.gapTolerance);
                const top = classifier.State();
                const type = this.enumService.getTopAbsStateEnum(top);
                if (inputs.keepOn && type === Inputs.OCCT.topAbsStateEnum.on) {
                    points.push(pt);
                }
                if (inputs.keepIn && type === Inputs.OCCT.topAbsStateEnum.in) {
                    points.push(pt);
                }
                if (inputs.keepOut && type === Inputs.OCCT.topAbsStateEnum.out) {
                    points.push(pt);
                }
                Iif (inputs.keepUnknown && type === Inputs.OCCT.topAbsStateEnum.unknown) {
                    points.push(pt);
                }
                gpPnt.delete();
            });
            classifier.delete();
            return points;
        } else {
            return [];
        }
    }
 
 
    createSquareFace(inputs: Inputs.OCCT.SquareDto): TopoDS_Face {
        const squareWire = this.wiresService.createSquareWire(inputs);
        const faceMakerFromWire = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(squareWire, true);
        squareWire.delete();
        return faceMakerFromWire;
    }
 
    createRectangleFace(inputs: Inputs.OCCT.RectangleDto): TopoDS_Face {
        const rectangleWire = this.wiresService.createRectangleWire(inputs);
        const faceMakerFromWire = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(rectangleWire, true);
        rectangleWire.delete();
        return faceMakerFromWire;
    }
 
    createFaceFromMultipleCircleTanWires(inputs: Inputs.OCCT.FaceFromMultipleCircleTanWiresDto<TopoDS_Wire>): TopoDS_Shape {
        const circleWires = inputs.circles;
        const faces: TopoDS_Face[] = [];
        if (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.allWithAll) {
            for (let i = 0; i < circleWires.length; i++) {
                for (let j = i + 1; j < circleWires.length; j++) {
                    const wire = this.wiresService.createWireFromTwoCirclesTan({
                        circle1: circleWires[i],
                        circle2: circleWires[j],
                        keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                        circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                        tolerance: inputs.tolerance,
                    });
                    const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                    faces.push(face);
                }
            }
        } else if (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.inOrder) {
            for (let i = 0; i < circleWires.length - 1; i++) {
                const wire = this.wiresService.createWireFromTwoCirclesTan({
                    circle1: circleWires[i],
                    circle2: circleWires[i + 1],
                    keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                    circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                    tolerance: inputs.tolerance,
                });
                const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                faces.push(face);
            }
        } else Eif (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.inOrderClosed) {
            for (let i = 0; i < circleWires.length; i++) {
                const wire = this.wiresService.createWireFromTwoCirclesTan({
                    circle1: circleWires[i],
                    circle2: circleWires[(i + 1) % circleWires.length],
                    keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                    circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                    tolerance: inputs.tolerance,
                });
                const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                faces.push(face);
            }
        }
        let result;
        if (inputs.unify) {
            result = this.booleansService.union({ shapes: faces, keepEdges: false });
        } else {
            result = this.converterService.makeCompound({ shapes: faces });
        }
        return result;
    }
 
    createFaceFromMultipleCircleTanWireCollections(inputs: Inputs.OCCT.FaceFromMultipleCircleTanWireCollectionsDto<TopoDS_Wire>): TopoDS_Shape {
        const listsOfCircles = inputs.listsOfCircles;
 
        const faces: TopoDS_Face[] = [];
        if (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.allWithAll) {
            for (let i = 0; i < listsOfCircles.length; i++) {
                // lists of circles is a 2D array of circular wires
                const currentCirclesList = listsOfCircles[i];
                const nextCirclesList = listsOfCircles[(i + 1)];
                if (nextCirclesList) {
                    for (let j = 0; j < currentCirclesList.length; j++) {
                        for (let k = 0; k < nextCirclesList.length; k++) {
                            const circle1 = currentCirclesList[j];
                            const circle2 = nextCirclesList[k];
                            const wire = this.wiresService.createWireFromTwoCirclesTan({
                                circle1,
                                circle2,
                                keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                                circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                                tolerance: inputs.tolerance,
                            });
                            const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                            faces.push(face);
                        }
                    }
                } else {
                    break;
                }
            }
        } else if (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.inOrder) {
            for (let i = 0; i < listsOfCircles.length; i++) {
                if (listsOfCircles[i].length !== listsOfCircles[0].length) {
                    throw new Error("All lists of circles must have the same length in order to use inOrder strategy.");
                }
            }
            for (let i = 0; i < listsOfCircles.length - 1; i++) {
                for (let j = 0; j < listsOfCircles[i].length; j++) {
                    const wire = this.wiresService.createWireFromTwoCirclesTan({
                        circle1: listsOfCircles[i][j],
                        circle2: listsOfCircles[i + 1][j],
                        keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                        circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                        tolerance: inputs.tolerance,
                    });
                    const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                    faces.push(face);
                }
            }
        } else Eif (inputs.combination === Inputs.OCCT.combinationCirclesForFaceEnum.inOrderClosed) {
            // check if all lists are of the same length
            for (let i = 0; i < listsOfCircles.length; i++) {
                if (listsOfCircles[i].length !== listsOfCircles[0].length) {
                    throw new Error("All lists of circles must have the same length in order to use inOrderClosed strategy.");
                }
            }
            for (let i = 0; i < listsOfCircles.length - 1; i++) {
                for (let j = 0; j < listsOfCircles[i].length; j++) {
                    const wire = this.wiresService.createWireFromTwoCirclesTan({
                        circle1: listsOfCircles[i][j],
                        circle2: listsOfCircles[i + 1][j],
                        keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                        circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                        tolerance: inputs.tolerance,
                    });
                    const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                    faces.push(face);
                }
            }
            for (let i = 0; i < listsOfCircles.length; i++) {
                for (let j = 0; j < listsOfCircles[i].length; j++) {
                    const wire = this.wiresService.createWireFromTwoCirclesTan({
                        circle1: listsOfCircles[i][j],
                        circle2: listsOfCircles[i][(j + 1) % listsOfCircles[i].length],
                        keepLines: Inputs.OCCT.twoSidesStrictEnum.outside,
                        circleRemainders: Inputs.OCCT.fourSidesStrictEnum.outside,
                        tolerance: inputs.tolerance,
                    });
                    const face = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, true);
                    faces.push(face);
                }
            }
        }
        let result;
        if (inputs.unify) {
            result = this.booleansService.union({ shapes: faces, keepEdges: false });
        } else {
            result = this.converterService.makeCompound({ shapes: faces });
        }
        return result;
    }
 
    faceNormalOnUV(inputs: Inputs.OCCT.DataOnUVDto<TopoDS_Face>): Base.Vector3 {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const u = uMin + (uMax - uMin) * inputs.paramU;
        const v = vMin + (vMax - vMin) * inputs.paramV;
        const gpDir = this.entitiesService.gpDir([0, 1, 0]);
        this.occ.GeomLib.NormEstim(handle, this.entitiesService.gpPnt2d([u, v]), 1e-7, gpDir);
        if (face.Orientation_1() === this.occ.TopAbs_Orientation.TopAbs_REVERSED) {
            gpDir.Reverse();
        }
        const dir: Base.Vector3 = [gpDir.X(), gpDir.Y(), gpDir.Z()];
        gpDir.delete();
        handle.delete();
        return dir;
    }
 
    getUVBounds(face: TopoDS_Face): { uMin: number, uMax: number, vMin: number, vMax: number } {
        const uMin = { current: 0 };
        const uMax = { current: 0 };
        const vMin = { current: 0 };
        const vMax = { current: 0 };
        this.occRefReturns.BRepTools_UVBounds_1(face, uMin, uMax, vMin, vMax);
        return { uMin: uMin.current, uMax: uMax.current, vMin: vMin.current, vMax: vMax.current };
    }
 
    createFaceFromWires(inputs: Inputs.OCCT.FacesFromWiresDto<TopoDS_Wire>): TopoDS_Face {
        const result = this.entitiesService.bRepBuilderAPIMakeFaceFromWires(inputs.shapes, inputs.planar);
        return result;
    }
 
    createFaceFromWiresOnFace(inputs: Inputs.OCCT.FaceFromWiresOnFaceDto<TopoDS_Wire, TopoDS_Face>): TopoDS_Face {
        const result = this.entitiesService.bRepBuilderAPIMakeFaceFromWires(inputs.wires, false, inputs.face, inputs.inside);
        return result;
    }
 
    createFacesFromWires(inputs: Inputs.OCCT.FacesFromWiresDto<TopoDS_Wire>): TopoDS_Face[] {
        const result = inputs.shapes.map(shape => {
            return this.createFaceFromWire({ shape, planar: inputs.planar });
        });
        return result;
    }
 
    faceFromSurface(inputs: Inputs.OCCT.ShapeWithToleranceDto<Geom_Surface>) {
        const face = this.entitiesService.bRepBuilderAPIMakeFaceFromSurface(inputs.shape, inputs.tolerance) as TopoDS_Face;
        Iif (face.IsNull()) {
            face.delete();
            throw new Error("Could not construct a face from the surface. Check if surface is not infinite.");
        } else {
            return face;
        }
    }
 
    faceFromSurfaceAndWire(inputs: Inputs.OCCT.FaceFromSurfaceAndWireDto<Geom_Surface, TopoDS_Wire>) {
        const face = this.entitiesService.bRepBuilderAPIMakeFaceFromSurfaceAndWire(inputs.surface, inputs.wire, inputs.inside) as TopoDS_Face;
        Iif (face.IsNull()) {
            face.delete();
            throw new Error("Could not construct a face from the surface. Check if surface is not infinite.");
        } else {
            return face;
        }
    }
 
    getUMinBound(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): number {
        const face = inputs.shape;
        const { uMin } = this.getUVBounds(face);
        return uMin;
    }
 
    getUMaxBound(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): number {
        const face = inputs.shape;
        const { uMax } = this.getUVBounds(face);
        return uMax;
    }
 
    getVMinBound(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): number {
        const face = inputs.shape;
        const { vMin } = this.getUVBounds(face);
        return vMin;
    }
 
    getVMaxBound(inputs: Inputs.OCCT.ShapeDto<TopoDS_Face>): number {
        const face = inputs.shape;
        const { vMax } = this.getUVBounds(face);
        return vMax;
    }
 
    subdivideToPointsControlled(inputs: Inputs.OCCT.FaceSubdivisionControlledDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const points: Base.Point3[] = [];
 
        for (let i = 0; i < inputs.nrDivisionsU; i++) {
            const stepU = (uMax - uMin) / (inputs.nrDivisionsU - 1);
            const halfStepU = stepU / 2;
            const stepsU = stepU * i;
 
            for (let j = 0; j < inputs.nrDivisionsV; j++) {
                const stepV = (vMax - vMin) / (inputs.nrDivisionsV - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                let v = vMin + stepsV;
                v += (inputs.shiftHalfStepNthV && (i + inputs.shiftHalfStepVOffsetN) % inputs.shiftHalfStepNthV === 0) ? halfStepV : 0;
                let u = uMin + stepsU;
                u += (inputs.shiftHalfStepNthU && (j + inputs.shiftHalfStepUOffsetN) % inputs.shiftHalfStepNthU === 0) ? halfStepU : 0;
                const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
                surface.D0(u, v, gpPnt);
                const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
 
                let shouldPush = true;
                if (i === 0 && inputs.removeStartEdgeNthU && (j + inputs.removeStartEdgeUOffsetN) % inputs.removeStartEdgeNthU === 0) {
                    shouldPush = false;
                } else if (i === inputs.nrDivisionsU - 1 && inputs.removeEndEdgeNthU && (j + inputs.removeEndEdgeUOffsetN) % inputs.removeEndEdgeNthU === 0) {
                    shouldPush = false;
                } else if (j === 0 && inputs.removeStartEdgeNthV && (i + inputs.removeStartEdgeVOffsetN) % inputs.removeStartEdgeNthV === 0) {
                    shouldPush = false;
                } else if (j === inputs.nrDivisionsV - 1 && inputs.removeEndEdgeNthV && (i + inputs.removeEndEdgeVOffsetN) % inputs.removeEndEdgeNthV === 0) {
                    shouldPush = false;
                }
                if (shouldPush) {
                    points.push(pt);
                }
                gpPnt.delete();
            }
        }
        handle.delete();
        return points;
    }
 
    subdivideToPoints(inputs: Inputs.OCCT.FaceSubdivisionDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const points: Base.Point3[] = [];
 
        const uStartRemoval = inputs.removeStartEdgeU ? 1 : 0;
        const uEndRemoval = inputs.removeEndEdgeU ? 1 : 0;
 
        const vStartRemoval = inputs.removeStartEdgeV ? 1 : 0;
        const vEndRemoval = inputs.removeEndEdgeV ? 1 : 0;
 
        for (let i = 0 + uStartRemoval; i < inputs.nrDivisionsU - uEndRemoval; i++) {
            const stepU = (uMax - uMin) / (inputs.nrDivisionsU - 1);
            const halfStepU = stepU / 2;
            const stepsU = stepU * i;
            const u = uMin + (inputs.shiftHalfStepU ? halfStepU : 0) + stepsU;
            for (let j = 0 + vStartRemoval; j < inputs.nrDivisionsV - vEndRemoval; j++) {
                const stepV = (vMax - vMin) / (inputs.nrDivisionsV - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                const v = vMin + (inputs.shiftHalfStepV ? halfStepV : 0) + stepsV;
                const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
                surface.D0(u, v, gpPnt);
                const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
                points.push(pt);
                gpPnt.delete();
            }
        }
        handle.delete();
        return points;
    }
 
    subdivideToWires(inputs: Inputs.OCCT.FaceSubdivisionToWiresDto<TopoDS_Face>): TopoDS_Wire[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
 
        const params = [];
        const step = 1 / inputs.nrDivisions;
        for (let i = 0; i <= inputs.nrDivisions; i++) {
            const p = step * i;
            params.push(p);
        }
 
        if (inputs.removeStart) {
            params.shift();
        }
        if (inputs.removeEnd) {
            params.pop();
        }
 
        Iif (inputs.shiftHalfStep) {
            const halfStep = step / 2;
            params.forEach((p, i) => {
                params[i] = params[i] + halfStep;
            });
        }
 
        const wires: TopoDS_Wire[] = [];
        for (let i = 0; i < params.length; i++) {
            const param = params[i];
            const placedWire = this.placeWireOnParamSurface(inputs.isU, param, uMin, uMax, vMin, vMax, surface);
            wires.push(placedWire);
        }
        handle.delete();
        return wires;
    }
 
    subdivideToRectangleWires(inputs: Inputs.OCCT.FaceSubdivideToRectangleWiresDto<TopoDS_Face>): TopoDS_Wire[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const shapesToDelete = [];
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
 
        const paramsU = [];
        const stepU = (1 - inputs.offsetFromBorderU * 2) / inputs.nrRectanglesU;
        const halfStepU = stepU / 2;
 
        for (let i = 0; i < inputs.nrRectanglesU; i++) {
            const pU = stepU * i + halfStepU + inputs.offsetFromBorderU;
            paramsU.push(pU);
        }
 
        const paramsV = [];
        const stepV = (1 - inputs.offsetFromBorderV * 2) / inputs.nrRectanglesV;
        const halfStepV = stepV / 2;
 
        for (let i = 0; i < inputs.nrRectanglesV; i++) {
            const pV = stepV * i + halfStepV + inputs.offsetFromBorderV;
            paramsV.push(pV);
        }
 
        // figure out actual parametric scale
        const line1 = this.wiresService.createLineWire({
            start: [0, 0, 0],
            end: [1, 0, 0],
        });
        const line2 = this.wiresService.createLineWire({
            start: [0, 0, 0],
            end: [0, 0, 1],
        });
 
        const placedLine1 = this.wiresService.placeWire(line1, surface);
        const placedLine2 = this.wiresService.placeWire(line2, surface);
        const scaleX = this.wiresService.getWireLength({ shape: placedLine1 });
        const scaleZ = this.wiresService.getWireLength({ shape: placedLine2 });
 
        const scaleU = (uMax - uMin);
        const scaleV = (vMax - vMin);
 
        const wires = [];
        let currentScalePatternUIndex = 0;
        let currentScalePatternVIndex = 0;
        let currentInclusionPatternIndex = 0;
        let currentFilletPatternIndex = 0;
 
        // potentially each rectangle can have unique fillets and scale factors due to patterns applied
        // we can though optimise this by using cached rectangles to speed up the algorithm
        const cachedRectangles: { id: string, shape: TopoDS_Wire }[] = [];
 
        for (let i = 0; i < paramsU.length; i++) {
            for (let j = 0; j < paramsV.length; j++) {
 
                let scaleFromPatternU = 1;
                if (inputs.scalePatternU && inputs.scalePatternU.length > 0) {
                    scaleFromPatternU = inputs.scalePatternU[currentScalePatternUIndex];
                    currentScalePatternUIndex++;
                    if (currentScalePatternUIndex >= inputs.scalePatternU.length) {
                        currentScalePatternUIndex = 0;
                    }
                }
 
                let scaleFromPatternV = 1;
                if (inputs.scalePatternV && inputs.scalePatternV.length > 0) {
                    scaleFromPatternV = inputs.scalePatternV[currentScalePatternVIndex];
                    currentScalePatternVIndex++;
                    if (currentScalePatternVIndex >= inputs.scalePatternV.length) {
                        currentScalePatternVIndex = 0;
                    }
                }
                let include = true;
                Iif (inputs.inclusionPattern && inputs.inclusionPattern.length > 0) {
                    include = inputs.inclusionPattern[currentInclusionPatternIndex];
                    currentInclusionPatternIndex++;
                    if (currentInclusionPatternIndex >= inputs.inclusionPattern.length) {
                        currentInclusionPatternIndex = 0;
                    }
                }
 
                let fillet = 0;
                Iif (inputs.filletPattern && inputs.filletPattern.length > 0) {
                    fillet = inputs.filletPattern[currentFilletPatternIndex];
                    currentFilletPatternIndex++;
                    if (currentFilletPatternIndex >= inputs.filletPattern.length) {
                        currentFilletPatternIndex = 0;
                    }
                }
 
                Eif (include) {
 
                    const width = stepV * scaleFromPatternV;
                    const length = stepU * scaleFromPatternU;
                    const minForFillet = Math.min(width * scaleV * scaleX, length * scaleU * scaleZ);
                    if (minForFillet === width * scaleV * scaleX) {
                        fillet = minForFillet / 2 * fillet;
                    } else Eif (minForFillet === length * scaleU * scaleZ) {
                        fillet = minForFillet / 2 * fillet;
                    }
 
                    const useRec = cachedRectangles.find(r => r.id === `${width}-${length}-${fillet}`)?.shape;
                    const translation = [paramsV[j] * scaleV + vMin, 0, paramsU[i] * scaleU + uMin] as Base.Vector3;
 
                    if (useRec) {
                        const translated = this.transformsService.translate({
                            shape: useRec,
                            translation,
                        });
                        const placedRec = this.wiresService.placeWire(translated, surface);
                        wires.push(placedRec);
                    } else {
                        const rectangle = this.wiresService.createRectangleWire({
                            width,
                            length,
                            center: [0, 0, 0],
                            direction: [0, 1, 0],
                        });
 
                        Iif (fillet > 0) {
                            const scaleVec2 = [scaleV * scaleX, 1, scaleU * scaleZ] as Base.Vector3;
                            const scaledRec2 = this.transformsService.scale3d({
                                shape: rectangle,
                                center: [0, 0, 0],
                                scale: scaleVec2,
                            });
 
                            const filletRectangle = this.filletsService.fillet2d({
                                shape: scaledRec2,
                                radius: fillet,
                            });
 
                            const scaleVec3 = [1 / scaleX, 1, 1 / scaleZ] as Base.Vector3;
                            let scaledRec3 = filletRectangle;
                            if (!this.vectorService.vectorsTheSame(scaleVec3, [1, 1, 1], 1e-7)) {
                                scaledRec3 = this.transformsService.scale3d({
                                    shape: filletRectangle,
                                    center: [0, 0, 0],
                                    scale: scaleVec3,
                                });
                            }
 
                            const translated = this.transformsService.translate({
                                shape: scaledRec3,
                                translation,
                            });
                            shapesToDelete.push(rectangle);
 
                            const placedRec = this.wiresService.placeWire(translated, surface);
                            wires.push(placedRec);
                            cachedRectangles.push({ id: `${width}-${length}-${fillet}`, shape: scaledRec3 });
                        } else {
                            const scaledRec = this.transformsService.scale3d({
                                shape: rectangle,
                                center: [0, 0, 0],
                                scale: [scaleV, 1, scaleU],
                            });
                            const translated = this.transformsService.translate({
                                shape: scaledRec,
                                translation,
                            });
                            shapesToDelete.push(rectangle);
                            const placedRec = this.wiresService.placeWire(translated, surface);
                            wires.push(placedRec);
                            cachedRectangles.push({ id: `${width}-${length}-${fillet}`, shape: scaledRec });
                        }
                    }
                }
            }
        }
 
        shapesToDelete.forEach(s => s.delete());
 
        return wires;
    }
 
    subdivideToRectangleHoles(inputs: Inputs.OCCT.FaceSubdivideToRectangleHolesDto<TopoDS_Face>): TopoDS_Face[] {
        // default should be smaller then 1 as that can't punch holes or create faces nicely.
        Iif (inputs.scalePatternU === undefined) {
            inputs.scalePatternU = [0.5];
        }
        Iif (inputs.scalePatternV === undefined) {
            inputs.scalePatternV = [0.5];
        }
        const wires = this.subdivideToRectangleWires(inputs);
        const faceWires = this.shapeGettersService.getWires({ shape: inputs.shape });
        const wireLengths = this.wiresService.getWiresLengths({ shapes: faceWires });
        const longestFaceWire = faceWires[wireLengths.indexOf(Math.max(...wireLengths))];
 
        const revWires = wires.map(wire => { return this.wiresService.reversedWire({ shape: wire }); });
        const listOfWires = [longestFaceWire, ...revWires];
        const newFace = this.createFaceFromWiresOnFace({ wires: listOfWires, face: inputs.shape, inside: true });
 
        // check if the normals are the same, if not reverse the face
        const normalOriginal = this.faceNormalOnUV({ shape: inputs.shape, paramU: 0, paramV: 0 });
        const normalNew = this.faceNormalOnUV({ shape: newFace, paramU: 0, paramV: 0 });
 
        let shouldReverse = false;
        Iif (this.vectorService.angleBetweenVectors(normalOriginal, normalNew) > 1e-7) {
            shouldReverse = true;
            newFace.Reverse();
        }
 
        let faces = [];
        if (inputs.holesToFaces) {
            faces = wires.map(wire => {
                return this.createFaceFromWireOnFace({ wire, face: inputs.shape, inside: true });
            });
            Iif (shouldReverse) {
                faces.forEach(f => f.Reverse());
            }
        }
 
        wires.forEach(w => w.delete());
        longestFaceWire.delete();
        revWires.forEach(w => w.delete());
 
        return [newFace, ...faces];
    }
 
 
    subdivideToHexagonWires(inputs: Inputs.OCCT.FaceSubdivideToHexagonWiresDto<TopoDS_Face>): TopoDS_Wire[] {
        Iif (inputs.shape === undefined) {
            throw new Error("Face not defined");
        }
        const shapesToDelete: TopoDS_Shape[] = [];
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
 
        // Calculate parametric range
        const scaleU = uMax - uMin;
        const scaleV = vMax - vMin;
 
        Iif (scaleU <= 0 || scaleV <= 0) {
            console.warn("Face has zero or negative parametric range. Skipping.");
            return [];
        }
 
        // Calculate target parametric dimensions and origin for the grid
        const gridHeightU = scaleU * (1 - inputs.offsetFromBorderU * 2);
        const gridWidthV = scaleV * (1 - inputs.offsetFromBorderV * 2);
 
        const gridOriginU = uMin + scaleU * inputs.offsetFromBorderU;
        const gridOriginV = vMin + scaleV * inputs.offsetFromBorderV;
 
        Iif (gridHeightU <= 0 || gridWidthV <= 0) {
            console.warn("Grid dimensions are zero or negative after applying offset. Skipping.");
            return [];
        }
 
        // Generate hexagon grid in local 2D space (assuming X maps to V, Z maps to U)
        const hex = this.base.point.hexGridScaledToFit({
            width: gridWidthV,
            height: gridHeightU,
            nrHexagonsInHeight: inputs.nrHexagonsU,
            nrHexagonsInWidth: inputs.nrHexagonsV,
            centerGrid: false,
            pointsOnGround: true,
            flatTop: inputs.flatU,
            extendTop: inputs.extendUUp,
            extendBottom: inputs.extendUBottom,
            extendLeft: inputs.extendVBottom,
            extendRight: inputs.extendVUp,
        });
 
        // Create wires in local 2D space
        const localHexWires = hex.hexagons.map(hexPoints => {
            return this.wiresService.createPolygonWire({
                points: hexPoints
            });
        });
        shapesToDelete.push(...localHexWires);
 
        // Define the translation vector to map local grid origin to parametric grid origin
        const uvTranslation = [gridOriginV, 0, gridOriginU] as Base.Vector3;
 
        // Translate wires to parametric UV space
        const uvHexWires = localHexWires.map(h => {
            return this.transformsService.translate({
                shape: h,
                translation: uvTranslation
            });
        });
        shapesToDelete.push(...uvHexWires);
 
        // Translate centers to parametric UV space
        const uvHexCenters = this.base.point.translatePoints({
            points: hex.centers,
            translation: uvTranslation
        });
 
        const finalPlacedWires = [];
 
        let currentScalePatternUIndex = 0;
        let currentScalePatternVIndex = 0;
        let currentInclusionPatternIndex = 0;
        let currentFilletPatternIndex = 0;
 
        // Ensure we have enough hexagons generated for the loop counts
        const totalHexagons = inputs.nrHexagonsU * inputs.nrHexagonsV;
        Iif (uvHexWires.length !== totalHexagons || uvHexCenters.length !== totalHexagons) {
            console.error(`Generated ${uvHexWires.length} hexagons, but expected ${totalHexagons}. Check hexGridScaledToFit logic.`);
            return [];
        }
 
        // Process each hexagon (scale, fillet, place)
        for (let i = 0; i < inputs.nrHexagonsU; i++) {
            for (let j = 0; j < inputs.nrHexagonsV; j++) {
                const hexIndex = i * inputs.nrHexagonsV + j;
 
                // Get scale/inclusion/fillet values from patterns
                let scaleFromPatternU = 1;
                if (inputs.scalePatternU?.length > 0) {
                    scaleFromPatternU = inputs.scalePatternU[currentScalePatternUIndex % inputs.scalePatternU.length];
                    currentScalePatternUIndex++;
                }
 
                let scaleFromPatternV = 1;
                if (inputs.scalePatternV?.length > 0) {
                    scaleFromPatternV = inputs.scalePatternV[currentScalePatternVIndex % inputs.scalePatternV.length];
                    currentScalePatternVIndex++;
                }
 
                let include = true;
                Iif (inputs.inclusionPattern?.length > 0) {
                    include = inputs.inclusionPattern[currentInclusionPatternIndex % inputs.inclusionPattern.length];
                    currentInclusionPatternIndex++;
                }
 
                let filletFactor = 0;
                Iif (inputs.filletPattern?.length > 0) {
                    filletFactor = inputs.filletPattern[currentFilletPatternIndex % inputs.filletPattern.length];
                    currentFilletPatternIndex++;
                }
 
                Eif (include) {
                    const uvHexagon = uvHexWires[hexIndex];
                    const uvCenter = uvHexCenters[hexIndex];
 
                    let shapeToScale = uvHexagon;
                    // Apply Fillet (using the factor)
                    const filletRadius = hex.maxFilletRadius * filletFactor;
                    Iif (filletRadius > 1e-6) {
                        const filletedHex = this.filletsService.fillet2d({
                            shape: uvHexagon,
                            radius: filletRadius,
                        });
                        shapesToDelete.push(filletedHex);
                        shapeToScale = filletedHex;
                    }
 
                    // Apply Scaling (around the correct UV center)
                    let shapeToPlace = shapeToScale;
                    // Scaling vector maps to V
                    const scaleVec = [scaleFromPatternV, 1, scaleFromPatternU] as Base.Vector3;
                    if (Math.abs(scaleFromPatternU - 1.0) > 1e-6 || Math.abs(scaleFromPatternV - 1.0) > 1e-6) {
                        const scaledHex = this.transformsService.scale3d({
                            shape: shapeToScale,
                            center: uvCenter,
                            scale: scaleVec,
                        });
                        shapesToDelete.push(scaledHex);
                        shapeToPlace = scaledHex;
                    }
 
                    // Place the final processed wire onto the surface
                    const placedWire = this.wiresService.placeWire(shapeToPlace, surface);
                    finalPlacedWires.push(placedWire);
 
                }
            }
        }
 
        shapesToDelete.forEach(s => {
            s.delete();
        });
       
        return finalPlacedWires;
    }
 
    subdivideToHexagonHoles(inputs: Inputs.OCCT.FaceSubdivideToHexagonHolesDto<TopoDS_Face>): TopoDS_Wire[] {
        Eif (inputs.scalePatternU === undefined) {
            inputs.scalePatternU = [0.5];
        }
        Eif (inputs.scalePatternV === undefined) {
            inputs.scalePatternV = [0.5];
        }
        const wires = this.subdivideToHexagonWires(inputs);
        const faceWires = this.shapeGettersService.getWires({ shape: inputs.shape });
        const wireLengths = this.wiresService.getWiresLengths({ shapes: faceWires });
        const longestFaceWire = faceWires[wireLengths.indexOf(Math.max(...wireLengths))];
 
        const revWires = wires.map(wire => { return this.wiresService.reversedWire({ shape: wire }); });
        const listOfWires = [longestFaceWire, ...revWires];
        const newFace = this.createFaceFromWiresOnFace({ wires: listOfWires, face: inputs.shape, inside: true });
 
        // check if the normals are the same, if not reverse the face
        const normalOriginal = this.faceNormalOnUV({ shape: inputs.shape, paramU: 0, paramV: 0 });
        const normalNew = this.faceNormalOnUV({ shape: newFace, paramU: 0, paramV: 0 });
 
        let shouldReverse = false;
        Iif (this.vectorService.angleBetweenVectors(normalOriginal, normalNew) > 1e-7) {
            shouldReverse = true;
            newFace.Reverse();
        }
 
        let faces = [];
        if (inputs.holesToFaces) {
            faces = wires.map(wire => {
                return this.createFaceFromWireOnFace({ wire, face: inputs.shape, inside: true });
            });
            Iif (shouldReverse) {
                faces.forEach(f => f.Reverse());
            }
        }
 
        wires.forEach(w => w.delete());
        longestFaceWire.delete();
        revWires.forEach(w => w.delete());
 
        return [newFace, ...faces];
    }
 
    subdivideToNormals(inputs: Inputs.OCCT.FaceSubdivisionDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const points: Base.Point3[] = [];
 
        const uStartRemoval = inputs.removeStartEdgeU ? 1 : 0;
        const uEndRemoval = inputs.removeEndEdgeU ? 1 : 0;
 
        const vStartRemoval = inputs.removeStartEdgeV ? 1 : 0;
        const vEndRemoval = inputs.removeEndEdgeV ? 1 : 0;
 
        for (let i = 0 + uStartRemoval; i < inputs.nrDivisionsU - uEndRemoval; i++) {
            const stepU = (uMax - uMin) / (inputs.nrDivisionsU - 1);
            const halfStepU = stepU / 2;
            const stepsU = stepU * i;
            const u = uMin + (inputs.shiftHalfStepU ? halfStepU : 0) + stepsU;
            for (let j = 0 + vStartRemoval; j < inputs.nrDivisionsV - vEndRemoval; j++) {
                const stepV = (vMax - vMin) / (inputs.nrDivisionsV - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                const v = vMin + (inputs.shiftHalfStepV ? halfStepV : 0) + stepsV;
                const gpDir = this.entitiesService.gpDir([0, 1, 0]);
                const gpUv = this.entitiesService.gpPnt2d([u, v]);
                this.occ.GeomLib.NormEstim(handle, gpUv, 1e-7, gpDir);
                // Sometimes face gets reversed and its original surface is not reversed, thus we need to adjust for such situation.
                Iif (face.Orientation_1() === this.occ.TopAbs_Orientation.TopAbs_REVERSED) {
                    gpDir.Reverse();
                }
                const pt: Base.Point3 = [gpDir.X(), gpDir.Y(), gpDir.Z()];
                points.push(pt);
                gpDir.delete();
                gpUv.delete();
            }
        }
        handle.delete();
        return points;
    }
 
    wireAlongParam(inputs: Inputs.OCCT.WireAlongParamDto<TopoDS_Face>): TopoDS_Wire {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const placedWire = this.placeWireOnParamSurface(inputs.isU, inputs.param, uMin, uMax, vMin, vMax, surface);
        handle.delete();
        return placedWire;
    }
 
    private placeWireOnParamSurface(isU: boolean, param: number, uMin: number, uMax: number, vMin: number, vMax: number, surface: Geom_Surface) {
        let paramToUse = param;
 
        let wire;
        if (isU) {
            paramToUse = uMin + (uMax - uMin) * param;
            wire = this.wiresService.createLineWire({
                start: [vMin, 0, paramToUse],
                end: [vMax, 0, paramToUse],
            });
        } else {
            paramToUse = vMin + (vMax - vMin) * param;
            wire = this.wiresService.createLineWire({
                start: [paramToUse, 0, uMin],
                end: [paramToUse, 0, uMax],
            });
        }
 
        const placedWire = this.wiresService.placeWire(wire, surface);
        wire.delete();
        return placedWire;
    }
 
    wiresAlongParams(inputs: Inputs.OCCT.WiresAlongParamsDto<TopoDS_Face>): TopoDS_Wire[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
 
        const wires: TopoDS_Wire[] = [];
        for (let i = 0; i < inputs.params.length; i++) {
            const param = inputs.params[i];
            const placedWire = this.placeWireOnParamSurface(inputs.isU, param, uMin, uMax, vMin, vMax, surface);
            wires.push(placedWire);
        }
        handle.delete();
        return wires;
    }
 
    subdivideToPointsOnParam(inputs: Inputs.OCCT.FaceLinearSubdivisionDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const points: Base.Point3[] = [];
        const removeStart = inputs.removeStartPoint ? 1 : 0;
        const removeEnd = inputs.removeEndPoint ? 1 : 0;
 
        let param = inputs.param;
 
        if (inputs.isU) {
            param = uMin + (uMax - uMin) * param;
        } else {
            param = vMin + (vMax - vMin) * param;
        }
        for (let j = 0 + removeStart; j < inputs.nrPoints - removeEnd; j++) {
            let p;
            if (inputs.isU) {
                const stepV = (vMax - vMin) / (inputs.nrPoints - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                p = vMin + (inputs.shiftHalfStep ? halfStepV : 0) + stepsV;
            } else {
                const stepU = (uMax - uMin) / (inputs.nrPoints - 1);
                const halfStepU = stepU / 2;
                const stepsU = stepU * j;
                p = uMin + (inputs.shiftHalfStep ? halfStepU : 0) + stepsU;
            }
            const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
            if (inputs.isU) {
                surface.D0(param, p, gpPnt);
            } else {
                surface.D0(p, param, gpPnt);
            }
            const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
            points.push(pt);
            gpPnt.delete();
        }
        handle.delete();
        return points;
    }
 
    subdivideToUVOnParam(inputs: Inputs.OCCT.FaceLinearSubdivisionDto<TopoDS_Face>): Base.Point2[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const uvs: Base.Point2[] = [];
        const removeStart = inputs.removeStartPoint ? 1 : 0;
        const removeEnd = inputs.removeEndPoint ? 1 : 0;
 
        let param = inputs.param;
        if (inputs.isU) {
            param = uMin + (uMax - uMin) * param;
        } else {
            param = vMin + (vMax - vMin) * param;
        }
        for (let j = 0 + removeStart; j < inputs.nrPoints - removeEnd; j++) {
            let p;
            if (inputs.isU) {
                const stepV = (vMax - vMin) / (inputs.nrPoints - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                p = vMin + (inputs.shiftHalfStep ? halfStepV : 0) + stepsV;
            } else {
                const stepU = (uMax - uMin) / (inputs.nrPoints - 1);
                const halfStepU = stepU / 2;
                const stepsU = stepU * j;
                p = uMin + (inputs.shiftHalfStep ? halfStepU : 0) + stepsU;
            }
            let uv;
            if (inputs.isU) {
                uv = [param, p];
            } else {
                uv = [p, param];
            }
            uvs.push(uv);
        }
        return uvs;
    }
 
    subdivideToUV(inputs: Inputs.OCCT.FaceSubdivisionDto<TopoDS_Face>): Base.Point2[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
 
        const uvs: Base.Point2[] = [];
 
        const uStartRemoval = inputs.removeStartEdgeU ? 1 : 0;
        const uEndRemoval = inputs.removeEndEdgeU ? 1 : 0;
 
        const vStartRemoval = inputs.removeStartEdgeV ? 1 : 0;
        const vEndRemoval = inputs.removeEndEdgeV ? 1 : 0;
 
        for (let i = 0 + uStartRemoval; i < inputs.nrDivisionsU - uEndRemoval; i++) {
            const stepU = (uMax - uMin) / (inputs.nrDivisionsU - 1);
            const halfStepU = stepU / 2;
            const stepsU = stepU * i;
            const u = uMin + (inputs.shiftHalfStepU ? halfStepU : 0) + stepsU;
            for (let j = 0 + vStartRemoval; j < inputs.nrDivisionsV - vEndRemoval; j++) {
                const stepV = (vMax - vMin) / (inputs.nrDivisionsV - 1);
                const halfStepV = stepV / 2;
                const stepsV = stepV * j;
                const v = vMin + (inputs.shiftHalfStepV ? halfStepV : 0) + stepsV;
                uvs.push([u, v]);
            }
        }
        return uvs;
    }
 
    uvOnFace(inputs: Inputs.OCCT.DataOnUVDto<TopoDS_Face>): Base.Point2 {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const u = uMin + (uMax - uMin) * inputs.paramU;
        const v = vMin + (vMax - vMin) * inputs.paramV;
        return [u, v];
    }
 
    pointsOnUVs(inputs: Inputs.OCCT.DataOnUVsDto<TopoDS_Face>): Base.Point3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const pts: Base.Point3[] = inputs.paramsUV.map(uv => {
            const u = uMin + (uMax - uMin) * uv[0];
            const v = vMin + (vMax - vMin) * uv[1];
            const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
            surface.D0(u, v, gpPnt);
            const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
            gpPnt.delete();
            return pt;
        });
        return pts;
    }
 
    normalsOnUVs(inputs: Inputs.OCCT.DataOnUVsDto<TopoDS_Face>): Base.Vector3[] {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
        const nrmls: Base.Vector3[] = inputs.paramsUV.map(uv => {
            const u = uMin + (uMax - uMin) * uv[0];
            const v = vMin + (vMax - vMin) * uv[1];
            const gpDir = this.entitiesService.gpDir([0, 1, 0]);
            this.occ.GeomLib.NormEstim(handle, this.entitiesService.gpPnt2d([u, v]), 1e-7, gpDir);
            const pt = [gpDir.X(), gpDir.Y(), gpDir.Z()];
            gpDir.delete();
            return pt as Base.Vector3;
        });
        handle.delete();
        return nrmls;
    }
 
    pointOnUV(inputs: Inputs.OCCT.DataOnUVDto<TopoDS_Face>): Base.Point3 {
        Iif (inputs.shape === undefined) {
            throw (Error(("Face not defined")));
        }
        const face = inputs.shape;
        const handle = this.occ.BRep_Tool.Surface_2(face);
        const surface = handle.get();
        if (surface) {
            const { uMin, uMax, vMin, vMax } = this.getUVBounds(face);
            const u = uMin + (uMax - uMin) * inputs.paramU;
            const v = vMin + (vMax - vMin) * inputs.paramV;
            const gpPnt = this.entitiesService.gpPnt([0, 0, 0]);
            surface.D0(u, v, gpPnt);
            const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
            gpPnt.delete();
            handle.delete();
            return pt;
        } else E{
            return undefined;
        }
    }
 
    normalOnUV(inputs: Inputs.OCCT.DataOnUVDto<TopoDS_Face>): Base.Vector3 {
        return this.faceNormalOnUV(inputs);
    }
 
    createPolygonFace(inputs: Inputs.OCCT.PolygonDto) {
        const wire = this.wiresService.createPolygonWire(inputs);
        const result = this.entitiesService.bRepBuilderAPIMakeFaceFromWire(wire, false);
        wire.delete();
        return result;
    }
 
}