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