diff --git a/ChangeLog b/ChangeLog index 110f5345e5..0318e2c9c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-07-16 Michael Natterer + + * app/tools/gimppainttool.c (gimp_paint_tool_draw): add a small + EPSILON to the brush coordinates before rounding them (fixes + off-by-one floating point rounding fnord for "hard edge" painting + where e.g. (5.0 - (3.0 / 2.0)) was rounded to 3.0 instead of 4.0). + + * app/tools/gimpdrawtool.c (gimp_draw_tool_draw_boundary): use + RINT() instead of floor() to round the transformed boundary to + GdkSegments. + 2003-07-16 Michael Natterer * app/tools/gimptransformtool.[ch]: implemented transforming of diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c index deefadcb63..932e74af98 100644 --- a/app/tools/gimpbrushtool.c +++ b/app/tools/gimpbrushtool.c @@ -182,8 +182,8 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool) paint_tool->brush_bound_segs = NULL; paint_tool->n_brush_bound_segs = 0; - paint_tool->brush_x = 0; - paint_tool->brush_y = 0; + paint_tool->brush_x = 0.0; + paint_tool->brush_y = 0.0; } static void @@ -734,8 +734,16 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool) if (paint_options->hard) { - brush_x = RINT (brush_x); - brush_y = RINT (brush_y); +#define EPSILON 0.000001 + + /* Add EPSILON before rounding since e.g. + * (5.0 - 0.5) may end up at (4.499999999....) + * due to floating point fnords + */ + brush_x = RINT (brush_x + EPSILON); + brush_y = RINT (brush_y + EPSILON); + +#undef EPSILON } gimp_draw_tool_draw_boundary (draw_tool, diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c index 052ed89881..23eb80a9bb 100644 --- a/app/tools/gimpdrawtool.c +++ b/app/tools/gimpdrawtool.c @@ -835,8 +835,8 @@ gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool, &x, &y, FALSE); - gdk_segs[n_gdk_segs].x1 = floor (CLAMP (x, -1, xmax)); - gdk_segs[n_gdk_segs].y1 = floor (CLAMP (y, -1, ymax)); + gdk_segs[n_gdk_segs].x1 = RINT (CLAMP (x, -1, xmax)); + gdk_segs[n_gdk_segs].y1 = RINT (CLAMP (y, -1, ymax)); gimp_display_shell_transform_xy_f (shell, bound_segs[i].x2 + offset_x, @@ -844,8 +844,8 @@ gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool, &x, &y, FALSE); - gdk_segs[n_gdk_segs].x2 = floor (CLAMP (x, -1, xmax)); - gdk_segs[n_gdk_segs].y2 = floor (CLAMP (y, -1, ymax)); + gdk_segs[n_gdk_segs].x2 = RINT (CLAMP (x, -1, xmax)); + gdk_segs[n_gdk_segs].y2 = RINT (CLAMP (y, -1, ymax)); if (gdk_segs[n_gdk_segs].x1 == gdk_segs[n_gdk_segs].x2 && gdk_segs[n_gdk_segs].y1 == gdk_segs[n_gdk_segs].y2) diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c index deefadcb63..932e74af98 100644 --- a/app/tools/gimppainttool.c +++ b/app/tools/gimppainttool.c @@ -182,8 +182,8 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool) paint_tool->brush_bound_segs = NULL; paint_tool->n_brush_bound_segs = 0; - paint_tool->brush_x = 0; - paint_tool->brush_y = 0; + paint_tool->brush_x = 0.0; + paint_tool->brush_y = 0.0; } static void @@ -734,8 +734,16 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool) if (paint_options->hard) { - brush_x = RINT (brush_x); - brush_y = RINT (brush_y); +#define EPSILON 0.000001 + + /* Add EPSILON before rounding since e.g. + * (5.0 - 0.5) may end up at (4.499999999....) + * due to floating point fnords + */ + brush_x = RINT (brush_x + EPSILON); + brush_y = RINT (brush_y + EPSILON); + +#undef EPSILON } gimp_draw_tool_draw_boundary (draw_tool,