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 long type. 21 * Provides two long 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 Long2 { 29 public long x; 30 public long y; 31 Long2()32 public Long2() { 33 } 34 35 /** @hide */ Long2(long i)36 public Long2(long i) { 37 this.x = this.y = i; 38 } 39 Long2(long x, long y)40 public Long2(long x, long y) { 41 this.x = x; 42 this.y = y; 43 } 44 45 /** @hide */ Long2(Long2 source)46 public Long2(Long2 source) { 47 this.x = source.x; 48 this.y = source.y; 49 } 50 51 /** @hide 52 * Vector add 53 * 54 * @param a 55 */ add(Long2 a)56 public void add(Long2 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(Long2 a, Long2 b)68 public static Long2 add(Long2 a, Long2 b) { 69 Long2 result = new Long2(); 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(long value)81 public void add(long 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(Long2 a, long b)93 public static Long2 add(Long2 a, long b) { 94 Long2 result = new Long2(); 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(Long2 a)106 public void sub(Long2 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(Long2 a, Long2 b)118 public static Long2 sub(Long2 a, Long2 b) { 119 Long2 result = new Long2(); 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(long value)131 public void sub(long 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(Long2 a, long b)143 public static Long2 sub(Long2 a, long b) { 144 Long2 result = new Long2(); 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(Long2 a)156 public void mul(Long2 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(Long2 a, Long2 b)168 public static Long2 mul(Long2 a, Long2 b) { 169 Long2 result = new Long2(); 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(long value)181 public void mul(long 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(Long2 a, long b)193 public static Long2 mul(Long2 a, long b) { 194 Long2 result = new Long2(); 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(Long2 a)206 public void div(Long2 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(Long2 a, Long2 b)218 public static Long2 div(Long2 a, Long2 b) { 219 Long2 result = new Long2(); 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(long value)231 public void div(long 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(Long2 a, long b)243 public static Long2 div(Long2 a, long b) { 244 Long2 result = new Long2(); 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(Long2 a)256 public void mod(Long2 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(Long2 a, Long2 b)268 public static Long2 mod(Long2 a, Long2 b) { 269 Long2 result = new Long2(); 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(long value)281 public void mod(long 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(Long2 a, long b)293 public static Long2 mod(Long2 a, long b) { 294 Long2 result = new Long2(); 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 long 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(Long2 a)324 public long dotProduct(Long2 a) { 325 return (long)((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(Long2 a, Long2 b)335 public static long dotProduct(Long2 a, Long2 b) { 336 return (long)((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(Long2 a, long factor)345 public void addMultiple(Long2 a, long factor) { 346 x += a.x * factor; 347 y += a.y * factor; 348 } 349 350 /** @hide 351 * set vector value by Long2 352 * 353 * @param a 354 */ set(Long2 a)355 public void set(Long2 a) { 356 this.x = a.x; 357 this.y = a.y; 358 } 359 360 /** @hide 361 * set the vector field value by Long 362 * 363 * @param a 364 * @param b 365 */ setValues(long a, long b)366 public void setValues(long a, long 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 long elementSum() { 377 return (long)(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 long get(int i) { 387 switch (i) { 388 case 0: 389 return (long)(x); 390 case 1: 391 return (long)(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, long value)403 public void setAt(int i, long 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, long value)422 public void addAt(int i, long 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 long array 437 * 438 * @param data 439 * @param offset 440 */ copyTo(long[] data, int offset)441 public void copyTo(long[] data, int offset) { 442 data[offset] = (long)(x); 443 data[offset + 1] = (long)(y); 444 } 445 } 446