More work on merging history view
[ephy-soc.git] / lib / ephy-zoom.c
blob4e0d54839136abd94eefdf3e93f7beb3ea922c13
1 /*
2 * Copyright © 2003 Christian Persch
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * $Id: ephy-zoom.c 6952 2007-03-11 19:42:02Z chpe $
21 #include "config.h"
23 #include "ephy-zoom.h"
25 #include <math.h>
27 int
28 ephy_zoom_get_zoom_level_index (float level)
30 guint i;
31 float previous, current, mean;
33 previous = zoom_levels[0].level;
35 for (i = 1; i < n_zoom_levels; i++)
37 current = zoom_levels[i].level;
38 mean = sqrt (previous * current);
40 if (level <= mean) return i - 1;
42 previous = current;
45 return n_zoom_levels - 1;
49 float
50 ephy_zoom_get_changed_zoom_level (float level, int steps)
52 int index;
54 index = ephy_zoom_get_zoom_level_index (level);
55 return zoom_levels[CLAMP(index + steps, 0, (int) n_zoom_levels - 1)].level;
58 float ephy_zoom_get_nearest_zoom_level (float level)
60 return ephy_zoom_get_changed_zoom_level (level, 0);