Jason Sams | 25430d0 | 2010-02-02 15:26:40 -0800 | [diff] [blame] | 1 | /* |
Matthieu Delahaye | 6a5875c | 2013-09-10 15:11:35 -0500 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Jason Sams | 25430d0 | 2010-02-02 15:26:40 -0800 | [diff] [blame] | 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 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 19 | /** |
Matthieu Delahaye | 6a5875c | 2013-09-10 15:11:35 -0500 | [diff] [blame] | 20 | * Vector version of the basic int type. |
| 21 | * Provides three int fields packed. |
Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 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. |
Matthieu Delahaye | 6a5875c | 2013-09-10 15:11:35 -0500 | [diff] [blame] | 26 | */ |
Xusong Wang | 1f8dc65 | 2021-01-05 10:09:52 -0800 | [diff] [blame] | 27 | @Deprecated |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 28 | public class Int3 { |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 29 | public int x; |
| 30 | public int y; |
| 31 | public int z; |
Matthieu Delahaye | 6a5875c | 2013-09-10 15:11:35 -0500 | [diff] [blame] | 32 | |
| 33 | public Int3() { |
| 34 | } |
Jason Sams | afb0226 | 2013-11-27 15:30:06 -0800 | [diff] [blame] | 35 | |
Matthieu Delahaye | 6a5875c | 2013-09-10 15:11:35 -0500 | [diff] [blame] | 36 | /** @hide */ |
| 37 | public Int3(int i) { |
| 38 | this.x = this.y = this.z = i; |
| 39 | } |
| 40 | |
| 41 | public Int3(int x, int y, int z) { |
| 42 | this.x = x; |
| 43 | this.y = y; |
| 44 | this.z = z; |
| 45 | } |
| 46 | |
| 47 | /** @hide */ |
| 48 | public Int3(Int3 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 | */ |
| 59 | public void add(Int3 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 | */ |
| 72 | public static Int3 add(Int3 a, Int3 b) { |
| 73 | Int3 result = new Int3(); |
| 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 | */ |
| 86 | public void add(int 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 | */ |
| 99 | public static Int3 add(Int3 a, int b) { |
| 100 | Int3 result = new Int3(); |
| 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 | */ |
| 113 | public void sub(Int3 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 | */ |
| 126 | public static Int3 sub(Int3 a, Int3 b) { |
| 127 | Int3 result = new Int3(); |
| 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 | */ |
| 140 | public void sub(int 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 | */ |
| 153 | public static Int3 sub(Int3 a, int b) { |
| 154 | Int3 result = new Int3(); |
| 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 | */ |
| 167 | public void mul(Int3 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 | */ |
| 180 | public static Int3 mul(Int3 a, Int3 b) { |
| 181 | Int3 result = new Int3(); |
| 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 | */ |
| 194 | public void mul(int 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 | */ |
| 207 | public static Int3 mul(Int3 a, int b) { |
| 208 | Int3 result = new Int3(); |
| 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 | */ |
| 221 | public void div(Int3 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 | */ |
| 234 | public static Int3 div(Int3 a, Int3 b) { |
| 235 | Int3 result = new Int3(); |
| 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 | */ |
| 248 | public void div(int 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 | */ |
| 261 | public static Int3 div(Int3 a, int b) { |
| 262 | Int3 result = new Int3(); |
| 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 | */ |
| 275 | public void mod(Int3 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 | */ |
| 288 | public static Int3 mod(Int3 a, Int3 b) { |
| 289 | Int3 result = new Int3(); |
| 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 | */ |
| 302 | public void mod(int 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 | */ |
| 315 | public static Int3 mod(Int3 a, int b) { |
| 316 | Int3 result = new Int3(); |
| 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 | */ |
| 329 | public int length() { |
| 330 | return 3; |
| 331 | } |
| 332 | |
| 333 | /** @hide |
| 334 | * set vector negate |
| 335 | */ |
| 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 | */ |
| 348 | public int dotProduct(Int3 a) { |
| 349 | return (int)((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 | */ |
| 359 | public static int dotProduct(Int3 a, Int3 b) { |
| 360 | return (int)((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 | */ |
| 369 | public void addMultiple(Int3 a, int 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 Int3 |
| 377 | * |
| 378 | * @param a |
| 379 | */ |
| 380 | public void set(Int3 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 Int |
| 388 | * |
| 389 | * @param a |
| 390 | * @param b |
| 391 | * @param c |
| 392 | */ |
| 393 | public void setValues(int a, int b, int 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 | */ |
| 404 | public int elementSum() { |
| 405 | return (int)(x + y + z); |
| 406 | } |
| 407 | |
| 408 | /** @hide |
| 409 | * get the vector field value by index |
| 410 | * |
| 411 | * @param i |
| 412 | * @return |
| 413 | */ |
| 414 | public int get(int i) { |
| 415 | switch (i) { |
| 416 | case 0: |
| 417 | return (int)(x); |
| 418 | case 1: |
| 419 | return (int)(y); |
| 420 | case 2: |
| 421 | return (int)(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 | */ |
| 433 | public void setAt(int i, int 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 | */ |
| 455 | public void addAt(int i, int 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 int array |
| 473 | * |
| 474 | * @param data |
| 475 | * @param offset |
| 476 | */ |
| 477 | public void copyTo(int[] data, int offset) { |
| 478 | data[offset] = (int)(x); |
| 479 | data[offset + 1] = (int)(y); |
| 480 | data[offset + 2] = (int)(z); |
| 481 | } |
Jason Sams | 25430d0 | 2010-02-02 15:26:40 -0800 | [diff] [blame] | 482 | } |