| 1488 | } |
| 1489 | |
| 1490 | Expected<void> interpolateArcs( std::vector<GCommand>& commands, const ArcInterpolationParams& params, Axis axis ) |
| 1491 | { |
| 1492 | const ArcPlane arcPlane = ( axis == Axis::X ) ? ArcPlane::YZ : |
| 1493 | ( axis == Axis::Y ) ? ArcPlane::XZ : |
| 1494 | ArcPlane::XY; |
| 1495 | |
| 1496 | commands.insert( commands.begin(), { .arcPlane = arcPlane } ); |
| 1497 | size_t startIndex = 1u; |
| 1498 | |
| 1499 | for ( int i = 0; startIndex < commands.size(); ++i ) |
| 1500 | { |
| 1501 | if ( ( i & 0x3FF ) && !reportProgress( params.cb, float( startIndex ) / commands.size() ) ) |
| 1502 | return unexpectedOperationCanceled(); |
| 1503 | |
| 1504 | while ( startIndex != commands.size() && ( commands[startIndex].type != MoveType::Linear || std::isnan( coord( commands[startIndex], axis ) ) ) ) |
| 1505 | ++startIndex; |
| 1506 | |
| 1507 | if ( ++startIndex >= commands.size() ) |
| 1508 | return {}; |
| 1509 | |
| 1510 | auto endIndex = startIndex + 1; |
| 1511 | while ( endIndex != commands.size() && std::isnan( coord( commands[endIndex], axis ) ) ) |
| 1512 | ++endIndex; |
| 1513 | |
| 1514 | const size_t segmentSize = endIndex - startIndex; |
| 1515 | const auto interpolatedSegment = replaceLineSegmentsWithCircularArcs( std::span<GCommand>( &commands[startIndex], segmentSize ), params.eps, params.maxRadius, axis ); |
| 1516 | if ( interpolatedSegment.empty() ) |
| 1517 | { |
| 1518 | startIndex = endIndex; |
| 1519 | continue; |
| 1520 | } |
| 1521 | |
| 1522 | if ( interpolatedSegment.size() != segmentSize ) |
| 1523 | { |
| 1524 | commands.erase( commands.begin() + startIndex + 1, commands.begin() + endIndex ); |
| 1525 | commands.insert( commands.begin() + startIndex + 1, interpolatedSegment.begin(), interpolatedSegment.end() ); |
| 1526 | } |
| 1527 | |
| 1528 | startIndex = startIndex + interpolatedSegment.size() + 1; |
| 1529 | } |
| 1530 | |
| 1531 | if ( !reportProgress( params.cb, 1.0f ) ) |
| 1532 | return unexpectedOperationCanceled(); |
| 1533 | |
| 1534 | return {}; |
| 1535 | } |
| 1536 | |
| 1537 | std::shared_ptr<ObjectGcode> exportToolPathToGCode( const std::vector<GCommand>& commands ) |
| 1538 | { |
nothing calls this directly
no test coverage detected