Skip to content

Commit

Permalink
Rename and fix initing array filled size pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Nov 21, 2024
1 parent 1dc4361 commit 78f2057
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ComplexCollisionBox implements CollisionBox {
// Most complex shape is the Modern MC Cauldron which is made up of 15 boxes
public static int DEFAULT_MAX_COLLISION_BOX_SIZE = 15; // increase if we somehow have a shape made of more than 15 parts.
private final SimpleCollisionBox[] boxes;
int maxLength = 0;
int currentLength = 0;

public ComplexCollisionBox(SimpleCollisionBox... boxes) {
this(DEFAULT_MAX_COLLISION_BOX_SIZE, boxes);
Expand All @@ -19,15 +19,15 @@ public ComplexCollisionBox(int maxIndex) {
}

public ComplexCollisionBox(int maxIndex, SimpleCollisionBox... boxes) {
this.currentLength = Math.min(maxIndex, boxes.length);
this.boxes = new SimpleCollisionBox[maxIndex];
System.arraycopy(boxes, 0, this.boxes, 0, Math.min(maxIndex, boxes.length));
maxLength = boxes.length;
System.arraycopy(boxes, 0, this.boxes, 0, this.currentLength);
}

public boolean add(SimpleCollisionBox collisionBox) {
boxes[maxLength] = collisionBox;
maxLength++;
return maxLength <= boxes.length;
boxes[currentLength] = collisionBox;
currentLength++;
return currentLength <= boxes.length;
}

@Override
Expand All @@ -38,15 +38,15 @@ public CollisionBox union(SimpleCollisionBox other) {

@Override
public boolean isCollided(SimpleCollisionBox other) {
for (int i = 0; i < maxLength; i++) {
for (int i = 0; i < currentLength; i++) {
if (boxes[i].isCollided(other)) return true;
}
return false;
}

@Override
public boolean isIntersected(SimpleCollisionBox other) {
for (int i = 0; i < maxLength; i++) {
for (int i = 0; i < currentLength; i++) {
if (boxes[i].isIntersected(other)) return true;
}
return false;
Expand All @@ -59,26 +59,26 @@ public CollisionBox copy() {

@Override
public CollisionBox offset(double x, double y, double z) {
for (int i = 0; i < maxLength; i++) {
for (int i = 0; i < currentLength; i++) {
boxes[i].offset(x, y ,z);
}
return this;
}

@Override
public void downCast(List<SimpleCollisionBox> list) {
list.addAll(Arrays.asList(boxes).subList(0, maxLength));
list.addAll(Arrays.asList(boxes).subList(0, currentLength));
}

@Override
public int downCast(SimpleCollisionBox[] list) {
System.arraycopy(boxes, 0, list, 0, maxLength);
return maxLength;
System.arraycopy(boxes, 0, list, 0, currentLength);
return currentLength;
}

@Override
public boolean isNull() {
for (int i = 0; i < maxLength; i++) {
for (int i = 0; i < currentLength; i++) {
if (!boxes[i].isNull()) return false;
}
return true;
Expand Down

0 comments on commit 78f2057

Please sign in to comment.