#pragma once #include "vde/core/point.h" #include #include namespace vde::curves { class NurbsCurve; } namespace vde::core { using core::Point3D; using core::Vector3D; /// Toolpath segment types enum class PathSegmentType { Rapid, ///< G0 — rapid traverse (不切削) Linear, ///< G1 — linear feed (直线切削) ArcCW, ///< G2 — clockwise arc ArcCCW ///< G3 — counter-clockwise arc }; /// Single toolpath segment struct PathSegment { Point3D start; Point3D end; Point3D center = Point3D::Zero(); ///< arc center (for G2/G3) PathSegmentType type = PathSegmentType::Linear; double feed_rate = 1000.0; ///< mm/min double z_depth = 0.0; ///< Z cutting depth }; /// Complete toolpath for one operation struct Toolpath { std::string name; std::vector segments; double safe_z = 10.0; ///< safe retract height double cut_z = -1.0; ///< cutting depth double step_down = 0.5; ///< depth per pass }; /// Offset a planar curve outward by a distance /// /// Samples the curve at regular intervals, computes the normal at each sample, /// offsets each point, and fits a NURBS curve through the offset points. /// /// @param curve Input curve (must lie in XY plane, Z coordinate ignored) /// @param distance Offset distance (> 0 for offset outward, < 0 for inward) /// @return Offset curve /// /// @ingroup core [[nodiscard]] curves::NurbsCurve offset_contour( const curves::NurbsCurve& curve, double distance); /// Generate contour toolpath (follow curve at cutting depth) /// /// Creates multiple depth passes from safe_z stepping down to cut_depth. /// Adds rapid moves between passes. /// /// @param curve Input contour curve /// @param cut_depth Cutting Z depth /// @param safe_z Safe retract Z height /// @param step_down Depth per pass /// @return Toolpath with spiral-down contour cuts /// /// @ingroup core [[nodiscard]] Toolpath contour_toolpath( const curves::NurbsCurve& curve, double cut_depth, double safe_z = 10.0, double step_down = 1.0); /// Generate pocket toolpath (clear area inside contour, zigzag fill) /// /// Computes the bounding box of the boundary, generates zigzag lines at the /// specified angle, clips them to the boundary and islands, then sorts /// segments for efficient tool movement. /// /// @param boundary Outer boundary curve /// @param islands Interior island curves (optional) /// @param cut_depth Cutting Z depth /// @param step_over Tool step-over (fraction of tool diameter) /// @param angle Zigzag angle in degrees (0=horizontal, 90=vertical) /// @return Toolpath with spiral-down pocket cuts /// /// @ingroup core [[nodiscard]] Toolpath pocket_toolpath( const curves::NurbsCurve& boundary, const std::vector& islands, double cut_depth, double step_over = 0.5, double angle = 0.0); /// Export toolpath to G-code string (basic ISO format) /// /// @param tp Toolpath to export /// @return G-code string /// /// @ingroup core [[nodiscard]] std::string export_gcode(const Toolpath& tp); } // namespace vde::core