1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
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 
17 package android.renderscript;
18 
19 /**
20  * Vector version of the basic long type.
21  * Provides four long fields packed.
22  *
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.
26  */
27 @Deprecated
28 public class Long4 {
29     public long x;
30     public long y;
31     public long z;
32     public long w;
33 
Long4()34     public Long4() {
35     }
36 
37     /** @hide */
Long4(long i)38     public Long4(long i) {
39         this.x = this.y = this.z = this.w = i;
40     }
41 
Long4(long x, long y, long z, long w)42     public Long4(long x, long y, long z, long w) {
43         this.x = x;
44         this.y = y;
45         this.z = z;
46         this.w = w;
47     }
48 
49     /** @hide */
Long4(Long4 source)50     public Long4(Long4 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      */
add(Long4 a)62     public void add(Long4 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      */
add(Long4 a, Long4 b)76     public static Long4 add(Long4 a, Long4 b) {
77         Long4 result = new Long4();
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      */
add(long value)91     public void add(long 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      */
add(Long4 a, long b)105     public static Long4 add(Long4 a, long b) {
106         Long4 result = new Long4();
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      */
sub(Long4 a)120     public void sub(Long4 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      */
sub(Long4 a, Long4 b)134     public static Long4 sub(Long4 a, Long4 b) {
135         Long4 result = new Long4();
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      */
sub(long value)149     public void sub(long 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      */
sub(Long4 a, long b)163     public static Long4 sub(Long4 a, long b) {
164         Long4 result = new Long4();
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      */
mul(Long4 a)178     public void mul(Long4 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      */
mul(Long4 a, Long4 b)192     public static Long4 mul(Long4 a, Long4 b) {
193         Long4 result = new Long4();
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      */
mul(long value)207     public void mul(long 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      */
mul(Long4 a, long b)221     public static Long4 mul(Long4 a, long b) {
222         Long4 result = new Long4();
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      */
div(Long4 a)236     public void div(Long4 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      */
div(Long4 a, Long4 b)250     public static Long4 div(Long4 a, Long4 b) {
251         Long4 result = new Long4();
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      */
div(long value)265     public void div(long 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      */
div(Long4 a, long b)279     public static Long4 div(Long4 a, long b) {
280         Long4 result = new Long4();
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      */
mod(Long4 a)294     public void mod(Long4 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      */
mod(Long4 a, Long4 b)308     public static Long4 mod(Long4 a, Long4 b) {
309         Long4 result = new Long4();
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      */
mod(long value)323     public void mod(long 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      */
mod(Long4 a, long b)337     public static Long4 mod(Long4 a, long b) {
338         Long4 result = new Long4();
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      */
length()352     public long length() {
353         return 4;
354     }
355 
356     /** @hide
357      * set vector negate
358      */
negate()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      */
dotProduct(Long4 a)372     public long dotProduct(Long4 a) {
373         return (long)((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      */
dotProduct(Long4 a, Long4 b)383     public static long dotProduct(Long4 a, Long4 b) {
384         return (long)((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      */
addMultiple(Long4 a, long factor)393     public void addMultiple(Long4 a, long 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 Long4
402      *
403      * @param a
404      */
set(Long4 a)405     public void set(Long4 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 Long
414      *
415      * @param a
416      * @param b
417      * @param c
418      * @param d
419      */
setValues(long a, long b, long c, long d)420     public void setValues(long a, long b, long c, long 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      */
elementSum()432     public long elementSum() {
433         return (long)(x + y + z + w);
434     }
435 
436     /** @hide
437      * get the vector field value by index
438      *
439      * @param i
440      * @return
441      */
get(int i)442     public long get(int i) {
443         switch (i) {
444         case 0:
445             return (long)(x);
446         case 1:
447             return (long)(y);
448         case 2:
449             return (long)(z);
450         case 3:
451             return (long)(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      */
setAt(int i, long value)463     public void setAt(int i, long 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      */
addAt(int i, long value)488     public void addAt(int i, long 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 long array
509      *
510      * @param data
511      * @param offset
512      */
copyTo(long[] data, int offset)513     public void copyTo(long[] data, int offset) {
514         data[offset] = (long)(x);
515         data[offset + 1] = (long)(y);
516         data[offset + 2] = (long)(z);
517         data[offset + 3] = (long)(w);
518     }
519 }
520