-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.java
More file actions
100 lines (93 loc) · 1.75 KB
/
Vector.java
File metadata and controls
100 lines (93 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
class Vector {
public float x, y, z, w;
private float[] values;
private int len;
public Vector(int dim) {
if (dim < 2) {
return;
}
values = new float[dim];
for (int i = 0; i < dim; i++) {
values[i] = 0;
}
len = dim;
}
public Vector(float[] values) {
if (values.length < 2) {
return;
}
this.values = values;
len = values.length;
if (len > 1) {
x = values[0];
y = values[1];
}
if (len > 2) {
z = values[2];
}
if (len > 3) {
w = values[3];
}
}
public Vector(float x, float y) {
this.x = x;
this.y = y;
len = 2;
values = new float[2];
values[0] = x;
values[1] = y;
}
public Vector(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
len = 3;
values = new float[3];
values[0] = x;
values[1] = y;
values[2] = z;
}
public Vector(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
len = 4;
values = new float[4];
values[0] = x;
values[1] = y;
values[2] = z;
values[3] = w;
}
public int length() {
return len;
}
public float get(int index) {
if (index >= len || index < 0) {
return -9999999;
} else {
return values[index];
}
}
public void set(float value, int index) {
if (index >= len || index < 0) {
return;
} else {
values[index] = value;
}
}
public float[] toArray() {
return values;
}
public int maximum() {
int index = -1;
float max_value = -999999999;
for (int i = 0; i < len; i++) {
if (values[i] > max_value) {
max_value = values[i];
index = i;
}
}
return index;
}
}