blob: 52f7bb2c2461eb9b6542bdc2f57dfea51d684825 [file] [log] [blame]
Jason Sams25430d02010-02-02 15:26:40 -08001/*
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -05002 * Copyright (C) 2013 The Android Open Source Project
Jason Sams25430d02010-02-02 15:26:40 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070019/**
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050020 * Vector version of the basic int type.
21 * Provides four int fields packed.
Xusong Wang8b4548c2021-01-05 10:09:52 -080022 *
23 * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
24 * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
25 * guide</a> for the proposed alternatives.
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050026 */
Xusong Wang8b4548c2021-01-05 10:09:52 -080027@Deprecated
Jason Samsa70f4162010-03-26 15:33:42 -070028public class Int4 {
Jason Samsa70f4162010-03-26 15:33:42 -070029 public int x;
30 public int y;
31 public int z;
32 public int w;
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050033
34 public Int4() {
35 }
36
37 /** @hide */
38 public Int4(int i) {
39 this.x = this.y = this.z = this.w = i;
40 }
41
42 public Int4(int x, int y, int z, int w) {
43 this.x = x;
44 this.y = y;
45 this.z = z;
46 this.w = w;
47 }
48
49 /** @hide */
50 public Int4(Int4 source) {
51 this.x = source.x;
52 this.y = source.y;
53 this.z = source.z;
54 this.w = source.w;
55 }
56
57 /** @hide
58 * Vector add
59 *
60 * @param a
61 */
62 public void add(Int4 a) {
63 this.x += a.x;
64 this.y += a.y;
65 this.z += a.z;
66 this.w += a.w;
67 }
68
69 /** @hide
70 * Vector add
71 *
72 * @param a
73 * @param b
74 * @return
75 */
76 public static Int4 add(Int4 a, Int4 b) {
77 Int4 result = new Int4();
78 result.x = a.x + b.x;
79 result.y = a.y + b.y;
80 result.z = a.z + b.z;
81 result.w = a.w + b.w;
82
83 return result;
84 }
85
86 /** @hide
87 * Vector add
88 *
89 * @param value
90 */
91 public void add(int value) {
92 x += value;
93 y += value;
94 z += value;
95 w += value;
96 }
97
98 /** @hide
99 * Vector add
100 *
101 * @param a
102 * @param b
103 * @return
104 */
105 public static Int4 add(Int4 a, int b) {
106 Int4 result = new Int4();
107 result.x = a.x + b;
108 result.y = a.y + b;
109 result.z = a.z + b;
110 result.w = a.w + b;
111
112 return result;
113 }
114
115 /** @hide
116 * Vector subtraction
117 *
118 * @param a
119 */
120 public void sub(Int4 a) {
121 this.x -= a.x;
122 this.y -= a.y;
123 this.z -= a.z;
124 this.w -= a.w;
125 }
126
127 /** @hide
128 * Vector subtraction
129 *
130 * @param a
131 * @param b
132 * @return
133 */
134 public static Int4 sub(Int4 a, Int4 b) {
135 Int4 result = new Int4();
136 result.x = a.x - b.x;
137 result.y = a.y - b.y;
138 result.z = a.z - b.z;
139 result.w = a.w - b.w;
140
141 return result;
142 }
143
144 /** @hide
145 * Vector subtraction
146 *
147 * @param value
148 */
149 public void sub(int value) {
150 x -= value;
151 y -= value;
152 z -= value;
153 w -= value;
154 }
155
156 /** @hide
157 * Vector subtraction
158 *
159 * @param a
160 * @param b
161 * @return
162 */
163 public static Int4 sub(Int4 a, int b) {
164 Int4 result = new Int4();
165 result.x = a.x - b;
166 result.y = a.y - b;
167 result.z = a.z - b;
168 result.w = a.w - b;
169
170 return result;
171 }
172
173 /** @hide
174 * Vector multiplication
175 *
176 * @param a
177 */
178 public void mul(Int4 a) {
179 this.x *= a.x;
180 this.y *= a.y;
181 this.z *= a.z;
182 this.w *= a.w;
183 }
184
185 /** @hide
186 * Vector multiplication
187 *
188 * @param a
189 * @param b
190 * @return
191 */
192 public static Int4 mul(Int4 a, Int4 b) {
193 Int4 result = new Int4();
194 result.x = a.x * b.x;
195 result.y = a.y * b.y;
196 result.z = a.z * b.z;
197 result.w = a.w * b.w;
198
199 return result;
200 }
201
202 /** @hide
203 * Vector multiplication
204 *
205 * @param value
206 */
207 public void mul(int value) {
208 x *= value;
209 y *= value;
210 z *= value;
211 w *= value;
212 }
213
214 /** @hide
215 * Vector multiplication
216 *
217 * @param a
218 * @param b
219 * @return
220 */
221 public static Int4 mul(Int4 a, int b) {
222 Int4 result = new Int4();
223 result.x = a.x * b;
224 result.y = a.y * b;
225 result.z = a.z * b;
226 result.w = a.w * b;
227
228 return result;
229 }
230
231 /** @hide
232 * Vector division
233 *
234 * @param a
235 */
236 public void div(Int4 a) {
237 this.x /= a.x;
238 this.y /= a.y;
239 this.z /= a.z;
240 this.w /= a.w;
241 }
242
243 /** @hide
244 * Vector division
245 *
246 * @param a
247 * @param b
248 * @return
249 */
250 public static Int4 div(Int4 a, Int4 b) {
251 Int4 result = new Int4();
252 result.x = a.x / b.x;
253 result.y = a.y / b.y;
254 result.z = a.z / b.z;
255 result.w = a.w / b.w;
256
257 return result;
258 }
259
260 /** @hide
261 * Vector division
262 *
263 * @param value
264 */
265 public void div(int value) {
266 x /= value;
267 y /= value;
268 z /= value;
269 w /= value;
270 }
271
272 /** @hide
273 * Vector division
274 *
275 * @param a
276 * @param b
277 * @return
278 */
279 public static Int4 div(Int4 a, int b) {
280 Int4 result = new Int4();
281 result.x = a.x / b;
282 result.y = a.y / b;
283 result.z = a.z / b;
284 result.w = a.w / b;
285
286 return result;
287 }
288
289 /** @hide
290 * Vector Modulo
291 *
292 * @param a
293 */
294 public void mod(Int4 a) {
295 this.x %= a.x;
296 this.y %= a.y;
297 this.z %= a.z;
298 this.w %= a.w;
299 }
300
301 /** @hide
302 * Vector Modulo
303 *
304 * @param a
305 * @param b
306 * @return
307 */
308 public static Int4 mod(Int4 a, Int4 b) {
309 Int4 result = new Int4();
310 result.x = a.x % b.x;
311 result.y = a.y % b.y;
312 result.z = a.z % b.z;
313 result.w = a.w % b.w;
314
315 return result;
316 }
317
318 /** @hide
319 * Vector Modulo
320 *
321 * @param value
322 */
323 public void mod(int value) {
324 x %= value;
325 y %= value;
326 z %= value;
327 w %= value;
328 }
329
330 /** @hide
331 * Vector Modulo
332 *
333 * @param a
334 * @param b
335 * @return
336 */
337 public static Int4 mod(Int4 a, int b) {
338 Int4 result = new Int4();
339 result.x = a.x % b;
340 result.y = a.y % b;
341 result.z = a.z % b;
342 result.w = a.w % b;
343
344 return result;
345 }
346
347 /** @hide
348 * get vector length
349 *
350 * @return
351 */
352 public int length() {
353 return 4;
354 }
355
356 /** @hide
357 * set vector negate
358 */
359 public void negate() {
360 this.x = -x;
361 this.y = -y;
362 this.z = -z;
363 this.w = -w;
364 }
365
366 /** @hide
367 * Vector dot Product
368 *
369 * @param a
370 * @return
371 */
372 public int dotProduct(Int4 a) {
373 return (int)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
374 }
375
376 /** @hide
377 * Vector dot Product
378 *
379 * @param a
380 * @param b
381 * @return
382 */
383 public static int dotProduct(Int4 a, Int4 b) {
384 return (int)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
385 }
386
387 /** @hide
388 * Vector add Multiple
389 *
390 * @param a
391 * @param factor
392 */
393 public void addMultiple(Int4 a, int factor) {
394 x += a.x * factor;
395 y += a.y * factor;
396 z += a.z * factor;
397 w += a.w * factor;
398 }
399
400 /** @hide
401 * set vector value by Int4
402 *
403 * @param a
404 */
405 public void set(Int4 a) {
406 this.x = a.x;
407 this.y = a.y;
408 this.z = a.z;
409 this.w = a.w;
410 }
411
412 /** @hide
413 * set the vector field value by Int
414 *
415 * @param a
416 * @param b
417 * @param c
418 * @param d
419 */
420 public void setValues(int a, int b, int c, int d) {
421 this.x = a;
422 this.y = b;
423 this.z = c;
424 this.w = d;
425 }
426
427 /** @hide
428 * return the element sum of vector
429 *
430 * @return
431 */
432 public int elementSum() {
433 return (int)(x + y + z + w);
434 }
435
436 /** @hide
437 * get the vector field value by index
438 *
439 * @param i
440 * @return
441 */
442 public int get(int i) {
443 switch (i) {
444 case 0:
445 return (int)(x);
446 case 1:
447 return (int)(y);
448 case 2:
449 return (int)(z);
450 case 3:
451 return (int)(w);
452 default:
453 throw new IndexOutOfBoundsException("Index: i");
454 }
455 }
456
457 /** @hide
458 * set the vector field value by index
459 *
460 * @param i
461 * @param value
462 */
463 public void setAt(int i, int value) {
464 switch (i) {
465 case 0:
466 x = value;
467 return;
468 case 1:
469 y = value;
470 return;
471 case 2:
472 z = value;
473 return;
474 case 3:
475 w = value;
476 return;
477 default:
478 throw new IndexOutOfBoundsException("Index: i");
479 }
480 }
481
482 /** @hide
483 * add the vector field value by index
484 *
485 * @param i
486 * @param value
487 */
488 public void addAt(int i, int value) {
489 switch (i) {
490 case 0:
491 x += value;
492 return;
493 case 1:
494 y += value;
495 return;
496 case 2:
497 z += value;
498 return;
499 case 3:
500 w += value;
501 return;
502 default:
503 throw new IndexOutOfBoundsException("Index: i");
504 }
505 }
506
507 /** @hide
508 * copy the vector to int array
509 *
510 * @param data
511 * @param offset
512 */
513 public void copyTo(int[] data, int offset) {
514 data[offset] = (int)(x);
515 data[offset + 1] = (int)(y);
516 data[offset + 2] = (int)(z);
517 data[offset + 3] = (int)(w);
518 }
Jason Sams25430d02010-02-02 15:26:40 -0800519}