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 short type. 21 * Provides three short 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 Short3 { 29 public short x; 30 public short y; 31 public short z; 32 Short3()33 public Short3() { 34 } 35 36 /** @hide */ Short3(short i)37 public Short3(short i) { 38 this.x = this.y = this.z = i; 39 } 40 Short3(short x, short y, short z)41 public Short3(short x, short y, short z) { 42 this.x = x; 43 this.y = y; 44 this.z = z; 45 } 46 47 /** @hide */ Short3(Short3 source)48 public Short3(Short3 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(Short3 a)59 public void add(Short3 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(Short3 a, Short3 b)72 public static Short3 add(Short3 a, Short3 b) { 73 Short3 result = new Short3(); 74 result.x = (short)(a.x + b.x); 75 result.y = (short)(a.y + b.y); 76 result.z = (short)(a.z + b.z); 77 78 return result; 79 } 80 81 /** @hide 82 * Vector add 83 * 84 * @param value 85 */ add(short value)86 public void add(short 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(Short3 a, short b)99 public static Short3 add(Short3 a, short b) { 100 Short3 result = new Short3(); 101 result.x = (short)(a.x + b); 102 result.y = (short)(a.y + b); 103 result.z = (short)(a.z + b); 104 105 return result; 106 } 107 108 /** @hide 109 * Vector subtraction 110 * 111 * @param a 112 */ sub(Short3 a)113 public void sub(Short3 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(Short3 a, Short3 b)126 public static Short3 sub(Short3 a, Short3 b) { 127 Short3 result = new Short3(); 128 result.x = (short)(a.x - b.x); 129 result.y = (short)(a.y - b.y); 130 result.z = (short)(a.z - b.z); 131 132 return result; 133 } 134 135 /** @hide 136 * Vector subtraction 137 * 138 * @param value 139 */ sub(short value)140 public void sub(short 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(Short3 a, short b)153 public static Short3 sub(Short3 a, short b) { 154 Short3 result = new Short3(); 155 result.x = (short)(a.x - b); 156 result.y = (short)(a.y - b); 157 result.z = (short)(a.z - b); 158 159 return result; 160 } 161 162 /** @hide 163 * Vector multiplication 164 * 165 * @param a 166 */ mul(Short3 a)167 public void mul(Short3 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(Short3 a, Short3 b)180 public static Short3 mul(Short3 a, Short3 b) { 181 Short3 result = new Short3(); 182 result.x = (short)(a.x * b.x); 183 result.y = (short)(a.y * b.y); 184 result.z = (short)(a.z * b.z); 185 186 return result; 187 } 188 189 /** @hide 190 * Vector multiplication 191 * 192 * @param value 193 */ mul(short value)194 public void mul(short 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(Short3 a, short b)207 public static Short3 mul(Short3 a, short b) { 208 Short3 result = new Short3(); 209 result.x = (short)(a.x * b); 210 result.y = (short)(a.y * b); 211 result.z = (short)(a.z * b); 212 213 return result; 214 } 215 216 /** @hide 217 * Vector division 218 * 219 * @param a 220 */ div(Short3 a)221 public void div(Short3 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(Short3 a, Short3 b)234 public static Short3 div(Short3 a, Short3 b) { 235 Short3 result = new Short3(); 236 result.x = (short)(a.x / b.x); 237 result.y = (short)(a.y / b.y); 238 result.z = (short)(a.z / b.z); 239 240 return result; 241 } 242 243 /** @hide 244 * Vector division 245 * 246 * @param value 247 */ div(short value)248 public void div(short 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(Short3 a, short b)261 public static Short3 div(Short3 a, short b) { 262 Short3 result = new Short3(); 263 result.x = (short)(a.x / b); 264 result.y = (short)(a.y / b); 265 result.z = (short)(a.z / b); 266 267 return result; 268 } 269 270 /** @hide 271 * Vector Modulo 272 * 273 * @param a 274 */ mod(Short3 a)275 public void mod(Short3 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(Short3 a, Short3 b)288 public static Short3 mod(Short3 a, Short3 b) { 289 Short3 result = new Short3(); 290 result.x = (short)(a.x % b.x); 291 result.y = (short)(a.y % b.y); 292 result.z = (short)(a.z % b.z); 293 294 return result; 295 } 296 297 /** @hide 298 * Vector Modulo 299 * 300 * @param value 301 */ mod(short value)302 public void mod(short 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(Short3 a, short b)315 public static Short3 mod(Short3 a, short b) { 316 Short3 result = new Short3(); 317 result.x = (short)(a.x % b); 318 result.y = (short)(a.y % b); 319 result.z = (short)(a.z % b); 320 321 return result; 322 } 323 324 /** @hide 325 * get vector length 326 * 327 * @return 328 */ length()329 public short length() { 330 return 3; 331 } 332 333 /** @hide 334 * set vector negate 335 */ negate()336 public void negate() { 337 this.x = (short)(-x); 338 this.y = (short)(-y); 339 this.z = (short)(-z); 340 } 341 342 /** @hide 343 * Vector dot Product 344 * 345 * @param a 346 * @return 347 */ dotProduct(Short3 a)348 public short dotProduct(Short3 a) { 349 return (short)((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(Short3 a, Short3 b)359 public static short dotProduct(Short3 a, Short3 b) { 360 return (short)((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(Short3 a, short factor)369 public void addMultiple(Short3 a, short 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 Short3 377 * 378 * @param a 379 */ set(Short3 a)380 public void set(Short3 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 Short 388 * 389 * @param a 390 * @param b 391 * @param c 392 */ setValues(short a, short b, short c)393 public void setValues(short a, short b, short 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 short elementSum() { 405 return (short)(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 short get(int i) { 415 switch (i) { 416 case 0: 417 return (short)(x); 418 case 1: 419 return (short)(y); 420 case 2: 421 return (short)(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, short value)433 public void setAt(int i, short 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, short value)455 public void addAt(int i, short 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 short array 473 * 474 * @param data 475 * @param offset 476 */ copyTo(short[] data, int offset)477 public void copyTo(short[] data, int offset) { 478 data[offset] = (short)(x); 479 data[offset + 1] = (short)(y); 480 data[offset + 2] = (short)(z); 481 } 482 } 483