From 5126538a873c9b99b62ea3ef3d9ba35c440177f7 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Fri, 19 Aug 2016 16:10:37 +0900 Subject: [PATCH] live_edit: Fix to reduce round-off error. Round off values in the end to reduce round-off error. --- src/bin/live_edit.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bin/live_edit.c b/src/bin/live_edit.c index 7e4a39d..caab8fe 100644 --- a/src/bin/live_edit.c +++ b/src/bin/live_edit.c @@ -832,10 +832,16 @@ keygrabber_direction_key_down_cb(void *data, Evas *e EINA_UNUSED, //Calculate the relative value of live view item to 4 places of decimals double orig_rel1_x = ld->rel_info.rel1_x; double orig_rel1_y = ld->rel_info.rel1_y; - ld->rel_info.rel1_x = ROUNDING(((double) (x - vx) / vw), 4); - ld->rel_info.rel1_y = ROUNDING(((double) (y - vy) / vh), 4); - ld->rel_info.rel2_x += ROUNDING((ld->rel_info.rel1_x - orig_rel1_x), 4); - ld->rel_info.rel2_y += ROUNDING((ld->rel_info.rel1_y - orig_rel1_y), 4); + ld->rel_info.rel1_x = (double) (x - vx) / vw; + ld->rel_info.rel1_y = (double) (y - vy) / vh; + ld->rel_info.rel2_x += ld->rel_info.rel1_x - orig_rel1_x; + ld->rel_info.rel2_y += ld->rel_info.rel1_y - orig_rel1_y; + + //Round off in the end to reduce round-off error. + ROUNDING(ld->rel_info.rel1_x, 4); + ROUNDING(ld->rel_info.rel1_y, 4); + ROUNDING(ld->rel_info.rel2_x, 4); + ROUNDING(ld->rel_info.rel2_y, 4); ctrl_pt_update(ld); info_text_update(ld); @@ -1876,10 +1882,16 @@ layout_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, double orig_rel1_x = ld->rel_info.rel1_x; double orig_rel1_y = ld->rel_info.rel1_y; - ld->rel_info.rel1_x = ROUNDING(((double) (x - vx) / vw), 2); - ld->rel_info.rel1_y = ROUNDING(((double) (y - vy) / vh), 2); - ld->rel_info.rel2_x += ROUNDING((ld->rel_info.rel1_x - orig_rel1_x), 2); - ld->rel_info.rel2_y += ROUNDING((ld->rel_info.rel1_y - orig_rel1_y), 2); + ld->rel_info.rel1_x = (double) (x - vx) / vw; + ld->rel_info.rel1_y = (double) (y - vy) / vh; + ld->rel_info.rel2_x += ld->rel_info.rel1_x - orig_rel1_x; + ld->rel_info.rel2_y += ld->rel_info.rel1_y - orig_rel1_y; + + //Round off in the end to reduce round-off error. + ROUNDING(ld->rel_info.rel1_x, 2); + ROUNDING(ld->rel_info.rel1_y, 2); + ROUNDING(ld->rel_info.rel2_x, 2); + ROUNDING(ld->rel_info.rel2_y, 2); evas_object_move(obj, x, y);