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