[gnome-shell] Replace "round(x)" with "(int)(0.5 + x)"
- From: Siegfried-Angel Gevatter Pujals <sgevatter src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell] Replace "round(x)" with "(int)(0.5 + x)"
- Date: Thu, 1 Oct 2009 20:39:36 +0000 (UTC)
commit 243824ab80fb58a46f9471e880316caf8356fe80
Author: Siegfried-Angel Gevatter Pujals <rainct ubuntu com>
Date: Thu Oct 1 22:32:38 2009 +0200
Replace "round(x)" with "(int)(0.5 + x)"
round() is a C99 addition, so causes portability problems:
different C library versions require different #defines to
enable it. So simply avoid using it.
src/st/st-button.c | 3 +--
src/st/st-theme-node.c | 21 ++++++++++-----------
src/st/st-widget.c | 5 ++---
3 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/src/st/st-button.c b/src/st/st-button.c
index a479e23..e1602e0 100644
--- a/src/st/st-button.c
+++ b/src/st/st-button.c
@@ -35,7 +35,6 @@
#include "config.h"
#endif
-#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -165,7 +164,7 @@ st_button_style_changed (StWidget *widget)
spacing = 6;
st_theme_node_get_length (theme_node, "border-spacing", FALSE, &spacing);
- priv->spacing = round (spacing);
+ priv->spacing = (int)(0.5 + spacing);
/* update the label styling */
st_button_update_label_style (button);
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index ac2c1f7..0b48e47 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -1,6 +1,5 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -1565,7 +1564,7 @@ font_weight_from_term (CRTerm *term,
if (term->content.num->type != NUM_GENERIC)
return FALSE;
- weight_int = (int)(term->content.num->val + 0.5);
+ weight_int = (int)(0.5 + term->content.num->val);
*weight = weight_int;
*weight_absolute = TRUE;
@@ -1899,7 +1898,7 @@ st_theme_node_get_border_image (StThemeNode *node)
if (term->content.num->type == NUM_GENERIC)
{
- borders[n_borders] = round (0.5 + term->content.num->val);
+ borders[n_borders] = (int)(0.5 + term->content.num->val);
n_borders++;
}
else if (term->content.num->type == NUM_PERCENTAGE)
@@ -1962,15 +1961,15 @@ st_theme_node_get_border_image (StThemeNode *node)
static float
get_width_inc (StThemeNode *node)
{
- return (round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] +
- round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
+ return ((int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT] +
+ (int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
}
static float
get_height_inc (StThemeNode *node)
{
- return (round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] +
- round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
+ return ((int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP] +
+ (int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
}
/**
@@ -2103,10 +2102,10 @@ st_theme_node_get_content_box (StThemeNode *node,
ensure_borders (node);
- content_box->x1 = round (node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
- content_box->y1 = round (node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
- content_box->x2 = allocation->x2 - allocation->x1 - (round (node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
- content_box->y2 = allocation->y2 - allocation->y1 - (round (node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
+ content_box->x1 = (int)(0.5 + node->border_width[ST_SIDE_LEFT]) + node->padding[ST_SIDE_LEFT];
+ content_box->y1 = (int)(0.5 + node->border_width[ST_SIDE_TOP]) + node->padding[ST_SIDE_TOP];
+ content_box->x2 = allocation->x2 - allocation->x1 - ((int)(0.5 + node->border_width[ST_SIDE_RIGHT]) + node->padding[ST_SIDE_RIGHT]);
+ content_box->y2 = allocation->y2 - allocation->y1 - ((int)(0.5 + node->border_width[ST_SIDE_BOTTOM]) + node->padding[ST_SIDE_BOTTOM]);
}
diff --git a/src/st/st-widget.c b/src/st/st-widget.c
index 6605ce7..02c57cc 100644
--- a/src/st/st-widget.c
+++ b/src/st/st-widget.c
@@ -28,7 +28,6 @@
#include "config.h"
#endif
-#include <math.h>
#include <stdlib.h>
#include <string.h>
@@ -533,7 +532,7 @@ st_widget_real_style_changed (StWidget *self)
double width = st_theme_node_get_border_width (theme_node, side);
if (width > 0.5)
{
- border_width = round (width);
+ border_width = (int)(0.5 + width);
st_theme_node_get_border_color (theme_node, side, &border_color);
break;
}
@@ -544,7 +543,7 @@ st_widget_real_style_changed (StWidget *self)
double radius = st_theme_node_get_border_radius (theme_node, corner);
if (radius > 0.5)
{
- border_radius = round (radius);
+ border_radius = (int)(0.5 + radius);
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]