blob: e52c902a27facd544ed45b1f52bd957e883ca61f [file] [log] [blame]
Jason Sams6cc888e2011-04-22 17:05:25 -07001/*
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -05002 * Copyright (C) 2013 The Android Open Source Project
Jason Sams6cc888e2011-04-22 17:05:25 -07003 *
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
17package android.renderscript;
18
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070019/**
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050020 * Vector version of the basic double type.
21 * Provides three double fields packed.
Xusong Wang8b4548c2021-01-05 10:09:52 -080022 *
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 Delahaye6a5875c2013-09-10 15:11:35 -050026 */
Xusong Wang8b4548c2021-01-05 10:09:52 -080027@Deprecated
Jason Sams6cc888e2011-04-22 17:05:25 -070028public class Double3 {
Jason Sams6cc888e2011-04-22 17:05:25 -070029 public double x;
30 public double y;
31 public double z;
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050032
33 public Double3() {
34 }
35 /** @hide */
36 public Double3(Double3 data) {
37 this.x = data.x;
38 this.y = data.y;
39 this.z = data.z;
40 }
41
42 public Double3(double x, double y, double 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 */
55 public static Double3 add(Double3 a, Double3 b) {
56 Double3 res = new Double3();
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 */
69 public void add(Double3 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 */
80 public void add(double 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 */
93 public static Double3 add(Double3 a, double b) {
94 Double3 res = new Double3();
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 */
107 public void sub(Double3 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 */
120 public static Double3 sub(Double3 a, Double3 b) {
121 Double3 res = new Double3();
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 */
134 public void sub(double 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 */
147 public static Double3 sub(Double3 a, double b) {
148 Double3 res = new Double3();
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 */
161 public void mul(Double3 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 */
174 public static Double3 mul(Double3 a, Double3 b) {
175 Double3 res = new Double3();
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 */
188 public void mul(double 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 */
201 public static Double3 mul(Double3 a, double b) {
202 Double3 res = new Double3();
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 */
215 public void div(Double3 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 */
228 public static Double3 div(Double3 a, Double3 b) {
229 Double3 res = new Double3();
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 */
242 public void div(double 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 */
255 public static Double3 div(Double3 a, double b) {
256 Double3 res = new Double3();
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 */
270 public double dotProduct(Double3 a) {
271 return (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 */
281 public static double dotProduct(Double3 a, Double3 b) {
282 return (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 */
291 public void addMultiple(Double3 a, double 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 double3
299 *
300 * @param a
301 */
302 public void set(Double3 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 */
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 */
322 public int length() {
323 return 3;
324 }
325
326 /** @hide
327 * Return the element sum of vector
328 *
329 * @return
330 */
331 public double elementSum() {
332 return x + y + z;
333 }
334
335 /** @hide
336 * Get the vector field value by index
337 *
338 * @param i
339 * @return
340 */
341 public double 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 */
360 public void setAt(int i, double 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 */
382 public void addAt(int i, double 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 */
405 public void setValues(double x, double y, double z) {
406 this.x = x;
407 this.y = y;
408 this.z = z;
409 }
410
411 /** @hide
412 * Copy the vector to double array
413 *
414 * @param data
415 * @param offset
416 */
417 public void copyTo(double[] data, int offset) {
418 data[offset] = x;
419 data[offset + 1] = y;
420 data[offset + 2] = z;
421 }
Jason Sams6cc888e2011-04-22 17:05:25 -0700422}