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