Skip to content

Commit ab54854

Browse files
committed
fix(nc): fix connecting arc/lines that are tangental
1 parent 4fd1515 commit ab54854

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

src/renderer/lib/nc/parser/parser.ts

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -900,22 +900,25 @@ export class NCToShapesVisitor extends BaseCstVisitor {
900900
lastPath.xe = insersectionPoints[0].x
901901
lastPath.ye = insersectionPoints[0].y
902902
} else {
903-
// arcs and lines may not intersect due to the cutter compensation and the case where the arc is tangent to the line
904-
// for those cases we can create the connecting arc tool path
905-
this.result.push(new Shapes.Arc({
906-
xs: lastPath.xe,
907-
ys: lastPath.ye,
908-
xe: xs,
909-
ye: ys,
910-
xc: this.state.previousX,
911-
yc: this.state.previousY,
912-
clockwise: lastPath.clockwise ? 0 : 1,
913-
symbol: this.state.currentTool,
914-
attributes: {
915-
cutterCompensation: `${(this.state.cutterCompensation).toString()}${this.state.units}`,
916-
cutterCompensationMode: this.state.cutterCompensationMode,
917-
}
918-
}))
903+
if (Math.sqrt(((lastPath.xe - xs) ** 2) + ((lastPath.ye - ys) ** 2)) > this.state.cutterCompensation / 2) {
904+
// arcs and lines may not intersect due to the cutter compensation and the case where the arc is tangent to the line
905+
// we can tell if the tangent line to the arc is a smooth transition or a sharp corner by checking if the distance between the arc end point and the line start point is greater than half the cutter compensation
906+
// for those cases we can create the connecting arc tool path
907+
this.result.push(new Shapes.Arc({
908+
xs: lastPath.xe,
909+
ys: lastPath.ye,
910+
xe: xs,
911+
ye: ys,
912+
xc: this.state.previousX,
913+
yc: this.state.previousY,
914+
clockwise: lastPath.clockwise ? 0 : 1,
915+
symbol: this.state.currentTool,
916+
attributes: {
917+
cutterCompensation: `${(this.state.cutterCompensation).toString()}${this.state.units}`,
918+
cutterCompensationMode: this.state.cutterCompensationMode,
919+
}
920+
}))
921+
}
919922
}
920923

921924
}
@@ -1014,22 +1017,25 @@ export class NCToShapesVisitor extends BaseCstVisitor {
10141017
lastPath.xe = insersectionPoints[1].x
10151018
lastPath.ye = insersectionPoints[1].y
10161019
} else {
1017-
// arcs and lines may not intersect due to the cutter compensation and the case where the arc is tangent to the line
1018-
// for those cases we can create the connecting arc tool path
1019-
this.result.push(new Shapes.Arc({
1020-
xs: lastPath.xe,
1021-
ys: lastPath.ye,
1022-
xe: xs,
1023-
ye: ys,
1024-
xc: this.state.previousX,
1025-
yc: this.state.previousY,
1026-
clockwise: clockwise ? 0 : 1,
1027-
symbol: this.state.currentTool,
1028-
attributes: {
1029-
cutterCompensation: `${(this.state.cutterCompensation).toString()}${this.state.units}`,
1030-
cutterCompensationMode: this.state.cutterCompensationMode,
1031-
}
1032-
}))
1020+
if (Math.sqrt(((lastPath.xe - xs) ** 2) + ((lastPath.ye - ys) ** 2)) > this.state.cutterCompensation / 2) {
1021+
// arcs and lines may not intersect due to the cutter compensation and the case where the arc is tangent to the line
1022+
// we can tell if the tangent line to the arc is a smooth transition or a sharp corner by checking if the distance between the arc end point and the line start point is greater than half the cutter compensation
1023+
// for those cases we can create the connecting arc tool path
1024+
this.result.push(new Shapes.Arc({
1025+
xs: lastPath.xe,
1026+
ys: lastPath.ye,
1027+
xe: xs,
1028+
ye: ys,
1029+
xc: this.state.previousX,
1030+
yc: this.state.previousY,
1031+
clockwise: clockwise ? 0 : 1,
1032+
symbol: this.state.currentTool,
1033+
attributes: {
1034+
cutterCompensation: `${(this.state.cutterCompensation).toString()}${this.state.units}`,
1035+
cutterCompensationMode: this.state.cutterCompensationMode,
1036+
}
1037+
}))
1038+
}
10331039
}
10341040
}
10351041
}

0 commit comments

Comments
 (0)