|
1 /*************************************************************************** |
|
2 * Copyright (C) 2006-2008 by Tomasz Ziobrowski * |
|
3 * http://www.3electrons.com * |
|
4 * e-mail: t.ziobrowski@3electrons.com * |
|
5 * * |
|
6 * * |
|
7 * This program is free software; you can redistribute it and/or modify * |
|
8 * it under the terms of the GNU General Public License as published by * |
|
9 * the Free Software Foundation; either version 2 of the License, or * |
|
10 * (at your option) any later version. * |
|
11 * * |
|
12 * This program is distributed in the hope that it will be useful, * |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|
15 * GNU General Public License for more details. * |
|
16 * * |
|
17 * You should have received a copy of the GNU General Public License * |
|
18 * along with this program; if not, write to the * |
|
19 * Free Software Foundation, Inc., * |
|
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|
21 ***************************************************************************/ |
|
22 |
|
23 #include "functions.h" |
|
24 |
|
25 #include <iostream> |
|
26 using namespace std; |
|
27 |
|
28 double minimalStep(double scaleSize, int steps) |
|
29 { |
|
30 scaleSize = std::abs(scaleSize); |
|
31 double ms = scaleSize/steps; |
|
32 double fractions[]={5,2,1}; |
|
33 double multiply = 10; |
|
34 double fraction = 1.0; |
|
35 double test; |
|
36 if (static_cast<int>(ms)<=5) multiply = 0.1 ; |
|
37 |
|
38 while (true) |
|
39 { |
|
40 for (int i=0;i<3;i++) |
|
41 { |
|
42 //cout<<"Fractions:"<<fractions[i]<<" scaleSize:"<<scaleSize<<" steps:"<<steps<<" steps*farction:"<<steps*fractions[i]<<endl; |
|
43 if (fractions[i]<ms) |
|
44 { |
|
45 fraction =fractions[i]; |
|
46 } |
|
47 |
|
48 fractions[i]*=multiply; |
|
49 test = steps * fractions[i]; |
|
50 if ( (test < scaleSize) && multiply< 1.0 ) return fraction; |
|
51 if ( (test > scaleSize) && multiply> 1.0 ) return fraction; |
|
52 } |
|
53 } |
|
54 |
|
55 return fraction; |
|
56 } |