All files / lib/services/shapes wire.ts

100% Statements 157/157
100% Branches 2/2
100% Functions 75/75
100% Lines 140/140

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                          5x       4x 2x       11x       4x 2x       10x       6x 2x       35x       4x 2x       18x       4x 2x       12x       6x       1x       5x       8x       4x 2x       3x       23x       2x       16x       2x       2x       3x       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       3x       3x       143x       29x       11x       19x       1x       3x       6x       1x       6x       5x       10x       23x       194x       1x       2x       2x           3x 3x 3x 3x 3x       1x 1x 1x 22x   1x 1x 1x 22x 1x       1x 1x 1x 1x 1x       1x 1x 1x 2x 1x       3x 3x 3x 3x 3x 1x   2x 2x 2x 2x       1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x   1x       1x 1x 2x 2x 2x 2x 2x 2x     1x       9x      
import { TopoDS_Face, OpenCascadeInstance, TopoDS_Wire, TopoDS_Compound, TopoDS_Shape, TopoDS_Edge } from "../../../bitbybit-dev-occt/bitbybit-dev-occt";
import { OccHelper } from "../../occ-helper";
import * as Inputs from "../../api/inputs/inputs";
 
export class OCCTWire {
 
    constructor(
        private readonly occ: OpenCascadeInstance,
        private readonly och: OccHelper
    ) {
    }
 
    createPolygonWire(inputs: Inputs.OCCT.PolygonDto): TopoDS_Wire {
        return this.och.wiresService.createPolygonWire(inputs);
    }
 
