From f2e7e5d146876659b06544d05c4a027a77cb7af7 Mon Sep 17 00:00:00 2001 From: Vinicius Monego Date: Sat, 10 Jul 2021 22:04:17 -0300 Subject: [PATCH] Issue #6861: Symmetry Drawing: Decimal input bugs the symmetry. Symmetry drawing allows decimal points for positioning the axes. This has the side effect of of producing an imperfect mirroring when the position contains a decimal point of .50. Since it makes little sense to mirror at decimal points, this change introduces unsigned integers instead of doubles to position the axes. --- app/core/gimpsymmetry-mandala.c | 42 ++++++++++++++---------------- app/core/gimpsymmetry-mirror.c | 46 ++++++++++++++++----------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/app/core/gimpsymmetry-mandala.c b/app/core/gimpsymmetry-mandala.c index 395b2925bf..fe7142a072 100644 --- a/app/core/gimpsymmetry-mandala.c +++ b/app/core/gimpsymmetry-mandala.c @@ -117,25 +117,25 @@ gimp_mandala_class_init (GimpMandalaClass *klass) symmetry_class->get_transform = gimp_mandala_get_transform; symmetry_class->active_changed = gimp_mandala_active_changed; - GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_CENTER_X, - "center-x", - _("Center abscissa"), - NULL, - 0.0, G_MAXDOUBLE, 0.0, - GIMP_PARAM_STATIC_STRINGS | - GIMP_SYMMETRY_PARAM_GUI); + GIMP_CONFIG_PROP_UINT (object_class, PROP_CENTER_X, + "center-x", + _("Center abscissa"), + NULL, + 0, G_MAXUINT, 0, + GIMP_PARAM_STATIC_STRINGS | + GIMP_SYMMETRY_PARAM_GUI); pspec = g_object_class_find_property (object_class, "center-x"); gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate"); gegl_param_spec_set_property_key (pspec, "axis", "x"); - GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_CENTER_Y, - "center-y", - _("Center ordinate"), - NULL, - 0.0, G_MAXDOUBLE, 0.0, - GIMP_PARAM_STATIC_STRINGS | - GIMP_SYMMETRY_PARAM_GUI); + GIMP_CONFIG_PROP_UINT (object_class, PROP_CENTER_Y, + "center-y", + _("Center ordinate"), + NULL, + 0, G_MAXUINT, 0, + GIMP_PARAM_STATIC_STRINGS | + GIMP_SYMMETRY_PARAM_GUI); pspec = g_object_class_find_property (object_class, "center-y"); gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate"); @@ -204,10 +204,9 @@ gimp_mandala_set_property (GObject *object, switch (property_id) { case PROP_CENTER_X: - if (g_value_get_double (value) > 0.0 && - g_value_get_double (value) < (gdouble) gimp_image_get_width (image)) + if (g_value_get_uint (value) < (guint) gimp_image_get_width (image)) { - mandala->center_x = g_value_get_double (value); + mandala->center_x = g_value_get_uint (value); if (mandala->vertical_guide) { @@ -225,10 +224,9 @@ gimp_mandala_set_property (GObject *object, break; case PROP_CENTER_Y: - if (g_value_get_double (value) > 0.0 && - g_value_get_double (value) < (gdouble) gimp_image_get_height (image)) + if (g_value_get_uint (value) < (guint) gimp_image_get_height (image)) { - mandala->center_y = g_value_get_double (value); + mandala->center_y = g_value_get_uint (value); if (mandala->horizontal_guide) { @@ -274,10 +272,10 @@ gimp_mandala_get_property (GObject *object, switch (property_id) { case PROP_CENTER_X: - g_value_set_double (value, mandala->center_x); + g_value_set_uint (value, mandala->center_x); break; case PROP_CENTER_Y: - g_value_set_double (value, mandala->center_y); + g_value_set_uint (value, mandala->center_y); break; case PROP_SIZE: g_value_set_int (value, mandala->size); diff --git a/app/core/gimpsymmetry-mirror.c b/app/core/gimpsymmetry-mirror.c index f8de54bc4a..d17979f7da 100644 --- a/app/core/gimpsymmetry-mirror.c +++ b/app/core/gimpsymmetry-mirror.c @@ -155,25 +155,25 @@ gimp_mirror_class_init (GimpMirrorClass *klass) GIMP_PARAM_STATIC_STRINGS | GIMP_SYMMETRY_PARAM_GUI); - GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_MIRROR_POSITION_X, - "mirror-position-x", - _("Vertical axis position"), - NULL, - 0.0, G_MAXDOUBLE, 0.0, - GIMP_PARAM_STATIC_STRINGS | - GIMP_SYMMETRY_PARAM_GUI); + GIMP_CONFIG_PROP_UINT (object_class, PROP_MIRROR_POSITION_X, + "mirror-position-x", + _("Vertical axis position"), + NULL, + 0, G_MAXUINT, 0, + GIMP_PARAM_STATIC_STRINGS | + GIMP_SYMMETRY_PARAM_GUI); pspec = g_object_class_find_property (object_class, "mirror-position-x"); gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate"); gegl_param_spec_set_property_key (pspec, "axis", "x"); - GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_MIRROR_POSITION_Y, - "mirror-position-y", - _("Horizontal axis position"), - NULL, - 0.0, G_MAXDOUBLE, 0.0, - GIMP_PARAM_STATIC_STRINGS | - GIMP_SYMMETRY_PARAM_GUI); + GIMP_CONFIG_PROP_UINT (object_class, PROP_MIRROR_POSITION_Y, + "mirror-position-y", + _("Horizontal axis position"), + NULL, + 0, G_MAXUINT, 0, + GIMP_PARAM_STATIC_STRINGS | + GIMP_SYMMETRY_PARAM_GUI); pspec = g_object_class_find_property (object_class, "mirror-position-y"); gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate"); @@ -237,10 +237,9 @@ gimp_mirror_set_property (GObject *object, break; case PROP_MIRROR_POSITION_X: - if (g_value_get_double (value) >= 0.0 && - g_value_get_double (value) < (gdouble) gimp_image_get_width (image)) + if (g_value_get_uint (value) < (guint) gimp_image_get_width (image)) { - mirror->mirror_position_x = g_value_get_double (value); + mirror->mirror_position_x = g_value_get_uint (value); if (mirror->vertical_guide) { @@ -258,10 +257,9 @@ gimp_mirror_set_property (GObject *object, break; case PROP_MIRROR_POSITION_Y: - if (g_value_get_double (value) >= 0.0 && - g_value_get_double (value) < (gdouble) gimp_image_get_height (image)) + if (g_value_get_uint (value) < (guint) gimp_image_get_height (image)) { - mirror->mirror_position_y = g_value_get_double (value); + mirror->mirror_position_y = g_value_get_uint (value); if (mirror->horizontal_guide) { @@ -307,10 +305,10 @@ gimp_mirror_get_property (GObject *object, g_value_set_boolean (value, mirror->disable_transformation); break; case PROP_MIRROR_POSITION_X: - g_value_set_double (value, mirror->mirror_position_x); + g_value_set_uint (value, mirror->mirror_position_x); break; case PROP_MIRROR_POSITION_Y: - g_value_set_double (value, mirror->mirror_position_y); + g_value_set_uint (value, mirror->mirror_position_y); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -566,7 +564,7 @@ gimp_mirror_guide_removed_cb (GObject *object, "point-symmetry", FALSE, NULL); g_object_set (mirror, - "mirror-position-x", 0.0, + "mirror-position-x", 0, NULL); if (mirror->horizontal_guide && @@ -616,7 +614,7 @@ gimp_mirror_guide_position_cb (GObject *object, else if (guide == mirror->vertical_guide) { g_object_set (mirror, - "mirror-position-x", (gdouble) gimp_guide_get_position (guide), + "mirror-position-x", (guint) gimp_guide_get_position (guide), NULL); } }