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)
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 $
23 #include "ephy-zoom.h"
28 ephy_zoom_get_zoom_level_index (float level
)
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;
45 return n_zoom_levels
- 1;
50 ephy_zoom_get_changed_zoom_level (float level
, int steps
)
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);