[gnome-photos/wip/rishi/buffer-decoder: 5/14] Port to G_APPROX_VALUE



commit 681857e7252325dfc26e18b62bfbcb23f2f72d97
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Aug 17 10:11:03 2018 +0200

    Port to G_APPROX_VALUE
    
    Bump minimum GLib version to 2.57.2.

 configure.ac                   |  2 +-
 meson.build                    |  2 +-
 src/photos-gesture-zoom.c      |  9 ++++-----
 src/photos-image-view-helper.c |  5 ++---
 src/photos-image-view.c        |  5 ++---
 src/photos-preview-view.c      | 22 +++++++++++++---------
 src/photos-tool-crop-helper.c  |  9 ++++-----
 src/photos-tool-crop.c         |  6 +++---
 src/photos-utils.c             |  8 --------
 src/photos-utils.h             |  2 --
 10 files changed, 30 insertions(+), 40 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e399bdf5..54889e4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ GDK_PIXBUF_MIN_VERSION=2.32
 GEGL_MIN_VERSION=0.4.0
 GEXIV2_MIN_VERSION=0.10.8
 GFBGRAPH_MIN_VERSION=0.2.1
-GLIB_MIN_VERSION=2.44.0
+GLIB_MIN_VERSION=2.57.2
 GOA_MIN_VERSION=3.8.0
 GRILO_MIN_VERSION=0.3.5
 GTK_MIN_VERSION=3.22.16
diff --git a/meson.build b/meson.build
index 3f6e1552..d115c3b6 100644
--- a/meson.build
+++ b/meson.build
@@ -146,7 +146,7 @@ geocode_glib_dep = dependency('geocode-glib-1.0')
 gexiv_dep = dependency('gexiv2', version: '>= 0.10.8')
 gio_dep = dependency('gio-2.0')
 gio_unix_dep = dependency('gio-unix-2.0')
-glib_dep = dependency('glib-2.0', version: '>= 2.44.0')
+glib_dep = dependency('glib-2.0', version: '>= 2.57.2')
 
 goa_dep = dependency('goa-1.0', version: '>= 3.8.0')
 config_h.set('GOA_API_IS_SUBJECT_TO_CHANGE', true)
diff --git a/src/photos-gesture-zoom.c b/src/photos-gesture-zoom.c
index 0e24f6e0..bdf99147 100644
--- a/src/photos-gesture-zoom.c
+++ b/src/photos-gesture-zoom.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2017 Red Hat, Inc.
+ * Copyright © 2017 – 2018 Red Hat, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,6 @@
 #include "photos-enums.h"
 #include "photos-gesture-zoom.h"
 #include "photos-marshalers.h"
-#include "photos-utils.h"
 
 
 struct _PhotosGestureZoom
@@ -117,14 +116,14 @@ photos_gesture_zoom_update (PhotosGestureZoom *self)
 
   g_return_if_fail (PHOTOS_IS_GESTURE_ZOOM (self));
   g_return_if_fail ((self->previous_direction == PHOTOS_GESTURE_ZOOM_DIRECTION_NONE
-                     && photos_utils_equal_double (self->initial_distance, self->previous_distance))
+                     && G_APPROX_VALUE (self->initial_distance, self->previous_distance, PHOTOS_EPSILON))
                     || (self->previous_direction != PHOTOS_GESTURE_ZOOM_DIRECTION_NONE
-                        && !photos_utils_equal_double (self->initial_distance, self->previous_distance)));
+                        && !G_APPROX_VALUE (self->initial_distance, self->previous_distance, 
PHOTOS_EPSILON)));
 
   distance = photos_gesture_zoom_calculate_distance (self, GDK_TOUCHPAD_GESTURE_PHASE_UPDATE);
   g_return_if_fail (distance >= 0.0);
 
-  if (photos_utils_equal_double (distance, self->previous_distance))
+  if (G_APPROX_VALUE (distance, self->previous_distance, PHOTOS_EPSILON))
     goto out;
 
   if (self->previous_distance > distance)
diff --git a/src/photos-image-view-helper.c b/src/photos-image-view-helper.c
index 7123ec7e..d2d1de50 100644
--- a/src/photos-image-view-helper.c
+++ b/src/photos-image-view-helper.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 – 2017 Red Hat, Inc.
+ * Copyright © 2015 – 2018 Red Hat, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
 #include "config.h"
 
 #include "photos-image-view-helper.h"
-#include "photos-utils.h"
 
 
 struct _PhotosImageViewHelper
@@ -127,7 +126,7 @@ photos_image_view_helper_set_zoom (PhotosImageViewHelper *self, gdouble zoom)
   g_return_if_fail (PHOTOS_IS_IMAGE_VIEW_HELPER (self));
   g_return_if_fail (zoom > 0.0);
 
-  if (photos_utils_equal_double (self->zoom, zoom))
+  if (G_APPROX_VALUE (self->zoom, zoom, PHOTOS_EPSILON))
     return;
 
   self->zoom = zoom;
