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 int type. 21 * Provides two int 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 Int2 { 29 public int x; 30 public int y; 31 Int2()32 public Int2() { 33 } 34 35 /** @hide */ Int2(int i)36 public Int2(int i) { 37 this.x = this.y = i; 38 } 39 Int2(int x, int y)40 public Int2(int x, int y) { 41 this.x = x; 42 this.y = y; 43 } 44 45 /** @hide */ Int2(Int2 source)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 */ add(Int2 a)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 */ add(Int2 a, Int2 b)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 */ add(int value)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 */ add(Int2 a, int b)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 */ sub(Int2 a)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 */ sub(Int2 a, Int2 b)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 */ sub(int value)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 */ sub(Int2 a, int b)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 */ mul(Int2 a)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 */ mul(Int2 a, Int2 b)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 */ mul(int value)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 */ mul(Int2 a, int b)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 */ div(Int2 a)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 */ div(Int2 a, Int2 b)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 */ div(int value)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 */ div(Int2 a, int b)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 */ mod(Int2 a)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 */ mod(Int2 a, Int2 b)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 */ mod(int value)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 */ mod(Int2 a, int b)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 */ length()306 public int length() { 307 return 2; 308 } 309 310 /** @hide 311 * set vector negate 312 */ negate()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 */ dotProduct(Int2 a)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 */ dotProduct(Int2 a, Int2 b)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 */ addMultiple(Int2 a, int factor)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 */ set(Int2 a)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 */ setValues(int a, int b)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 */ elementSum()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 */ get(int i)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 */ setAt(int i, int value)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 */ addAt(int i, int value)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 */ copyTo(int[] data, int offset)441 public void copyTo(int[] data, int offset) { 442 data[offset] = (int)(x); 443 data[offset + 1] = (int)(y); 444 } 445 } 446