-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting ready to work with vectors (cuboids)
- Loading branch information
Pavel Fedin
committed
Dec 3, 2016
1 parent
5e9ce77
commit 2a94174
Showing
6 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |