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