[gimp/gimp-2-10] Issue #4846 - Symmetry origin is wrong when painting on offset drawable



commit 7685c16a1eb51c4422fd284e79c1470ef610ef47
Author: Ell <ell_se yahoo com>
Date:   Thu Mar 26 20:26:51 2020 +0200

    Issue #4846 - Symmetry origin is wrong when painting on offset drawable
    
    In gimp_symmetry_{mirror,mandala}_update_strokes(), adjust the
    symmetry origin according to the drawable offset, so that it
    remains fixed relative to the image regardless of the drawable
    position.
    
    (cherry picked from commit 6ed9b2bb7ab92015d4c97e40f1946e50e9fd1fd4)

 app/core/gimpsymmetry-mandala.c | 23 +++++++++++++++--------
 app/core/gimpsymmetry-mirror.c  | 15 +++++++++++----
 2 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/app/core/gimpsymmetry-mandala.c b/app/core/gimpsymmetry-mandala.c
index 94374ac66a..668819a820 100644
--- a/app/core/gimpsymmetry-mandala.c
+++ b/app/core/gimpsymmetry-mandala.c
@@ -456,9 +456,16 @@ gimp_mandala_update_strokes (GimpSymmetry *sym,
   GimpMandala *mandala = GIMP_MANDALA (sym);
   GimpCoords  *coords;
   GimpMatrix3  matrix;
+  gdouble      slice_angle;
+  gdouble      mid_slice_angle = 0.0;
+  gdouble      center_x, center_y;
+  gint         offset_x, offset_y;
   gint         i;
-  gdouble slice_angle;
-  gdouble mid_slice_angle = 0.0;
+
+  gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
+
+  center_x = mandala->center_x - offset_x;
+  center_y = mandala->center_y - offset_y;
 
   g_list_free_full (sym->strokes, g_free);
   sym->strokes = NULL;
@@ -472,8 +479,8 @@ gimp_mandala_update_strokes (GimpSymmetry *sym,
   if (mandala->enable_reflection)
     {
       /* Find out in which slice the user is currently drawing. */
-      gdouble angle = atan2 (sym->origin->y - mandala->center_y,
-                             sym->origin->x - mandala->center_x);
+      gdouble angle = atan2 (sym->origin->y - center_y,
+                             sym->origin->x - center_x);
       gint slice_no = (int) floor(angle/slice_angle);
 
       /* Angle where the middle of that slice is. */
@@ -487,8 +494,8 @@ gimp_mandala_update_strokes (GimpSymmetry *sym,
       coords = g_memdup (sym->origin, sizeof (GimpCoords));
       gimp_matrix3_identity (&matrix);
       gimp_matrix3_translate (&matrix,
-                              - mandala->center_x,
-                              - mandala->center_y);
+                              -center_x,
+                              -center_y);
       if (mandala->enable_reflection && i % 2 == 1)
         {
           /* Reflecting over the mid_slice_angle axis, reflects slice without changing position. */
@@ -501,8 +508,8 @@ gimp_mandala_update_strokes (GimpSymmetry *sym,
           gimp_matrix3_rotate (&matrix, - i * slice_angle);
         }
       gimp_matrix3_translate (&matrix,
-                              mandala->center_x,
-                              mandala->center_y);
+                              +center_x,
+                              +center_y);
       gimp_matrix3_transform_point (&matrix,
                                     coords->x,
                                     coords->y,
diff --git a/app/core/gimpsymmetry-mirror.c b/app/core/gimpsymmetry-mirror.c
index 7f92301292..66a0eaa07b 100644
--- a/app/core/gimpsymmetry-mirror.c
+++ b/app/core/gimpsymmetry-mirror.c
@@ -325,6 +325,13 @@ gimp_mirror_update_strokes (GimpSymmetry *sym,
   GimpMirror *mirror  = GIMP_MIRROR (sym);
   GList      *strokes = NULL;
   GimpCoords *coords;
+  gdouble     mirror_position_x, mirror_position_y;
+  gint        offset_x,          offset_y;
+
+  gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
+
+  mirror_position_x = mirror->mirror_position_x - offset_x;
+  mirror_position_y = mirror->mirror_position_y - offset_y;
 
   g_list_free_full (sym->strokes, g_free);
   strokes = g_list_prepend (strokes,
@@ -333,22 +340,22 @@ gimp_mirror_update_strokes (GimpSymmetry *sym,
   if (mirror->horizontal_mirror)
     {
       coords = g_memdup (origin, sizeof (GimpCoords));
-      coords->y = 2.0 * mirror->mirror_position_y - origin->y;
+      coords->y = 2.0 * mirror_position_y - origin->y;
       strokes = g_list_prepend (strokes, coords);
     }
 
   if (mirror->vertical_mirror)
     {
       coords = g_memdup (origin, sizeof (GimpCoords));
-      coords->x = 2.0 * mirror->mirror_position_x - origin->x;
+      coords->x = 2.0 * mirror_position_x - origin->x;
       strokes = g_list_prepend (strokes, coords);
     }
 
   if (mirror->point_symmetry)
     {
       coords = g_memdup (origin, sizeof (GimpCoords));
-      coords->x = 2.0 * mirror->mirror_position_x - origin->x;
-      coords->y = 2.0 * mirror->mirror_position_y - origin->y;
+      coords->x = 2.0 * mirror_position_x - origin->x;
+      coords->y = 2.0 * mirror_position_y - origin->y;
       strokes = g_list_prepend (strokes, coords);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]