generateNotchedRectangleGcode = function () {
if (2 * radius > width || 2 * radius > height) {
throw new Error(
"Invalid parameters: The diameter of the notch (2*radius) must be less than the width and height of the rectangle."
);
}
const xCenter = 0;
const yCenter = 0;
const x0 = xCenter - width / 2;
const y0 = yCenter - height / 2;
const x1 = xCenter + width / 2;
const y1 = yCenter + height / 2;
const passDepth = cutDepth / passCount;
let gcode = `G00 Z0.5 F${movingFeedRate}
G00 X${x0 + radius} Y${y0} F${movingFeedRate}
G01 Z0 F50`;
for (let x = 0; x < passCount; x++) {
gcode += `
G02 X${x0} Y${y0 + radius} J${radius} F${cuttingFeedRate}
G01 X${x0} Y${y1 - radius} Z-${(x + 1) * passDepth}
G02 X${x0 + radius} Y${y1} I${radius}
G01 X${x1 - radius} Y${y1} F${cuttingFeedRate}
G02 X${x1} Y${y1 - radius} J-${radius}
G01 X${x1} Y${y0 + radius}
G02 X${x1 - radius} Y${y0} I-${radius}
G01 X${x0 + radius} Y${y0}\n`;
}
gcode += `
G02 X${x0} Y${y0 + radius} J${radius} F${cuttingFeedRate}
G01 X${x0} Y${y1 - radius} Z-${passCount * passDepth}
G02 X${x0 + radius} Y${y1} I${radius}
G01 X${x1 - radius} Y${y1} F${cuttingFeedRate}
G02 X${x1} Y${y1 - radius} J-${radius}
G01 X${x1} Y${y0 + radius}
G02 X${x1 - radius} Y${y0} I-${radius}
G01 X${x0 + radius} Y${y0}
G00 Z0.5 F${movingFeedRate}
G00 X0 Y0 F${movingFeedRate}
M30
`;
return gcode;
}