Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
caa2d703
Commit
caa2d703
authored
Jun 19, 2026
by
Matthias Betz
Browse files
Add primitive growable FloatList/IntList for GL buffer building
parent
13e3e158
Changes
3
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/gl/FloatList.java
0 → 100644
View file @
caa2d703
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
java.util.Arrays
;
/** Growable primitive float array to avoid boxing when building large vertex buffers. */
public
class
FloatList
{
private
float
[]
data
;
private
int
size
;
public
FloatList
()
{
this
(
1024
);
}
public
FloatList
(
int
initialCapacity
)
{
data
=
new
float
[
Math
.
max
(
1
,
initialCapacity
)];
}
public
void
add
(
float
v
)
{
ensure
(
size
+
1
);
data
[
size
++]
=
v
;
}
public
void
add
(
float
a
,
float
b
,
float
c
)
{
ensure
(
size
+
3
);
data
[
size
++]
=
a
;
data
[
size
++]
=
b
;
data
[
size
++]
=
c
;
}
private
void
ensure
(
int
capacity
)
{
if
(
capacity
>
data
.
length
)
{
int
newCap
=
data
.
length
;
while
(
newCap
<
capacity
)
{
newCap
<<=
1
;
}
data
=
Arrays
.
copyOf
(
data
,
newCap
);
}
}
public
int
size
()
{
return
size
;
}
public
float
[]
toArray
()
{
return
Arrays
.
copyOf
(
data
,
size
);
}
}
CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/gl/IntList.java
0 → 100644
View file @
caa2d703
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
java.util.Arrays
;
/** Growable primitive int array. */
public
class
IntList
{
private
int
[]
data
;
private
int
size
;
public
IntList
()
{
this
(
1024
);
}
public
IntList
(
int
initialCapacity
)
{
data
=
new
int
[
Math
.
max
(
1
,
initialCapacity
)];
}
public
void
add
(
int
v
)
{
if
(
size
+
1
>
data
.
length
)
{
data
=
Arrays
.
copyOf
(
data
,
data
.
length
<<
1
);
}
data
[
size
++]
=
v
;
}
public
int
get
(
int
index
)
{
return
data
[
index
];
}
public
int
size
()
{
return
size
;
}
public
int
[]
toArray
()
{
return
Arrays
.
copyOf
(
data
,
size
);
}
}
CityDoctorParent/Extensions/CityDoctorGUI/src/test/java/de/hft/stuttgart/citydoctor2/gui/gl/FloatListTest.java
0 → 100644
View file @
caa2d703
package
de.hft.stuttgart.citydoctor2.gui.gl
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
public
class
FloatListTest
{
@Test
public
void
growsBeyondInitialCapacityAndPreservesOrder
()
{
FloatList
list
=
new
FloatList
(
2
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
list
.
add
(
i
);
}
assertEquals
(
10
,
list
.
size
());
float
[]
expected
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
assertArrayEquals
(
expected
,
list
.
toArray
(),
0.0f
);
}
@Test
public
void
addThreeAddsAllInOrder
()
{
FloatList
list
=
new
FloatList
(
1
);
list
.
add
(
1
f
,
2
f
,
3
f
);
assertArrayEquals
(
new
float
[]{
1
,
2
,
3
},
list
.
toArray
(),
0.0f
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment