Skip to content

Commit

Permalink
Improve extrusion radius calculation in parser
Browse files Browse the repository at this point in the history
Refactored the calculation of the extrusion radius by introducing `radiusSquared` to handle squared values correctly before taking the square root. This change ensures that negative extrusions are handled as move-extrusions and updates bounding box calculations more accurately.
  • Loading branch information
saumyaj3 committed Dec 3, 2024
1 parent b41428b commit f608837
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,17 @@ export class GCodeParser {
const length = getLength(lastPoint, newPoint);

if (length !== 0) {
let radius = ((e - lastE) / length) * 10;
let radiusSquared = ((e - lastE) / length);

let radius = 0;
// Hide negative extrusions as only move-extrusions
if (radius < 0) {
if (radiusSquared < 0) {
radius = 0;
}

if (radius == 0) {
if (radiusSquared === 0) {
radius = travelWidth;
} else {
radius = Math.sqrt(radiusSquared);
// Update the bounding box.
const { min: newMin, max: newMax } = calcMinMax(
min,
Expand Down

0 comments on commit f608837

Please sign in to comment.