blob: 070d608dc181937af460bd319f40454f3a930e97 [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
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050019/**
20 * Vector version of the basic short type.
21 * Provides two short fields packed.
22 */
Jason Samsa70f4162010-03-26 15:33:42 -070023public class Short2 {
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050024 public short x;
25 public short y;
26
Jason Samsa70f4162010-03-26 15:33:42 -070027 public Short2() {
Jason Sams25430d02010-02-02 15:26:40 -080028 }
29
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050030 /** @hide */
31 public Short2(short i) {
32 this.x = this.y = i;
Jason Sams6cc888e2011-04-22 17:05:25 -070033 }
34
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050035 public Short2(short x, short y) {
36 this.x = x;
37 this.y = y;
38 }
39
40 /** @hide */
41 public Short2(Short2 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(Short2 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 Short2 add(Short2 a, Short2 b) {
64 Short2 result = new Short2();
65 result.x = (short)(a.x + b.x);
66 result.y = (short)(a.y + b.y);
67
68 return result;
69 }
70
71 /** @hide
72 * Vector add
73 *
74 * @param value
75 */
76 public void add(short 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 Short2 add(Short2 a, short b) {
89 Short2 result = new Short2();
90 result.x = (short)(a.x + b);
91 result.y = (short)(a.y + b);
92
93 return result;
94 }
95
96 /** @hide
97 * Vector subtraction
98 *
99 * @param a
100 */
101 public void sub(Short2 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 Short2 sub(Short2 a, Short2 b) {
114 Short2 result = new Short2();
115 result.x = (short)(a.x - b.x);
116 result.y = (short)(a.y - b.y);
117
118 return result;
119 }
120
121 /** @hide
122 * Vector subtraction
123 *
124 * @param value
125 */
126 public void sub(short 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 Short2 sub(Short2 a, short b) {
139 Short2 result = new Short2();
140 result.x = (short)(a.x - b);
141 result.y = (short)(a.y - b);
142
143 return result;
144 }
145
146 /** @hide
147 * Vector multiplication
148 *
149 * @param a
150 */
151 public void mul(Short2 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 Short2 mul(Short2 a, Short2 b) {
164 Short2 result = new Short2();
165 result.x = (short)(a.x * b.x);
166 result.y = (short)(a.y * b.y);
167
168 return result;
169 }
170
171 /** @hide
172 * Vector multiplication
173 *
174 * @param value
175 */
176 public void mul(short 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 Short2 mul(Short2 a, short b) {
189 Short2 result = new Short2();
190 result.x = (short)(a.x * b);
191 result.y = (short)(a.y * b);
192
193 return result;
194 }
195
196 /** @hide
197 * Vector division
198 *
199 * @param a
200 */
201 public void div(Short2 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 Short2 div(Short2 a, Short2 b) {
214 Short2 result = new Short2();
215 result.x = (short)(a.x / b.x);
216 result.y = (short)(a.y / b.y);
217
218 return result;
219 }
220
221 /** @hide
222 * Vector division
223 *
224 * @param value
225 */
226 public void div(short 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 Short2 div(Short2 a, short b) {
239 Short2 result = new Short2();
240 result.x = (short)(a.x / b);
241 result.y = (short)(a.y / b);
242
243 return result;
244 }
245
246 /** @hide
247 * Vector Modulo
248 *
249 * @param a
250 */
251 public void mod(Short2 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 Short2 mod(Short2 a, Short2 b) {
264 Short2 result = new Short2();
265 result.x = (short)(a.x % b.x);
266 result.y = (short)(a.y % b.y);
267
268 return result;
269 }
270
271 /** @hide
272 * Vector Modulo
273 *
274 * @param value
275 */
276 public void mod(short 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 Short2 mod(Short2 a, short b) {
289 Short2 result = new Short2();
290 result.x = (short)(a.x % b);
291 result.y = (short)(a.y % b);
292
293 return result;
294 }
295
296 /** @hide
297 * get vector length
298 *
299 * @return
300 */
301 public short length() {
302 return 2;
303 }
304
305 /** @hide
306 * set vector negate
307 */
308 public void negate() {
309 this.x = (short)(-x);
310 this.y = (short)(-y);
311 }
312
313 /** @hide
314 * Vector dot Product
315 *
316 * @param a
317 * @return
318 */
319 public short dotProduct(Short2 a) {
320 return (short)((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 short dotProduct(Short2 a, Short2 b) {
331 return (short)((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(Short2 a, short factor) {
341 x += a.x * factor;
342 y += a.y * factor;
343 }
344
345 /** @hide
346 * set vector value by Short2
347 *
348 * @param a
349 */
350 public void set(Short2 a) {
351 this.x = a.x;
352 this.y = a.y;
353 }
354
355 /** @hide
356 * set the vector field value by Short
357 *
358 * @param a
359 * @param b
360 */
361 public void setValues(short a, short 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 short elementSum() {
372 return (short)(x + y);
373 }
374
375 /** @hide
376 * get the vector field value by index
377 *
378 * @param i
379 * @return
380 */
381 public short get(int i) {
382 switch (i) {
383 case 0:
384 return (short)(x);
385 case 1:
386 return (short)(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, short 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, short 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 short array
432 *
433 * @param data
434 * @param offset
435 */
436 public void copyTo(short[] data, int offset) {
437 data[offset] = (short)(x);
438 data[offset + 1] = (short)(y);
439 }
Jason Sams25430d02010-02-02 15:26:40 -0800440}