Initial import of ephy (rev# 7126) from svn
[ephy-soc.git] / lib / .svn / text-base / ephy-zoom.c.svn-base
blob43c8757ab55094bb646fbca646f32ead4842ae0b
1 /*
2  *  Copyright © 2003 Christian Persch
3  *
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.
8  *
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.
13  *
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.
17  *
18  *  $Id$
19  */
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++)
36         {
37                 current = zoom_levels[i].level;
38                 mean = sqrt (previous * current);
40                 if (level <= mean) return i - 1;
42                 previous = current;
43         }
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);