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 float type. 21 * Provides four float 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 Float4 { 29 public float x; 30 public float y; 31 public float z; 32 public float w; 33 Float4()34 public Float4() { 35 } 36 /** @hide */ Float4(Float4 data)37 public Float4(Float4 data) { 38 this.x = data.x; 39 this.y = data.y; 40 this.z = data.z; 41 this.w = data.w; 42 } 43 Float4(float x, float y, float z, float w)44 public Float4(float x, float y, float z, float 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 */ add(Float4 a, Float4 b)58 public static Float4 add(Float4 a, Float4 b) { 59 Float4 res = new Float4(); 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 */ add(Float4 value)73 public void add(Float4 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 */ add(float value)85 public void add(float 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 */ add(Float4 a, float b)99 public static Float4 add(Float4 a, float b) { 100 Float4 res = new Float4(); 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 */ sub(Float4 value)114 public void sub(Float4 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 */ sub(float value)126 public void sub(float 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 */ sub(Float4 a, float b)140 public static Float4 sub(Float4 a, float b) { 141 Float4 res = new Float4(); 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 */ sub(Float4 a, Float4 b)157 public static Float4 sub(Float4 a, Float4 b) { 158 Float4 res = new Float4(); 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 */ mul(Float4 value)172 public void mul(Float4 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 */ mul(float value)184 public void mul(float 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 */ mul(Float4 a, Float4 b)198 public static Float4 mul(Float4 a, Float4 b) { 199 Float4 res = new Float4(); 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 */ mul(Float4 a, float b)215 public static Float4 mul(Float4 a, float b) { 216 Float4 res = new Float4(); 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 */ div(Float4 value)230 public void div(Float4 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 */ div(float value)242 public void div(float 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 */ div(Float4 a, float b)256 public static Float4 div(Float4 a, float b) { 257 Float4 res = new Float4(); 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 */ div(Float4 a, Float4 b)273 public static Float4 div(Float4 a, Float4 b) { 274 Float4 res = new Float4(); 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 */ dotProduct(Float4 a)289 public float dotProduct(Float4 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 */ dotProduct(Float4 a, Float4 b)300 public static float dotProduct(Float4 a, Float4 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 */ addMultiple(Float4 a, float factor)310 public void addMultiple(Float4 a, float 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 float4 319 * 320 * @param a 321 */ set(Float4 a)322 public void set(Float4 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 */ negate()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 */ length()344 public int length() { 345 return 4; 346 } 347 348 /** @hide 349 * return the element sum of vector 350 * 351 * @return 352 */ elementSum()353 public float 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 */ get(int i)363 public float 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 */ setAt(int i, float value)384 public void setAt(int i, float 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 */ addAt(int i, float value)409 public void addAt(int i, float 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 */ setValues(float x, float y, float z, float w)436 public void setValues(float x, float y, float z, float 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 float array 445 * 446 * @param data 447 * @param offset 448 */ copyTo(float[] data, int offset)449 public void copyTo(float[] data, int offset) { 450 data[offset] = x; 451 data[offset + 1] = y; 452 data[offset + 2] = z; 453 data[offset + 3] = w; 454 } 455 } 456