{% if (purge_x_center + purge_amount + rapid_move) > bed_x_max %}
{% set purge_x_center=(bed_x_max - (purge_amount + rapid_move)) %}
{% endif %}
{% if (purge_y_center + purge_amount + rapid_move) > bed_y_max %}
{% set purge_y_center=(bed_y_max - (purge_amount + rapid_move)) %}
{% endif %}
{% set purge_x_origin_low=(purge_x_min - purge_margin) %}
{% set purge_x_origin_high=(purge_x_max + purge_margin) %}
{% set purge_y_origin_low=(purge_y_min - purge_margin) %}
{% set purge_y_origin_high=(purge_y_max + purge_margin) %}
{% set purge_move_speed=(flow_rate / 5.0) * 60 | float %}
{% if cross_section < 5 %}
RESPOND TYPE=command MSG="[Extruder] max_extrude_cross_section is insufficient for line purge, please set it to 5 or greater. Purge skipped."
{% else %}
{% if verbose_enable== True %}
RESPOND TYPE=command MSG="Moving filament tip {tip_distance}mm"
{% endif %}
{% if detect_object== 0 %}
RESPOND TYPE=command MSG="No object detected! Using classic purge line."
{% elif purge_y_origin_low > 0 %}
RESPOND TYPE=command MSG="KAMP line purge starting at {purge_x_center}, {purge_y_origin_low} and purging {purge_amount}mm of filament, requested flow rate is {flow_rate}mm3/s."
{% elif purge_x_origin_low > 0 %}
RESPOND TYPE=command MSG="KAMP line purge starting at {purge_x_origin_low}, {purge_y_center} and purging {purge_amount}mm of filament, requested flow rate is {flow_rate}mm3/s."
{% elif purge_y_origin_high < bed_y_max %}
RESPOND TYPE=command MSG="KAMP line purge starting at {purge_x_center}, {purge_y_origin_high} and purging {purge_amount}mm of filament, requested flow rate is {flow_rate}mm3/s."
{% elif purge_x_origin_high < bed_x_max %}
RESPOND TYPE=command MSG="KAMP line purge starting at {purge_x_origin_high}, {purge_y_center} and purging {purge_amount}mm of filament, requested flow rate is {flow_rate}mm3/s."
{% else %}
RESPOND TYPE=command MSG="No space for purge line! Using classic purge line."