Skip to content

Commit 2a37035

Browse files
fixed bug for evaluating points on edges, also fixed some object deletions that were causing code to fail after memory management improvements.
1 parent 1937a14 commit 2a37035

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

src/lib/workers/occ/occ-helper.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class OccHelper {
3939
points.push(pt2g);
4040
} catch {
4141
}
42-
crvHandle.delete();
4342
});
4443
if (points.length > 0) {
4544
points = this.vecHelper.removeAllDuplicateVectors(points);
@@ -454,7 +453,6 @@ export class OccHelper {
454453
} else {
455454
const edge = this.bRepBuilderAPIMakeEdge(circle);
456455
if (type === typeSpecificityEnum.edge) {
457-
circle.delete();
458456
return edge;
459457
} else {
460458
const circleWire = this.bRepBuilderAPIMakeWire(edge);
@@ -477,7 +475,6 @@ export class OccHelper {
477475
} else {
478476
const edge = this.bRepBuilderAPIMakeEdge(ellipse);
479477
if (type === typeSpecificityEnum.edge) {
480-
ellipse.delete();
481478
return edge;
482479
} else {
483480
const ellipseWire = this.bRepBuilderAPIMakeWire(edge);
@@ -620,7 +617,8 @@ export class OccHelper {
620617
divideEdgeByParamsToPoints(inputs: Inputs.OCCT.DivideDto<TopoDS_Edge>): Inputs.Base.Point3[] {
621618
const edge = inputs.shape;
622619
const { uMin, uMax } = this.getEdgeBounds(edge);
623-
const curve = this.getGeomCurveFromEdge(edge, uMin, uMax);
620+
const wire = this.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
621+
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
624622
return this.divideCurveToNrSegments({ ...inputs, shape: curve }, uMin, uMax);
625623
}
626624

@@ -639,7 +637,6 @@ export class OccHelper {
639637
const param = this.remap(inputs.param, 0, 1, uMin, uMax);
640638
curve.D0(param, gpPnt);
641639
const pt: Base.Point3 = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
642-
curve.delete();
643640
gpPnt.delete();
644641
return pt;
645642
}
@@ -651,7 +648,6 @@ export class OccHelper {
651648
const param = this.remap(inputs.param, 0, 1, uMin, uMax);
652649
const vec = curve.DN(param, 1);
653650
const vector: Base.Vector3 = [vec.X(), vec.Y(), vec.Z()];
654-
curve.delete();
655651
vec.delete();
656652
return vector;
657653
}
@@ -1222,26 +1218,29 @@ export class OccHelper {
12221218

12231219
startPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Base.Point3 {
12241220
const edge = inputs.shape;
1225-
const { uMin, uMax } = this.getEdgeBounds(edge);
1226-
const curve = this.getGeomCurveFromEdge(edge, uMin, uMax);
1227-
let res = this.startPointOnCurve({ ...inputs, shape: curve });
1228-
curve.delete();
1221+
const wire = this.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
1222+
let res = this.pointOnWireAtParam({ shape: wire, param: 0 });
1223+
return res;
1224+
}
1225+
1226+
endPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Base.Point3 {
1227+
const edge = inputs.shape;
1228+
const wire = this.combineEdgesAndWiresIntoAWire({ shapes: [edge] });
1229+
let res = this.pointOnWireAtParam({ shape: wire, param: 1 });
12291230
return res;
12301231
}
12311232

12321233
startPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
12331234
const wire = inputs.shape;
12341235
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
12351236
let res = this.startPointOnCurve({ ...inputs, shape: curve });
1236-
curve.delete();
12371237
return res;
12381238
}
12391239

12401240
endPointOnWire(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): Base.Point3 {
12411241
const wire = inputs.shape;
12421242
const curve = new this.occ.BRepAdaptor_CompCurve_2(wire, false);
12431243
let res = this.endPointOnCurve({ ...inputs, shape: curve });
1244-
curve.delete();
12451244
return res;
12461245
}
12471246

@@ -1267,8 +1266,6 @@ export class OccHelper {
12671266
const loc = edge.Location_1();
12681267
const crvHandle = this.occ.BRep_Tool.Curve_1(edge, loc, uMin, uMax);
12691268
const curve = crvHandle.get();
1270-
crvHandle.delete();
1271-
loc.delete();
12721269
return curve;
12731270
}
12741271

src/lib/workers/occ/services/shapes/edge.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class OCCTEdge {
7272
}
7373

7474
getEdge(inputs: Inputs.OCCT.ShapeIndexDto<TopoDS_Shape>): any {
75-
if (!inputs.shape || inputs.shape.ShapeType() > this.occ.TopAbs_ShapeEnum.TopAbs_WIRE || inputs.shape.IsNull()) {
75+
if (!inputs.shape || (inputs.shape.ShapeType && inputs.shape.ShapeType() > this.occ.TopAbs_ShapeEnum.TopAbs_WIRE) || inputs.shape.IsNull()) {
7676
throw (new Error('Shape is not provided or is of incorrect type'));
7777
}
7878
if (!inputs.index) { inputs.index = 0; }
@@ -91,28 +91,12 @@ export class OCCTEdge {
9191
return { result: this.och.tangentOnEdgeAtParam(inputs) };
9292
}
9393

94-
startPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
95-
const edge = inputs.shape;
96-
const { uMin, uMax } = this.och.getEdgeBounds(edge);
97-
const curve = this.och.getGeomCurveFromEdge(edge, uMin, uMax);
98-
const gpPnt = this.och.gpPnt([0, 0, 0]);
99-
curve.D0(uMin, gpPnt);
100-
const pt = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
101-
gpPnt.delete();
102-
curve.delete();
103-
return { result: pt };
94+
startPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
95+
return {result : this.och.startPointOnEdge({...inputs })};
10496
}
10597

10698
endPointOnEdge(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>) {
107-
const edge = inputs.shape;
108-
const { uMin, uMax } = this.och.getEdgeBounds(edge);
109-
const curve = this.och.getGeomCurveFromEdge(edge, uMin, uMax);
110-
const gpPnt = this.och.gpPnt([0, 0, 0]);
111-
curve.D0(uMax, gpPnt);
112-
const pt = [gpPnt.X(), gpPnt.Y(), gpPnt.Z()];
113-
gpPnt.delete();
114-
curve.delete();
115-
return { result: pt };
99+
return {result : this.och.endPointOnEdge({...inputs })};
116100
}
117101

118102
pointOnEdgeAtLength(inputs: Inputs.OCCT.DataOnGeometryAtLengthDto<TopoDS_Edge>): { result: Inputs.Base.Point3 } {

0 commit comments

Comments
 (0)