From e152b75f4a2efcbf2eb3f6015ee6b71e64b12d61 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 4 Jan 2020 13:02:53 +0100 Subject: [PATCH] =?UTF-8?q?properly=20use=20angles=20from=200=20to=202PI?= =?UTF-8?q?=20(0=20to=20360=C2=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://pulkomandy.tk/projects/GrafX2/ticket/129 --- src/brush_ops.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/brush_ops.c b/src/brush_ops.c index 4a9db8d3..1563f558 100644 --- a/src/brush_ops.c +++ b/src/brush_ops.c @@ -952,7 +952,6 @@ void Rotate_brush_1_5(void) short old_y; short prev_state; double angle; - int dx,dy; short cursor_x,cursor_y; Operation_pop(&prev_state); @@ -972,9 +971,12 @@ void Rotate_brush_1_5(void) angle=0.0; else { - dx=cursor_x-Brush_rotation_center_X; - dy=cursor_y-Brush_rotation_center_Y; - angle=M_2PI-atan2((double)dy,(double)dx); + // Angle from 0 to 2 PI + int dx = cursor_x - Brush_rotation_center_X; + int dy = cursor_y - Brush_rotation_center_Y; + angle = 0.0 - atan2((double)dy, (double)dx); + if (angle < 0.0) + angle += M_2PI; } if (Menu_is_visible) @@ -1022,7 +1024,6 @@ void Rotate_brush_0_5(void) byte angle_change; short prev_state; double angle=0.0; - int dx,dy; short cursor_x, cursor_y; @@ -1044,9 +1045,12 @@ void Rotate_brush_0_5(void) angle=0.0; else { - dx=cursor_x-Brush_rotation_center_X; - dy=cursor_y-Brush_rotation_center_Y; - angle=M_2PI-atan2((double)dy, (double)dx); + // Angle from 0 to 2 PI + int dx = cursor_x - Brush_rotation_center_X; + int dy = cursor_y - Brush_rotation_center_Y; + angle = 0.0 - atan2((double)dy, (double)dx); + if (angle < 0.0) + angle += M_2PI; } if (Menu_is_visible)