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