xref: /inferno-os/libmemdraw/icossin.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 #include	"lib9.h"
2 #include	"draw.h"
3 
4 /*
5  * Integer sine and cosine for integral degree argument.
6  * Tables computed by (sin,cos)(PI*d/180).
7  */
8 static short sinus[91] = {
9 	0,	/* 0 */
10 	18,	/* 1 */
11 	36,	/* 2 */
12 	54,	/* 3 */
13 	71,	/* 4 */
14 	89,	/* 5 */
15 	107,	/* 6 */
16 	125,	/* 7 */
17 	143,	/* 8 */
18 	160,	/* 9 */
19 	178,	/* 10 */
20 	195,	/* 11 */
21 	213,	/* 12 */
22 	230,	/* 13 */
23 	248,	/* 14 */
24 	265,	/* 15 */
25 	282,	/* 16 */
26 	299,	/* 17 */
27 	316,	/* 18 */
28 	333,	/* 19 */
29 	350,	/* 20 */
30 	367,	/* 21 */
31 	384,	/* 22 */
32 	400,	/* 23 */
33 	416,	/* 24 */
34 	433,	/* 25 */
35 	449,	/* 26 */
36 	465,	/* 27 */
37 	481,	/* 28 */
38 	496,	/* 29 */
39 	512,	/* 30 */
40 	527,	/* 31 */
41 	543,	/* 32 */
42 	558,	/* 33 */
43 	573,	/* 34 */
44 	587,	/* 35 */
45 	602,	/* 36 */
46 	616,	/* 37 */
47 	630,	/* 38 */
48 	644,	/* 39 */
49 	658,	/* 40 */
50 	672,	/* 41 */
51 	685,	/* 42 */
52 	698,	/* 43 */
53 	711,	/* 44 */
54 	724,	/* 45 */
55 	737,	/* 46 */
56 	749,	/* 47 */
57 	761,	/* 48 */
58 	773,	/* 49 */
59 	784,	/* 50 */
60 	796,	/* 51 */
61 	807,	/* 52 */
62 	818,	/* 53 */
63 	828,	/* 54 */
64 	839,	/* 55 */
65 	849,	/* 56 */
66 	859,	/* 57 */
67 	868,	/* 58 */
68 	878,	/* 59 */
69 	887,	/* 60 */
70 	896,	/* 61 */
71 	904,	/* 62 */
72 	912,	/* 63 */
73 	920,	/* 64 */
74 	928,	/* 65 */
75 	935,	/* 66 */
76 	943,	/* 67 */
77 	949,	/* 68 */
78 	956,	/* 69 */
79 	962,	/* 70 */
80 	968,	/* 71 */
81 	974,	/* 72 */
82 	979,	/* 73 */
83 	984,	/* 74 */
84 	989,	/* 75 */
85 	994,	/* 76 */
86 	998,	/* 77 */
87 	1002,	/* 78 */
88 	1005,	/* 79 */
89 	1008,	/* 80 */
90 	1011,	/* 81 */
91 	1014,	/* 82 */
92 	1016,	/* 83 */
93 	1018,	/* 84 */
94 	1020,	/* 85 */
95 	1022,	/* 86 */
96 	1023,	/* 87 */
97 	1023,	/* 88 */
98 	1024,	/* 89 */
99 	1024,	/* 90 */
100 };
101 
102 void
icossin(int deg,int * cosp,int * sinp)103 icossin(int deg, int *cosp, int *sinp)
104 {
105 	int sinsign, cossign;
106 	short *stp, *ctp;
107 
108 	deg %= 360;
109 	if(deg < 0)
110 		deg += 360;
111 	sinsign = 1;
112 	cossign = 1;
113 	stp = 0;
114 	ctp = 0;
115 	switch(deg/90){
116 	case 2:
117 		sinsign = -1;
118 		cossign = -1;
119 		deg -= 180;
120 		/* fall through */
121 	case 0:
122 		stp = &sinus[deg];
123 		ctp = &sinus[90-deg];
124 		break;
125 	case 3:
126 		sinsign = -1;
127 		cossign = -1;
128 		deg -= 180;
129 		/* fall through */
130 	case 1:
131 		deg = 180-deg;
132 		cossign = -cossign;
133 		stp = &sinus[deg];
134 		ctp = &sinus[90-deg];
135 		break;
136 	}
137 	*sinp = sinsign*stp[0];
138 	*cosp = cossign*ctp[0];
139 }
140