diff --git a/src/photos-image-view.c b/src/photos-image-view.c
index 5fc72291..1cd0603f 100644
--- a/src/photos-image-view.c
+++ b/src/photos-image-view.c
@@ -30,7 +30,6 @@
 #include "photos-image-view.h"
 #include "photos-image-view-helper.h"
 #include "photos-marshalers.h"
-#include "photos-utils.h"
 
 
 struct _PhotosImageView
@@ -388,7 +387,7 @@ photos_image_view_update (PhotosImageView *self)
 
       photos_image_view_calculate_best_fit_zoom (self, &zoom, &zoom_scaled);
 
-      if (!photos_utils_equal_double (self->zoom, zoom))
+      if (!G_APPROX_VALUE (self->zoom, zoom, PHOTOS_EPSILON))
         {
           self->zoom = zoom;
           g_object_notify (G_OBJECT (self), "zoom");
@@ -1188,7 +1187,7 @@ photos_image_view_set_zoom (PhotosImageView *self, gdouble zoom, gboolean enable
   g_return_if_fail (PHOTOS_IS_IMAGE_VIEW (self));
   g_return_if_fail (zoom > 0.0);
 
-  if (photos_utils_equal_double (self->zoom, zoom))
+  if (G_APPROX_VALUE (self->zoom, zoom, PHOTOS_EPSILON))
     return;
 
   if (self->zoom_animation != NULL)
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 117e81a2..0f5815d9 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 – 2017 Red Hat, Inc.
+ * Copyright © 2013 – 2018 Red Hat, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -981,7 +981,7 @@ photos_preview_view_zoom_end (PhotosPreviewView *self, GVariant *parameter)
   view = photos_preview_view_get_view_from_view_container (view_container);
   zoom = photos_image_view_get_zoom (PHOTOS_IMAGE_VIEW (view));
 
-  if (zoom < self->zoom_best_fit || photos_utils_equal_double (self->zoom_best_fit, zoom))
+  if (zoom < self->zoom_best_fit || G_APPROX_VALUE (self->zoom_best_fit, zoom, PHOTOS_EPSILON))
     {
       photos_image_view_set_best_fit (PHOTOS_IMAGE_VIEW (view), TRUE, TRUE);
       g_simple_action_set_enabled (G_SIMPLE_ACTION (self->zoom_best_fit_action), FALSE);
@@ -1012,8 +1012,10 @@ photos_preview_view_calculate_zoom_for_non_touch (PhotosPreviewView *self,
 
   g_return_val_if_fail (event != PHOTOS_ZOOM_EVENT_NONE, 0.0);
   g_return_val_if_fail (event != PHOTOS_ZOOM_EVENT_TOUCH, 0.0);
-  g_return_val_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR && photos_utils_equal_double 
(delta, 1.0))
-                        || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK && photos_utils_equal_double (delta, 1.0))
+  g_return_val_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR
+                         && G_APPROX_VALUE (delta, 1.0, PHOTOS_EPSILON))
+                        || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK
+                            && G_APPROX_VALUE (delta, 1.0, PHOTOS_EPSILON))
                         || (event == PHOTOS_ZOOM_EVENT_SCROLL && delta >= 0.0),
                         0.0);
 
@@ -1068,8 +1070,9 @@ photos_preview_view_zoom_in (PhotosPreviewView *self, GVariant *parameter)
   g_return_if_fail (event != PHOTOS_ZOOM_EVENT_NONE);
 
   delta = photos_utils_get_zoom_delta (parameter);
-  g_return_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR && photos_utils_equal_double (delta, 
1.0))
-                    || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK && photos_utils_equal_double (delta, 1.0))
+  g_return_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR
+                     && G_APPROX_VALUE (delta, 1.0, PHOTOS_EPSILON))
+                    || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK && G_APPROX_VALUE (delta, 1.0, 
PHOTOS_EPSILON))
                     || (event == PHOTOS_ZOOM_EVENT_SCROLL && delta >= 0.0)
                     || (event == PHOTOS_ZOOM_EVENT_TOUCH && delta >= 0.0 && self->zoom_begin > 0.0));
 
@@ -1122,8 +1125,9 @@ photos_preview_view_zoom_out (PhotosPreviewView *self, GVariant *parameter)
   g_return_if_fail (event != PHOTOS_ZOOM_EVENT_NONE);
 
   delta = photos_utils_get_zoom_delta (parameter);
-  g_return_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR && photos_utils_equal_double (delta, 
1.0))
-                    || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK && photos_utils_equal_double (delta, 1.0))
+  g_return_if_fail ((event == PHOTOS_ZOOM_EVENT_KEYBOARD_ACCELERATOR
+                     && G_APPROX_VALUE (delta, 1.0, PHOTOS_EPSILON))
+                    || (event == PHOTOS_ZOOM_EVENT_MOUSE_CLICK && G_APPROX_VALUE (delta, 1.0, 
PHOTOS_EPSILON))
                     || (event == PHOTOS_ZOOM_EVENT_SCROLL && delta >= 0.0)
                     || (event == PHOTOS_ZOOM_EVENT_TOUCH && delta >= 0.0 && self->zoom_begin > 0.0));
 
