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