Skip to content

Commit

Permalink
Getting ready to work with vectors (cuboids)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Fedin committed Dec 3, 2016
1 parent 5e9ce77 commit 2a94174
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/java/mregioneer/mcaliases/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.Arrays;

public class Block {
private final int x;
private final int z;
private final int y;
public final int x;
public final int z;
public final int y;

private final CompoundTag section;
private final int section_index;
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/mregioneer/mcaliases/Vector.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,76 @@
package mregioneer.mcaliases;

import mregioneer.utils.Coordinates3d;

import java.util.ArrayList;
import java.util.List;

import static java.lang.Math.max;
import static java.lang.Math.min;

/**
* Represents a set of blocks included in a cuboid specified with two coordinates;
*/
public class Vector {

private Coordinates3d cords1;
private Coordinates3d cords2;

public Vector(Coordinates3d cords1, Coordinates3d cords2) {
int min_x = min(cords1.x, cords2.x);
int max_x = max(cords1.x, cords2.x);

int min_z = min(cords1.z, cords2.z);
int max_z = max(cords1.z, cords2.z);

int min_y = min(cords1.y, cords2.y);
int max_y = max(cords1.y, cords2.y);

this.cords1 = new Coordinates3d(min_x, min_y, min_z);
this.cords2 = new Coordinates3d(max_x, max_y, max_z);
}

public int getXstart() {
return cords1.x;
}

public int getYstart() {
return cords1.y;
}

public int getZstart() {
return cords1.z;
}

public int getXend() {
return cords2.x;
}

public int getYend() {
return cords2.y;
}

public int getZend() {
return cords2.z;
}


public List<Coordinates3d> getCoordinatesArray() {

int height = getZend() - getZstart() + 1;
int width = getXend() - getXstart() + 1;
int depth = getYend() - getYstart() + 1;

//Coordinates3d[] cords_arr = new Coordinates3d[depth * height * width];
ArrayList cords_arr_list = new ArrayList<Coordinates3d>();

for(int z = getZstart(); z <= getZend(); z++) {
for(int y = getYstart(); y <= getYend(); y++) {
for(int x = getXstart(); x <= getXend(); x++) {
cords_arr_list.add(new Coordinates3d(x, y, z));
}
}
}
return cords_arr_list;
}
}
4 changes: 2 additions & 2 deletions src/main/java/mregioneer/utils/Coordinates2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* All new inctanses of the class with simular params returns the same hash code
*/
public class Coordinates2d {
private final int x;
private final int z;
public final int x;
public final int z;

private final String coordinates_as_string;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mregioneer/utils/Coordinates3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* All new inctanses of the class with simular params returns the same hash code
*/
public class Coordinates3d {
private final int x;
private final int y;
private final int z;
public final int x;
public final int y;
public final int z;

private final String coordinates_as_string;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mregioneer/utils/Helpers.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mregioneer.utils;


import mregioneer.mcaliases.Vector;

public class Helpers {
/**
* Helps to calculate offset for Add and Data sections which are known to keep 4 bits for a block
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/TestVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mregioneer.mcaliases.Vector;
import mregioneer.utils.Coordinates3d;
import org.junit.Test;

import java.util.List;

public class TestVector {
@Test
public void testAdd() {
Coordinates3d cords1 = new Coordinates3d(3, 3, 3);
Coordinates3d cords2 = new Coordinates3d(3, 4, 4);

Vector vector = new Vector(cords1, cords2);

List arr = vector.getCoordinatesArray();
}
}

0 comments on commit 2a94174

Please sign in to comment.