[gimp] Bug 684330 - Rectangle tool's "fixed size" option is off-by-one
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 684330 - Rectangle tool's "fixed size" option is off-by-one
- Date: Tue, 12 Feb 2013 23:26:56 +0000 (UTC)
commit 4a5a6ef914398ff4d94bc32002d3929e43f63bdf
Author: TÃo Mazars <teo mazars ensimag fr>
Date: Tue Feb 12 18:36:15 2013 +0100
Bug 684330 - Rectangle tool's "fixed size" option is off-by-one
ROUND() is consistent only on positive values, and bad rounding
creates an offset when negative values are involved. Introduce
SIGNED_ROUND() and use it in gimprectangletool.c. It should probably
be used in much more places.
app/tools/gimprectangletool.c | 8 ++++----
libgimpmath/gimpmath.h | 10 +++++++++-
plug-ins/common/curve-bend.c | 1 -
3 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/app/tools/gimprectangletool.c b/app/tools/gimprectangletool.c
index d1ab71d..6f7df65 100644
--- a/app/tools/gimprectangletool.c
+++ b/app/tools/gimprectangletool.c
@@ -4134,13 +4134,13 @@ gimp_rectangle_tool_update_int_rect (GimpRectangleTool *rect_tool)
{
GimpRectangleToolPrivate *priv = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
- priv->x1_int = ROUND (priv->x1);
- priv->y1_int = ROUND (priv->y1);
+ priv->x1_int = SIGNED_ROUND (priv->x1);
+ priv->y1_int = SIGNED_ROUND (priv->y1);
if (gimp_rectangle_tool_rect_rubber_banding_func (rect_tool))
{
- priv->width_int = (gint) ROUND (priv->x2) - priv->x1_int;
- priv->height_int = (gint) ROUND (priv->y2) - priv->y1_int;
+ priv->width_int = (gint) SIGNED_ROUND (priv->x2) - priv->x1_int;
+ priv->height_int = (gint) SIGNED_ROUND (priv->y2) - priv->y1_int;
}
}
diff --git a/libgimpmath/gimpmath.h b/libgimpmath/gimpmath.h
index 843f580..d3abb33 100644
--- a/libgimpmath/gimpmath.h
+++ b/libgimpmath/gimpmath.h
@@ -74,11 +74,19 @@ G_BEGIN_DECLS
* ROUND:
* @x: the value to be rounded.
*
- * This macro rounds its argument @x to the nearest integer.
+ * This macro rounds its positive argument @x to the nearest integer.
**/
#define ROUND(x) ((int) ((x) + 0.5))
/**
+ * SIGNED_ROUND:
+ * @x: the value to be rounded.
+ *
+ * This macro rounds its argument @x to the nearest integer.
+ **/
+#define SIGNED_ROUND(x) ((int) ((((x) < 0) ? (x) - 0.5 : (x) + 0.5)))
+
+/**
* SQR:
* @x: the value to be squared.
*
diff --git a/plug-ins/common/curve-bend.c b/plug-ins/common/curve-bend.c
index 13337fa..2299113 100644
--- a/plug-ins/common/curve-bend.c
+++ b/plug-ins/common/curve-bend.c
@@ -66,7 +66,6 @@
#define MIDDLE 127
-#define SIGNED_ROUND(x) ((int) (((x < 0) ? (x) - 0.5 : (x) + 0.5) ))
#define MIX_CHANNEL(a, b, m) (((a * m) + (b * (255 - m))) / 255)
#define UP_GRAPH 0x1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]