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 three 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 Long3 {
29     public long x;
30     public long y;
31     public long z;
32 
Long3()33     public Long3() {
34     }
35 
36     /** @hide */
Long3(long i)37     public Long3(long i) {
38         this.x = this.y = this.z = i;
39     }
40 
Long3(long x, long y, long z)41     public Long3(long x, long y, long z) {
42         this.x = x;
43         this.y = y;
44         this.z = z;
45     }
46 
47     /** @hide */
Long3(Long3 source)48     public Long3(Long3 source) {
49         this.x = source.x;
50         this.y = source.y;
51         this.z = source.z;
52     }
53 
54     /** @hide
55      * Vector add
56      *
57      * @param a
58      */
add(Long3 a)59     public void add(Long3 a) {
60         this.x += a.x;
61         this.y += a.y;
62         this.z += a.z;
63     }
64 
65     /** @hide
66      * Vector add
67      *
68      * @param a
69      * @param b
70      * @return
71      */
add(Long3 a, Long3 b)72     public static Long3 add(Long3 a, Long3 b) {
73         Long3 result = new Long3();
74         result.x = a.x + b.x;
75         result.y = a.y + b.y;
76         result.z = a.z + b.z;
77 
78         return result;
79     }
80 
81     /** @hide
82      * Vector add
83      *
84      * @param value
85      */
add(long value)86     public void add(long value) {
87         x += value;
88         y += value;
89         z += value;
90     }
91 
92     /** @hide
93      * Vector add
94      *
95      * @param a
96      * @param b
97      * @return
98      */
add(Long3 a, long b)99     public static Long3 add(Long3 a, long b) {
100         Long3 result = new Long3();
101         result.x = a.x + b;
102         result.y = a.y + b;
103         result.z = a.z + b;
104 
105         return result;
106     }
107 
108     /** @hide
109      * Vector subtraction
110      *
111      * @param a
112      */
sub(Long3 a)113     public void sub(Long3 a) {
114         this.x -= a.x;
115         this.y -= a.y;
116         this.z -= a.z;
117     }
118 
119     /** @hide
120      * Vector subtraction
121      *
122      * @param a
123      * @param b
124      * @return
125      */
sub(Long3 a, Long3 b)126     public static Long3 sub(Long3 a, Long3 b) {
127         Long3 result = new Long3();
128         result.x = a.x - b.x;
129         result.y = a.y - b.y;
130         result.z = a.z - b.z;
131 
132         return result;
133     }
134 
135     /** @hide
136      * Vector subtraction
137      *
138      * @param value
139      */
sub(long value)140     public void sub(long value) {
141         x -= value;
142         y -= value;
143         z -= value;
144     }
145 
146     /** @hide
147      * Vector subtraction
148      *
149      * @param a
150      * @param b
151      * @return
152      */
sub(Long3 a, long b)153     public static Long3 sub(Long3 a, long b) {
154         Long3 result = new Long3();
155         result.x = a.x - b;
156         result.y = a.y - b;
157         result.z = a.z - b;
158 
159         return result;
160     }
161 
162     /** @hide
163      * Vector multiplication
164      *
165      * @param a
166      */
mul(Long3 a)167     public void mul(Long3 a) {
168         this.x *= a.x;
169         this.y *= a.y;
170         this.z *= a.z;
171     }
172 
173     /** @hide
174      * Vector multiplication
175      *
176      * @param a
177      * @param b
178      * @return
179      */
mul(Long3 a, Long3 b)180     public static Long3 mul(Long3 a, Long3 b) {
181         Long3 result = new Long3();
182         result.x = a.x * b.x;
183         result.y = a.y * b.y;
184         result.z = a.z * b.z;
185 
186         return result;
187     }
188 
189     /** @hide
190      * Vector multiplication
191      *
192      * @param value
193      */
mul(long value)194     public void mul(long value) {
195         x *= value;
196         y *= value;
197         z *= value;
198     }
199 
200     /** @hide
201      * Vector multiplication
202      *
203      * @param a
204      * @param b
205      * @return
206      */
mul(Long3 a, long b)207     public static Long3 mul(Long3 a, long b) {
208         Long3 result = new Long3();
209         result.x = a.x * b;
210         result.y = a.y * b;
211         result.z = a.z * b;
212 
213         return result;
214     }
215 
216     /** @hide
217      * Vector division
218      *
219      * @param a
220      */
div(Long3 a)221     public void div(Long3 a) {
222         this.x /= a.x;
223         this.y /= a.y;
224         this.z /= a.z;
225     }
226 
227     /** @hide
228      * Vector division
229      *
230      * @param a
231      * @param b
232      * @return
233      */
div(Long3 a, Long3 b)234     public static Long3 div(Long3 a, Long3 b) {
235         Long3 result = new Long3();
236         result.x = a.x / b.x;
237         result.y = a.y / b.y;
238         result.z = a.z / b.z;
239 
240         return result;
241     }
242 
243     /** @hide
244      * Vector division
245      *
246      * @param value
247      */
div(long value)248     public void div(long value) {
249         x /= value;
250         y /= value;
251         z /= value;
252     }
253 
254     /** @hide
255      * Vector division
256      *
257      * @param a
258      * @param b
259      * @return
260      */
div(Long3 a, long b)261     public static Long3 div(Long3 a, long b) {
262         Long3 result = new Long3();
263         result.x = a.x / b;
264         result.y = a.y / b;
265         result.z = a.z / b;
266 
267         return result;
268     }
269 
270     /** @hide
271      * Vector Modulo
272      *
273      * @param a
274      */
mod(Long3 a)275     public void mod(Long3 a) {
276         this.x %= a.x;
277         this.y %= a.y;
278         this.z %= a.z;
279     }
280 
281     /** @hide
282      * Vector Modulo
283      *
284      * @param a
285      * @param b
286      * @return
287      */
mod(Long3 a, Long3 b)288     public static Long3 mod(Long3 a, Long3 b) {
289         Long3 result = new Long3();
290         result.x = a.x % b.x;
291         result.y = a.y % b.y;
292         result.z = a.z % b.z;
293 
294         return result;
295     }
296 
297     /** @hide
298      * Vector Modulo
299      *
300      * @param value
301      */
mod(long value)302     public void mod(long value) {
303         x %= value;
304         y %= value;
305         z %= value;
306     }
307 
308     /** @hide
309      * Vector Modulo
310      *
311      * @param a
312      * @param b
313      * @return
314      */
mod(Long3 a, long b)315     public static Long3 mod(Long3 a, long b) {
316         Long3 result = new Long3();
317         result.x = a.x % b;
318         result.y = a.y % b;
319         result.z = a.z % b;
320 
321         return result;
322     }
323 
324     /** @hide
325      * get vector length
326      *
327      * @return
328      */
length()329     public long length() {
330         return 3;
331     }
332 
333     /** @hide
334      * set vector negate
335      */
negate()336     public void negate() {
337         this.x = -x;
338         this.y = -y;
339         this.z = -z;
340     }
341 
342     /** @hide
343      * Vector dot Product
344      *
345      * @param a
346      * @return
347      */
dotProduct(Long3 a)348     public long dotProduct(Long3 a) {
349         return (long)((x * a.x) + (y * a.y) + (z * a.z));
350     }
351 
352     /** @hide
353      * Vector dot Product
354      *
355      * @param a
356      * @param b
357      * @return
358      */
dotProduct(Long3 a, Long3 b)359     public static long dotProduct(Long3 a, Long3 b) {
360         return (long)((b.x * a.x) + (b.y * a.y) + (b.z * a.z));
361     }
362 
363     /** @hide
364      * Vector add Multiple
365      *
366      * @param a
367      * @param factor
368      */
addMultiple(Long3 a, long factor)369     public void addMultiple(Long3 a, long factor) {
370         x += a.x * factor;
371         y += a.y * factor;
372         z += a.z * factor;
373     }
374 
375     /** @hide
376      * set vector value by Long3
377      *
378      * @param a
379      */
set(Long3 a)380     public void set(Long3 a) {
381         this.x = a.x;
382         this.y = a.y;
383         this.z = a.z;
384     }
385 
386     /** @hide
387      * set the vector field value by Long
388      *
389      * @param a
390      * @param b
391      * @param c
392      */
setValues(long a, long b, long c)393     public void setValues(long a, long b, long c) {
394         this.x = a;
395         this.y = b;
396         this.z = c;
397     }
398 
399     /** @hide
400      * return the element sum of vector
401      *
402      * @return
403      */
elementSum()404     public long elementSum() {
405         return (long)(x + y + z);
406     }
407 
408     /** @hide
409      * get the vector field value by index
410      *
411      * @param i
412      * @return
413      */
get(int i)414     public long get(int i) {
415         switch (i) {
416         case 0:
417             return (long)(x);
418         case 1:
419             return (long)(y);
420         case 2:
421             return (long)(z);
422         default:
423             throw new IndexOutOfBoundsException("Index: i");
424         }
425     }
426 
427     /** @hide
428      * set the vector field value by index
429      *
430      * @param i
431      * @param value
432      */
setAt(int i, long value)433     public void setAt(int i, long value) {
434         switch (i) {
435         case 0:
436             x = value;
437             return;
438         case 1:
439             y = value;
440             return;
441         case 2:
442             z = value;
443             return;
444         default:
445             throw new IndexOutOfBoundsException("Index: i");
446         }
447     }
448 
449     /** @hide
450      * add the vector field value by index
451      *
452      * @param i
453      * @param value
454      */
addAt(int i, long value)455     public void addAt(int i, long value) {
456         switch (i) {
457         case 0:
458             x += value;
459             return;
460         case 1:
461             y += value;
462             return;
463         case 2:
464             z += value;
465             return;
466         default:
467             throw new IndexOutOfBoundsException("Index: i");
468         }
469     }
470 
471     /** @hide
472      * copy the vector to long array
473      *
474      * @param data
475      * @param offset
476      */
copyTo(long[] data, int offset)477     public void copyTo(long[] data, int offset) {
478         data[offset] = (long)(x);
479         data[offset + 1] = (long)(y);
480         data[offset + 2] = (long)(z);
481     }
482 }
483