@@ -1153,7 +1157,7 @@ photos_preview_view_zoom_out (PhotosPreviewView *self, GVariant *parameter)
   view = photos_preview_view_get_view_from_view_container (view_container);
 
   zoom_best_fit = self->zoom_best_fit * zoom_best_fit_factor;
-  if (zoom < zoom_best_fit || photos_utils_equal_double (zoom_best_fit, zoom))
+  if (zoom < zoom_best_fit || G_APPROX_VALUE (zoom_best_fit, zoom, PHOTOS_EPSILON))
     {
       photos_image_view_set_best_fit (PHOTOS_IMAGE_VIEW (view), TRUE, TRUE);
       g_simple_action_set_enabled (G_SIMPLE_ACTION (self->zoom_best_fit_action), FALSE);
diff --git a/src/photos-tool-crop-helper.c b/src/photos-tool-crop-helper.c
index 06ced3c0..b94cac2e 100644
--- a/src/photos-tool-crop-helper.c
+++ b/src/photos-tool-crop-helper.c
@@ -21,7 +21,6 @@
 #include "config.h"
 
 #include "photos-tool-crop-helper.h"
-#include "photos-utils.h"
 
 
 struct _PhotosToolCropHelper
@@ -228,7 +227,7 @@ photos_tool_crop_helper_set_height (PhotosToolCropHelper *self, gdouble height)
   g_return_if_fail (PHOTOS_IS_TOOL_CROP_HELPER (self));
   g_return_if_fail (height >= 0.0);
 
-  if (photos_utils_equal_double (self->height, height))
+  if (G_APPROX_VALUE (self->height, height, PHOTOS_EPSILON))
     goto out;
 
   self->height = height;
@@ -245,7 +244,7 @@ photos_tool_crop_helper_set_width (PhotosToolCropHelper *self, gdouble width)
   g_return_if_fail (PHOTOS_IS_TOOL_CROP_HELPER (self));
   g_return_if_fail (width >= 0.0);
 
-  if (photos_utils_equal_double (self->width, width))
+  if (G_APPROX_VALUE (self->width, width, PHOTOS_EPSILON))
     goto out;
 
   self->width = width;
@@ -262,7 +261,7 @@ photos_tool_crop_helper_set_x (PhotosToolCropHelper *self, gdouble x)
   g_return_if_fail (PHOTOS_IS_TOOL_CROP_HELPER (self));
   g_return_if_fail (x >= 0.0);
 
-  if (photos_utils_equal_double (self->x, x))
+  if (G_APPROX_VALUE (self->x, x, PHOTOS_EPSILON))
     goto out;
 
   self->x = x;
@@ -279,7 +278,7 @@ photos_tool_crop_helper_set_y (PhotosToolCropHelper *self, gdouble y)
   g_return_if_fail (PHOTOS_IS_TOOL_CROP_HELPER (self));
   g_return_if_fail (y >= 0.0);
 
-  if (photos_utils_equal_double (self->y, y))
+  if (G_APPROX_VALUE (self->y, y, PHOTOS_EPSILON))
     goto out;
 
   self->y = y;
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index ca751023..57833ab4 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2015 – 2017 Red Hat, Inc.
+ * Copyright © 2015 – 2018 Red Hat, Inc.
  * Copyright © 2015 – 2017 Umang Jain
  * Copyright © 2011 – 2015 Yorba Foundation
  *
@@ -220,14 +220,14 @@ photos_tool_crop_find_constraint (PhotosToolCrop *self, gdouble aspect_ratio)
       gdouble constraint_aspect_ratio;
 
       constraint_aspect_ratio = photos_tool_crop_calculate_aspect_ratio (self, i);
-      if (photos_utils_equal_double (aspect_ratio, constraint_aspect_ratio))
+      if (G_APPROX_VALUE (aspect_ratio, constraint_aspect_ratio, PHOTOS_EPSILON))
         {
           ret_val = i;
           break;
         }
 
       constraint_aspect_ratio = 1.0 / constraint_aspect_ratio;
-      if (photos_utils_equal_double (aspect_ratio, constraint_aspect_ratio))
+      if (G_APPROX_VALUE (aspect_ratio, constraint_aspect_ratio, PHOTOS_EPSILON))
         {
           ret_val = i;
           break;
diff --git a/src/photos-utils.c b/src/photos-utils.c
index dbfc2dcb..0374da15 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -772,14 +772,6 @@ photos_utils_ensure_extension_points (void)
 }
 
 
-gboolean
-photos_utils_equal_double (gdouble a, gdouble b)
-{
-  const gdouble diff = a - b;
-  return diff > -PHOTOS_EPSILON && diff < PHOTOS_EPSILON;
-}
-
-
 gdouble
 photos_utils_eval_radial_line (gdouble crop_center_x,
                                gdouble crop_center_y,
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 527eb083..9522539d 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -109,8 +109,6 @@ void             photos_utils_ensure_builtins             (void);
 
 void             photos_utils_ensure_extension_points     (void);
 
-gboolean         photos_utils_equal_double                (gdouble a, gdouble b);
-
 gdouble          photos_utils_eval_radial_line            (gdouble crop_center_x,
                                                            gdouble crop_center_y,
                                                            gdouble corner_x,


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