1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

PixelPaint: Hold shift to constrain polygonal select tool line angle

Holding shift while using the polygonal select tool now constrains the
line angle in 22.5 degree increments. This matches the behavior of the
line tool.
This commit is contained in:
Tim Ledbetter 2023-01-12 19:49:03 +00:00 committed by Jelle Raaijmakers
parent 569ef94228
commit ecc202c59d
4 changed files with 27 additions and 19 deletions

View file

@ -70,4 +70,17 @@ Gfx::IntPoint Tool::editor_stroke_position(Gfx::IntPoint pixel_coords, int strok
return position.to_type<int>();
}
Gfx::IntPoint Tool::constrain_line_angle(Gfx::IntPoint start_pos, Gfx::IntPoint end_pos, float angle_increment)
{
float current_angle = AK::atan2<float>(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + float { M_PI * 2 };
float constrained_angle = ((int)((current_angle + angle_increment / 2) / angle_increment)) * angle_increment;
auto diff = end_pos - start_pos;
float line_length = AK::hypot<float>(diff.x(), diff.y());
return { start_pos.x() + (int)(AK::cos(constrained_angle) * line_length),
start_pos.y() + (int)(AK::sin(constrained_angle) * line_length) };
}
}