Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ValueArea.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Sun Aug 15 01:53:13 2010 UTC (13 years, 9 months ago) by okadu
File MIME type: text/x-chdr
File size: 1624 byte(s)


1 #ifndef VALUEAREA_H_INCLUDED
2 #define VALUEAREA_H_INCLUDED
3
4 /*
5 * 変数の値を一定の範囲に丸める (int)
6 */
7 inline void ValueArea(
8 int *dest, // 対象値
9 int min, // 最小値
10 int max // 最大値
11 ){
12 if(*dest<min) *dest = min;
13 if(*dest>max) *dest = max;
14 }
15
16 /*
17 * 変数の値を一定の範囲に丸める (float)
18 */
19 inline void ValueArea(
20 float *dest, // 対象値
21 float min, // 最小値
22 float max // 最大値
23 ){
24 if(*dest<min) *dest = min;
25 if(*dest>max) *dest = max;
26 }
27
28 /*
29 * 変数の値を一定の範囲でループさせる (char)
30 */
31 inline void ValueCircular(
32 char *dest, // 対象値
33 char min, // 最小値
34 char max // 最大値
35 ){
36 char area = max-min+1;
37 *dest = (*dest+area)%area;
38 }
39
40 /*
41 * 変数の値を一定の範囲でループさせる (int)
42 */
43 inline void ValueCircular(
44 int *dest, // 対象値
45 int min, // 最小値
46 int max // 最大値
47 ){
48 int area = max-min+1;
49 *dest = (*dest+area)%area;
50 }
51
52 /*
53 * 変数の値を一定の範囲でループさせる (float)
54 */
55 inline void ValueCircular(
56 float *dest, // 対象値
57 float min, // 最小値
58 float max // 最大値
59 ){
60 float area = max-min, tmp = *dest-min;
61 *dest = tmp-area*(int)(tmp/area)+min;
62 }
63
64 /*
65 * 変数の値が一定の範囲内か調べる (int)
66 */
67 inline bool CheckValueArea(
68 int target, // 対象値
69 int min, // 最小値
70 int max // 最大値
71 ){
72 return (target>=min) && (target<=max);
73 }
74
75 /*
76 * 座標が一定矩形内にあるか調べる
77 */
78 inline bool CheckRect(
79 int tx, // 対象左上 x
80 int ty, // 対象左上 y
81 int x, // 矩形左上 x
82 int y, // 矩形左上 y
83 int w, // 矩形幅
84 int h // 矩形高さ
85 ){
86 tx -= x;
87 ty -= y;
88 return 0<=tx && tx<w && 0<=ty && ty<h;
89 }
90
91 #endif

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26