src/misc.h

changeset 500
cad8cdc42a64
parent 498
791c831c8020
child 501
8f314f3f5054
equal deleted inserted replaced
499:ebd30d9eb667 500:cad8cdc42a64
38 str ftoa (double num); 38 str ftoa (double num);
39 39
40 double atof (str val); 40 double atof (str val);
41 41
42 // Simplifies the given fraction. 42 // Simplifies the given fraction.
43 void simplify (short& numer, short& denom); 43 void simplify (int& numer, int& denom);
44 44
45 str join (initlist<StringFormatArg> vals, str delim = " "); 45 str join (initlist<StringFormatArg> vals, str delim = " ");
46 46
47 // Grid stuff 47 // Grid stuff
48 struct gridinfo 48 struct gridinfo
49 { const char* const name; 49 { const char* const name;
50 FloatConfig* const confs[4]; 50 FloatConfig* const confs[4];
51 }; 51 };
52 52
53 extern_cfg (Int, grid); 53 extern_cfg (Int, grid);
54 static const short g_NumGrids = 3; 54 static const int g_NumGrids = 3;
55 extern const gridinfo g_GridInfo[3]; 55 extern const gridinfo g_GridInfo[3];
56 56
57 inline const gridinfo& currentGrid() 57 inline const gridinfo& currentGrid()
58 { return g_GridInfo[grid]; 58 { return g_GridInfo[grid];
59 } 59 }
85 85
86 double snap (double value, const Grid::Config axis); 86 double snap (double value, const Grid::Config axis);
87 } 87 }
88 88
89 // ============================================================================= 89 // =============================================================================
90 // RingFinder
91 //
92 // Provides an algorithm for finding a solution of rings between radii r0 and r1.
93 // =============================================================================
94 class RingFinder
95 { public:
96 struct SolutionComponent
97 { int num;
98 double scale;
99 };
100
101 typedef List<SolutionComponent> SolutionType;
102
103 RingFinder() {}
104 bool findRings (double r0, double r1);
105
106 inline const SolutionType& solution()
107 { return m_solution;
108 }
109
110 inline bool operator() (double r0, double r1)
111 { return findRings (r0, r1);
112 }
113
114 private:
115 SolutionType m_solution;
116 };
117
118 extern RingFinder g_RingFinder;
119
120 // =============================================================================
90 template<class T> void dataswap (T& a, T& b) 121 template<class T> void dataswap (T& a, T& b)
91 { T c = a; 122 { T c = a;
92 a = b; 123 a = b;
93 b = c; 124 b = c;
94 } 125 }
118 // Templated absolute value 149 // Templated absolute value
119 template<class T> static inline T abs (T a) 150 template<class T> static inline T abs (T a)
120 { return (a >= 0) ? a : -a; 151 { return (a >= 0) ? a : -a;
121 } 152 }
122 153
154 template<class T> inline bool isZero (T a)
155 { return abs<T> (a) < 0.0001;
156 }
157
158 template<class T> inline bool isInteger (T a)
159 { return isZero (a - (int) a);
160 }
161
123 #endif // MISC_H 162 #endif // MISC_H

mercurial