    createPolygons(inputs: Inputs.OCCT.PolygonsDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.polygons.map(p => this.createPolygonWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    createPolylineWire(inputs: Inputs.OCCT.PolylineDto): TopoDS_Wire {
        return this.och.wiresService.createPolylineWire(inputs);
    }
 
    createPolylines(inputs: Inputs.OCCT.PolylinesDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.polylines.map(p => this.createPolylineWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    createLineWire(inputs: Inputs.OCCT.LineDto): TopoDS_Wire {
        return this.och.wiresService.createLineWire(inputs);
    }
 
    createLines(inputs: Inputs.OCCT.LinesDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.lines.map(p => this.createLineWire(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    createBezier(inputs: Inputs.OCCT.BezierDto) {
        return this.och.wiresService.createBezier(inputs);
    }
 
    createBezierWires(inputs: Inputs.OCCT.BezierWiresDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.bezierWires.map(p => this.createBezier(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    interpolatePoints(inputs: Inputs.OCCT.InterpolationDto): TopoDS_Wire {
        return this.och.wiresService.interpolatePoints(inputs);
    }
 
    interpolateWires(inputs: Inputs.OCCT.InterpolateWiresDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.interpolations.map(p => this.interpolatePoints(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    splitOnPoints(inputs: Inputs.OCCT.SplitWireOnPointsDto<TopoDS_Wire>): TopoDS_Wire[] {
        return this.och.wiresService.splitOnPoints(inputs);
    }
 
    combineEdgesAndWiresIntoAWire(inputs: Inputs.OCCT.ShapesDto<TopoDS_Wire | TopoDS_Edge>): TopoDS_Wire {
        return this.och.converterService.combineEdgesAndWiresIntoAWire(inputs);
    }
 
    createWireFromEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): TopoDS_Wire {
        return this.och.wiresService.createWireFromEdges(inputs);
    }
 
    addEdgesAndWiresToWire(inputs: Inputs.OCCT.ShapeShapesDto<TopoDS_Wire, TopoDS_Wire | TopoDS_Edge>): TopoDS_Wire {
        return this.och.wiresService.addEdgesAndWiresToWire(inputs);
    }
 
    createBSpline(inputs: Inputs.OCCT.BSplineDto): TopoDS_Wire {
        return this.och.wiresService.createBSpline(inputs);
    }
 
    createBSplines(inputs: Inputs.OCCT.BSplinesDto): TopoDS_Wire[] | TopoDS_Compound {
        const wires = inputs.bSplines.map(p => this.createBSpline(p)).filter(s => s !== undefined);
        return this.och.converterService.makeCompoundIfNeeded(wires, inputs.returnCompound);
    }
 
    createZigZagBetweenTwoWires(inputs: Inputs.OCCT.ZigZagBetweenTwoWiresDto<TopoDS_Wire>): TopoDS_Wire {
        return this.och.wiresService.createZigZagBetweenTwoWires(inputs);
    }
 
    divideWireByParamsToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Wire>): Inputs.Base.Point3[] {
        return this.och.wiresService.divideWireByParamsToPoints(inputs);
    }
 
    divideWiresByParamsToPoints(inputs: Inputs.OCCT.DivideShapesDto<TopoDS_Wire>): Inputs.Base.Point3[][] {
        return inputs.shapes.map(s => this.divideWireByParamsToPoints({ ...inputs, shape: s }));
    }
 
    divideWireByEqualDistanceToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Wire>): Inputs.Base.Point3[] {
        return this.och.wiresService.divideWireByEqualDistanceToPoints(inputs);
    }
 
    divideWiresByEqualDistanceToPoints(inputs: Inputs.OCCT.DivideShapesDto<TopoDS_Wire>): Inputs.Base.Point3[][] {
        return inputs.shapes.map(s => this.divideWireByEqualDistanceToPoints({ ...inputs, shape: s }));
    }
 
    pointOnWireAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.pointOnWireAtParam(inputs);
    }
 
    pointOnWireAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.pointOnWireAtLength(inputs);
    }
 
    tangentOnWireAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.tangentOnWireAtParam(inputs);
    }
 
    tangentOnWireAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.tangentOnWireAtLength(inputs);
    }
 
    derivativesOnWireAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Wire>): [Inputs.Base.Vector3, Inputs.Base.Vector3, Inputs.Base.Vector3] {
        const wire = inputs.shape;
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
 
        const absc = new this.occ.GCPnts_AbscissaPoint_2(curve, inputs.length, curve.FirstParameter());
        const param = absc.Parameter();
        const gpPnt = this.och.entitiesService.gpPnt([0, 0, 0]);
 
        const der1 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der2 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der3 = this.och.entitiesService.gpVec([0, 0, 0]);
 
        curve.D3(param, gpPnt, der1, der2, der3);
        const der: [Inputs.Base.Vector3, Inputs.Base.Vector3, Inputs.Base.Vector3] = [[der1.X(), der1.Y(), der1.Z()], [der2.X(), der2.Y(), der2.Z()], [der3.X(), der3.Y(), der3.Z()]];
        der1.delete();
        der2.delete();
        der3.delete();
        curve.delete();
        absc.delete();
        gpPnt.delete();
        return der;
    }
 
    derivativesOnWireAtParam(inputs: Inputs.OCCT.DataOnGeometryAtParamDto<TopoDS_Wire>): [Inputs.Base.Vector3, Inputs.Base.Vector3, Inputs.Base.Vector3] {
        const wire = inputs.shape;
        const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
 
        const gpPnt = this.och.entitiesService.gpPnt([0, 0, 0]);
 
        const der1 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der2 = this.och.entitiesService.gpVec([0, 0, 0]);
        const der3 = this.och.entitiesService.gpVec([0, 0, 0]);
 
        const param = this.och.vecHelper.remap(inputs.param, 0, 1, curve.FirstParameter(), curve.LastParameter());
 
        curve.D3(param, gpPnt, der1, der2, der3);
        const der: [Inputs.Base.Vector3, Inputs.Base.Vector3, Inputs.Base.Vector3] = [[der1.X(), der1.Y(), der1.Z()], [der2.X(), der2.Y(), der2.Z()], [der3.X(), der3.Y(), der3.Z()]];
        der1.delete();
        der2.delete();
        der3.delete();
        curve.delete();
        gpPnt.delete();
        return der;
    }
 
    startPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.startPointOnWire(inputs);
    }
 
    endPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.endPointOnWire(inputs);
    }
 
    createCircleWire(inputs: Inputs.OCCT.CircleDto) {
        return this.och.entitiesService.createCircle(inputs.radius, inputs.center, inputs.direction, Inputs.OCCT.typeSpecificityEnum.wire) as TopoDS_Wire;
    }
 
    createEllipseWire(inputs: Inputs.OCCT.EllipseDto) {
        return this.och.entitiesService.createEllipse(inputs.radiusMinor, inputs.radiusMajor, inputs.center, inputs.direction, Inputs.OCCT.typeSpecificityEnum.wire) as TopoDS_Wire;
    }
 
    createSquareWire(inputs: Inputs.OCCT.SquareDto): TopoDS_Wire {
        return this.och.wiresService.createSquareWire(inputs);
    }
 
    createStarWire(inputs: Inputs.OCCT.StarDto): TopoDS_Wire {
        return this.och.wiresService.createStarWire(inputs);
    }
 
    createChristmasTreeWire(inputs: Inputs.OCCT.ChristmasTreeDto): TopoDS_Wire {
        return this.och.wiresService.createChristmasTreeWire(inputs);
    }
 
    createParallelogramWire(inputs: Inputs.OCCT.ParallelogramDto): TopoDS_Wire {
        return this.och.wiresService.createParallelogramWire(inputs);
    }
 
    createHeartWire(inputs: Inputs.OCCT.Heart2DDto): TopoDS_Wire {
        return this.och.wiresService.createHeartWire(inputs);
    }
 
    createNGonWire(inputs: Inputs.OCCT.NGonWireDto): TopoDS_Wire {
        return this.och.wiresService.createNGonWire(inputs);
    }
 
    createRectangleWire(inputs: Inputs.OCCT.RectangleDto): TopoDS_Wire {
        return this.och.wiresService.createRectangleWire(inputs);
    }
 
    createLPolygonWire(inputs: Inputs.OCCT.LPolygonDto): TopoDS_Wire {
        return this.och.wiresService.createLPolygonWire(inputs);
    }
 
    getWire(inputs: Inputs.OCCT.ShapeIndexDto<TopoDS_Shape>): TopoDS_Wire {
        return this.och.shapeGettersService.getWire(inputs);
    }
 
    getWires(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): TopoDS_Wire[] {
        return this.och.shapeGettersService.getWires(inputs);
    }
 
    getWireLength(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): number {
        return this.och.wiresService.getWireLength(inputs);
    }
 
    getWiresLengths(inputs: Inputs.OCCT.ShapesDto<TopoDS_Wire>): number[] {
        return this.och.wiresService.getWiresLengths(inputs);
    }
 
    getWireCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Inputs.Base.Point3 {
        return this.och.wiresService.getWireCenterOfMass(inputs);
    }
 
    getWiresCentersOfMass(inputs: Inputs.OCCT.ShapesDto<TopoDS_Wire>): Inputs.Base.Point3[] {
        return inputs.shapes.map(w => this.och.wiresService.getWireCenterOfMass({
            shape: w
        }));
    }
 
    reversedWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
        const wire: TopoDS_Wire = inputs.shape;
        const reversed = wire.Reversed();
        const result = this.och.converterService.getActualTypeOfShape(reversed);
        reversed.delete();
        return result;
    }
 
    reversedWireFromReversedEdges(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
        const wire: TopoDS_Wire = inputs.shape;
        const edges = this.och.edgesService.getEdgesAlongWire({ shape: wire });
        const reversedEdges = edges.map(e => {
            return this.och.converterService.getActualTypeOfShape(e.Reversed());
        });
        const reversed = this.och.converterService.combineEdgesAndWiresIntoAWire({ shapes: reversedEdges.reverse() });
        const result = this.och.converterService.getActualTypeOfShape(reversed);
        reversed.delete();
        reversedEdges.forEach(e => e.delete());
        return result;
    }
 
    placeWireOnFace(inputs: Inputs.OCCT.WireOnFaceDto<TopoDS_Wire, TopoDS_Face>) {
        const wire = inputs.wire as TopoDS_Wire;
        const face = inputs.face as TopoDS_Face;
        const srf = this.och.surfaceFromFace({ shape: face });
        const result = this.och.wiresService.placeWire(wire, srf);
        return result;
    }
 
    placeWiresOnFace(inputs: Inputs.OCCT.WiresOnFaceDto<TopoDS_Wire, TopoDS_Face>) {
        const wires = inputs.wires;
        const face = inputs.face;
        const srf = this.och.surfaceFromFace({ shape: face });
        const result = wires.map(wire => this.och.wiresService.placeWire(wire, srf));
        return result;
    }
 
    closeOpenWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): TopoDS_Wire {
        const wire = inputs.shape;
        const firstPoint = this.och.wiresService.startPointOnWire({ shape: wire });
        const lastPoint = this.och.wiresService.endPointOnWire({ shape: wire });
        const tolerance = 1.0e-7;
        if (this.och.vecHelper.vectorsTheSame(firstPoint, lastPoint, tolerance)) {
            return wire;
        }
        const edgeWire = this.createLineWire({ start: lastPoint, end: firstPoint });
        const result = this.addEdgesAndWiresToWire({ shape: wire, shapes: [edgeWire] });
        edgeWire.delete();
        return result;
    }
 
    project(inputs: Inputs.OCCT.ProjectWireDto<TopoDS_Wire, TopoDS_Shape>): TopoDS_Compound {
        const wire = inputs.wire;
        const gpDir = this.och.entitiesService.gpDir(inputs.direction);
        const proj = new this.occ.BRepProj_Projection_1(wire, inputs.shape, gpDir);
        const shape = proj.Shape();
        gpDir.delete();
        proj.delete();
        return shape;
    }
 
    wiresToPoints(inputs: Inputs.OCCT.WiresToPointsDto<TopoDS_Shape>): Inputs.Base.Point3[][] {
        const wires = this.getWires({ shape: inputs.shape });
        const allWirePoints = [];
        wires.forEach(w => {
            const edgePoints = this.och.edgesService.edgesToPoints({ ...inputs, shape: w });
            const flatPoints = edgePoints.flat();
            const dupsRemoved = this.och.vecHelper.removeConsecutiveDuplicates(flatPoints, false);
            allWirePoints.push(dupsRemoved);
        });
        return allWirePoints;
    }
 
    projectWires(inputs: Inputs.OCCT.ProjectWiresDto<TopoDS_Wire, TopoDS_Shape>): TopoDS_Compound[] {
        const shapes = [];
        inputs.wires.forEach(wire => {
            const gpDir = this.och.entitiesService.gpDir(inputs.direction);
            const proj = new this.occ.BRepProj_Projection_1(wire, inputs.shape, gpDir);
            const shape = proj.Shape();
            shapes.push(shape);
            gpDir.delete();
            proj.delete();
        });
 
        return shapes;
    }
 
    createWireFromTwoCirclesTan(inputs: Inputs.OCCT.WireFromTwoCirclesTanDto<TopoDS_Wire>): TopoDS_Wire {
        return this.och.wiresService.createWireFromTwoCirclesTan(inputs);
    }
}