Add more helper functions

This commit is contained in:
thewildmage
2023-05-31 19:33:41 -06:00
parent 36dfe571a7
commit 7737ab526b
2 changed files with 41 additions and 31 deletions

View File

@@ -293,33 +293,10 @@ std::string CalibPressureAdvancePattern::generate_test(double start_pa, double e
const auto center_x = w / 2;
const auto center_y = h / 2;
int num_patterns = std::ceil((end_pa - start_pa) / step_pa + 1);
num_patterns = std::min(num_patterns, int((h - 10) / m_space_y));
// TODO: fix m_space_y above
const int num_patterns = std::ceil((end_pa - start_pa) / step_pa + 1);
auto object_size_x = object_size_x(num_patterns);
auto object_size_y = object_size_y(start_pa, step_pa, num_patterns);
auto glyph_start_x =
center_x -
object_size_x / 2 +
(((m_wall_count - 1) / 2) * line_spacing_angle() - 2)
;
auto pattern_shift =
center_x -
object_size_x / 2 -
glyph_start_x +
m_glyph_padding_horizontal
;
if (pattern_shift > 0) {
pattern_shift += (line_width_anchor() / 2);
} else {
pattern_shift = 0;
}
auto start_x = center_x - (object_size_x + pattern_shift) / 2;
auto start_y = center_y - object_size_y / 2;
auto start_x = pattern_start_x(num_patterns, center_x);
auto start_y = pattern_start_y(start_pa, step_pa, num_patterns, center_y);
if (is_delta()) {
delta_modify_start(start_x, start_y, num_patterns);
@@ -366,6 +343,30 @@ double CalibPressureAdvancePattern::object_size_y(double start_pa, double step_p
line_width_anchor()
}
double CalibPressureAdvancePattern::glyph_start_x(int num_patterns, double center_x)
{
return
center_x -
object_size_x(num_patterns) / 2 +
(((m_wall_count - 1) / 2) * line_spacing_angle() - 2)
;
}
double CalibPressureAdvancePattern::pattern_shift(int num_patterns, double center_x)
{
auto shift =
center_x -
object_size_x(num_patterns) / 2 -
glyph_start_x(num_patterns, center_x) +
m_glyph_padding_horizontal
;
if (shift > 0) {
return shift + line_width_anchor() / 2;
}
return 0;
}
std::string CalibPressureAdvancePattern::draw_line(double to_x, double to_y, std::string comment = std::string())
{
std::stringstream gcode;
@@ -446,13 +447,13 @@ std::string CalibPressureAdvancePattern::draw_box(double min_x, double min_y, do
std::string CalibPressureAdvancePattern::print_pa_pattern(double start_x, double start_y, double start_pa, double step_pa, int num_patterns)
{
auto& writer = mp_gcodegen->writer();
const auto& writer = mp_gcodegen->writer();
std::stringstream gcode;
gcode << writer.travel_to_z(mp_gcodegen.config().initial_layer_print_height.value, "Move to start layer height");
gcode << writer.travel_to_z(m_height_first_layer, "Move to start layer height");
gcode << move_to(Vec2d(start_x, start_y), "Move to start position");
writer.set_pressure_advance(0.0);
writer.set_pressure_advance(start_pa);
// create anchor and line numbering frame

View File

@@ -108,9 +108,9 @@ public:
m_anchor_perimeters(4),
m_anchor_layer_line_ratio(140),
m_prime_zone_buffer(10.0),
m_wall_count(3),
m_wall_side_length(30.0),
m_corner_angle(90),
m_pattern_spacing(2),
@@ -142,6 +142,15 @@ private:
double object_size_x(int num_patterns);
double object_size_y(double start_pa, double step_pa, int num_patterns);
double frame_size_y() { return std::sin(to_radians(double(m_corner_angle) / 2)) * m_wall_side_length * 2; };
double glyph_start_x(int num_patterns, double center_x);
double pattern_shift(int num_patterns, double center_x);
double print_size_x(int num_patterns, double center_x) { return object_size_x(num_patterns) + pattern_shift(num_patterns, center_x); };
double print_size_y(double start_pa, double step_pa, int num_patterns) { return object_size_y(start_pa, step_pa, num_patterns); };
double pattern_start_x(int num_patterns, double center_x) { return center_x - (object_size_x(num_patterns) + pattern_shift(num_patterns, center_x)) / 2; };
double pattern_start_y(double start_pa, double step_pa, int num_patterns, double center_y) { return center_y - object_size_y(start_pa, step_pa, num_patterns) / 2; };
std::string draw_line(double to_x, double to_y, std::string comment = std::string());
std::string draw_box(double min_x, double min_y, double size_x, double size_y);
@@ -157,9 +166,9 @@ private:
int m_anchor_perimeters;
int m_anchor_layer_line_ratio;
double m_prime_zone_buffer;
int m_wall_count;
double m_wall_side_length;
int m_corner_angle;
int m_pattern_spacing;