diff --git a/README.md b/README.md index 9c15b57d7e040a8413a161eeb1818a73a00da634..2d5c4f69a25c56f169d17c516c98731eb1ff0beb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Image +# Tuiles de Wang ## Description du projet -Ce projet est l'occasion de travailler sur la représentation et la manipulation d'images. Ces images seront constituées de pixels caractérisés par une couleur représentant un niveau de gris. +Ce sujet est construit sur l'idée de réaliser des pavages du plan, à l'aide d'objets simples nommés des tuiles de Wang. Il s'agit de tuiles carrées divisées en quatre triangles. Chaque triangle est associé à un côté du carré, et coloré d'une couleur particulière. ## Membres du projet diff --git a/src/main/java/controller/GridController.java b/src/main/java/controller/GridController.java index 472abd4c38fcd705ba050419c0b34c9b38ad0e55..00c20dbd3a44f99d1eb605fee34adb06e84cbea5 100644 --- a/src/main/java/controller/GridController.java +++ b/src/main/java/controller/GridController.java @@ -8,6 +8,10 @@ import java.util.List; import java.util.Random; public class GridController { + public static final Color COLOR_FIRST_NAME_ONE = Color.RED; + public static final Color COLOR_LAST_NAME_ONE = Color.BLUE; + public static final Color COLOR_FIRST_NAME_TWO = Color.GREEN; + public static final Color COLOR_LAST_NAME_TWO = Color.YELLOW; Random random = new Random(); @FXML public GridTileCanvas gridTileCanvas; @@ -40,55 +44,74 @@ public class GridController { } @FXML - public void updateRedUniformTile(){ + public void updateFirstNameOneUniformTile(){ // TODO : uncomment the code to test UniformTileGenerator - // updateGrid(new UniformTileGenerator(new InternalSide(Color.RED))); + // updateGrid(new UniformTileGenerator(new InternalSide(COLOR_FIRST_NAME_ONE))); + } + + @FXML + public void updateFirstNameTwoUniformTile() { + // TODO : uncomment the code to test UniformTileGenerator + // updateGrid(new UniformTileGenerator(new InternalSide(COLOR_FIRST_NAME_TWO))); + } + + @FXML + public void updateLastNameOneUniformTile(){ + // TODO : uncomment the code to test UniformTileGenerator + // updateGrid(new UniformTileGenerator(new InternalSide(COLOR_LAST_NAME_ONE))); + } + + @FXML + public void updateLastNameTwoUniformTile() { + // TODO : uncomment the code to test UniformTileGenerator + // updateGrid(new UniformTileGenerator(new InternalSide(COLOR_LAST_NAME_TWO))); } @FXML public void updateRandomColorUniformTile(){ // TODO : uncomment the code to test RandomUniformTileGenerator - // updateGrid(new RandomUniformTileGenerator(List.of(Color.RED, Color.BLUE, Color.BLACK), random)); + // updateGrid(new RandomUniformTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_LAST_NAME_TWO), random)); } @FXML public void updateRandomTruchetTile(){ // TODO : uncomment the code to test RandomRotatedTruchetTileGenerator - // updateGrid(new RandomRotatedTruchetTileGenerator(Color.RED, Color.BLUE, random)); + // updateGrid(new RandomRotatedTruchetTileGenerator(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, random)); } @FXML public void updateRandomWangTile() { // TODO : uncomment the code to test RandomWangTileGenerator - // updateGrid(new RandomWangTileGenerator(List.of(Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW), random)); + // updateGrid(new RandomWangTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_FIRST_NAME_TWO, COLOR_LAST_NAME_TWO), random)); } @FXML public void updateRandomConstrainedWangTile() { // TODO : uncomment the code to test RandomConstrainedWangTileGenerator - // updateGrid(new RandomConstrainedWangTileGenerator(List.of(Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW), random)); + // updateGrid(new RandomConstrainedWangTileGenerator(List.of(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, COLOR_FIRST_NAME_TWO, Color.YELLOW), random)); } @FXML public void updateConstrainedTruchetTile() { // TODO : uncomment the code to test ConstrainedRotatedTruchetTileGenerator - // updateGrid(new ConstrainedRotatedTruchetTileGenerator(Color.RED, Color.BLUE, random)); + // updateGrid(new ConstrainedRotatedTruchetTileGenerator(COLOR_FIRST_NAME_ONE, COLOR_LAST_NAME_ONE, random)); } @FXML public void updateRandomWangTileSet() { // TODO : uncomment the code to test RandomTileSetGenerator - /* +/* updateGrid(new RandomTileSetGenerator(List.of( - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.BLUE), new InternalSide(Color.RED), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.RED), new InternalSide(Color.BLUE), new InternalSide(Color.BLUE)}), - new WangTile(new Side[]{new InternalSide(Color.RED), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.GREEN), new InternalSide(Color.RED), new InternalSide(Color.BLUE)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.BLUE), new InternalSide(Color.BLUE), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.BLUE), new InternalSide(Color.RED), new InternalSide(Color.GREEN), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.GREEN), new InternalSide(Color.BLUE), new InternalSide(Color.GREEN)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.RED), new InternalSide(Color.RED), new InternalSide(Color.RED)}), - new WangTile(new Side[]{new InternalSide(Color.GREEN), new InternalSide(Color.BLUE), new InternalSide(Color.GREEN), new InternalSide(Color.BLUE)})), random)); - */ + new WangTile(new Side[]{new InternalSide(COLOR_LAST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new InternalSide(COLOR_LAST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new InternalSide(COLOR_LAST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_LAST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new InternalSide(COLOR_LAST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_LAST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_LAST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_LAST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_ONE)}), + new WangTile(new Side[]{new InternalSide(COLOR_FIRST_NAME_ONE), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO)}), + new WangTile(new Side[]{new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO), new InternalSide(COLOR_FIRST_NAME_TWO)})), random)); +*/ } + + } diff --git a/src/main/java/model/EmptySquare.java b/src/main/java/model/EmptySquare.java index 3eb013bd7784e13695c400c5e51f1b2d967f0397..97b91b422780205f5ade7140353b5a6d0b08c8c2 100644 --- a/src/main/java/model/EmptySquare.java +++ b/src/main/java/model/EmptySquare.java @@ -3,9 +3,9 @@ package model; import java.util.List; public class EmptySquare implements Square{ - public static final Square EMPTY_SQUARE= new EmptySquare(); + public static final Square EMPTY_SQUARE = new EmptySquare(); - private EmptySquare(){} + private EmptySquare() {} @Override public boolean accept(Tile tile) { @@ -36,5 +36,5 @@ public class EmptySquare implements Square{ } @Override - public void setNeighbor(Square neighbor, CardinalDirection direction) { } + public void setNeighbor(Square neighbor, CardinalDirection direction) {} } diff --git a/src/main/resources/view/GridCanvas.fxml b/src/main/resources/view/GridCanvas.fxml index 009d4c0ccc74ec5032a327383e6c7e4792c14ac9..464d03cbad00fe3cb84cd39955a6985f09292b0c 100644 --- a/src/main/resources/view/GridCanvas.fxml +++ b/src/main/resources/view/GridCanvas.fxml @@ -17,7 +17,13 @@ <Menu mnemonicParsing="false" text="Uniform Tiles"> <MenuItem mnemonicParsing="false" onAction="#updateEmptyUniformTile" text="Empty"> </MenuItem> - <MenuItem mnemonicParsing="false" onAction="#updateRedUniformTile" text="Red"> + <MenuItem mnemonicParsing="false" onAction="#updateFirstNameOneUniformTile" text="Firstname 1"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateLastNameOneUniformTile" text="Lastname 1"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateFirstNameTwoUniformTile" text="Firstname 2"> + </MenuItem> + <MenuItem mnemonicParsing="false" onAction="#updateLastNameTwoUniformTile" text="Lastname 2"> </MenuItem> <MenuItem mnemonicParsing="false" onAction="#updateRandomColorUniformTile" text="Random color"> </MenuItem> diff --git a/src/test/java/EmptyGridTest.java b/src/test/java/EmptyGridTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2d6889e86b204d67b1f67449e47004a41b1d95f3 --- /dev/null +++ b/src/test/java/EmptyGridTest.java @@ -0,0 +1,29 @@ +import model.EmptyGrid; +import model.EmptySquare; +import model.Grid; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyGridTest { + @Test + void testGetNumberOfRows(){ + assertThat(new EmptyGrid(10,20).getNumberOfRows()).isEqualTo(10); + assertThat(new EmptyGrid(100,200).getNumberOfRows()).isEqualTo(100); + } + + @Test + void testGetNumberOfColumns(){ + assertThat(new EmptyGrid(10,20).getNumberOfColumns()).isEqualTo(20); + assertThat(new EmptyGrid(100,200).getNumberOfColumns()).isEqualTo(200); + } + + @Test + void testGetSquare(){ + Grid emptyGrid = new EmptyGrid(100,20); + assertThat(emptyGrid.getSquare(0, 0)).isEqualTo(EmptySquare.EMPTY_SQUARE); + assertThat(emptyGrid.getSquare(10, 9)).isEqualTo(EmptySquare.EMPTY_SQUARE); + assertThat(emptyGrid.getSquare(99, 19)).isEqualTo(EmptySquare.EMPTY_SQUARE); + } + +} diff --git a/src/test/java/EmptySideTest.java b/src/test/java/EmptySideTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c44f999261b6bca76303c3f4318f2922a350677d --- /dev/null +++ b/src/test/java/EmptySideTest.java @@ -0,0 +1,26 @@ +import javafx.scene.paint.Color; +import model.EmptySide; +import model.Side; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptySideTest { + @Test + void testCompatibleSides(){ + List<Side> sides = List.of(EmptySide.EMPTY_SIDE); + assertThat(EmptySide.EMPTY_SIDE.compatibleSides(sides)).containsExactly(EmptySide.EMPTY_SIDE); + } + + @Test + void testColor(){ + assertThat(EmptySide.EMPTY_SIDE.color()).isEqualTo(Color.WHITE); + } + @Test + void testAccept(){ + assertThat(EmptySide.EMPTY_SIDE.accept(EmptySide.EMPTY_SIDE)).isTrue(); + } + +} diff --git a/src/test/java/EmptySquareTest.java b/src/test/java/EmptySquareTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cf872f4549e2cc57168bd6bef291ca972dcb2b54 --- /dev/null +++ b/src/test/java/EmptySquareTest.java @@ -0,0 +1,37 @@ +import model.CardinalDirection; +import model.EmptySide; +import model.EmptySquare; +import model.EmptyTile; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptySquareTest { + @Test + void testAccept(){ + assertThat(EmptySquare.EMPTY_SQUARE.accept(EmptyTile.EMPTY_TILE)).isTrue(); + } + + @Test + void testGetTile(){ + assertThat(EmptySquare.EMPTY_SQUARE.getTile()).isEqualTo(EmptyTile.EMPTY_TILE); + } + + @Test + void testCompatibleTiles(){ + assertThat(EmptySquare.EMPTY_SQUARE.compatibleTiles(List.of(EmptyTile.EMPTY_TILE))).containsExactly(EmptyTile.EMPTY_TILE); + } + + @Test + void testCompatibleSides(){ + assertThat(EmptySquare.EMPTY_SQUARE.compatibleSides(List.of(EmptySide.EMPTY_SIDE), CardinalDirection.NORTH)).containsExactly(EmptySide.EMPTY_SIDE); + } + + @Test + void testGetNeighbor(){ + assertThat(EmptySquare.EMPTY_SQUARE.getNeighbor(CardinalDirection.NORTH)).isEqualTo(EmptySquare.EMPTY_SQUARE); + } + +} diff --git a/src/test/java/EmptyTileGeneratorTest.java b/src/test/java/EmptyTileGeneratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..70e634f6cb60d01b71a9051943a7423f406d0aa2 --- /dev/null +++ b/src/test/java/EmptyTileGeneratorTest.java @@ -0,0 +1,16 @@ +import model.EmptySquare; +import model.EmptyTile; +import model.EmptyTileGenerator; +import model.TileGenerator; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyTileGeneratorTest { + @Test + void testNextTile(){ + TileGenerator tileGenerator = new EmptyTileGenerator(); + assertThat(tileGenerator.nextTile(EmptySquare.EMPTY_SQUARE)).isEqualTo(EmptyTile.EMPTY_TILE); + assertThat(tileGenerator.nextTile(EmptySquare.EMPTY_SQUARE)).isEqualTo(EmptyTile.EMPTY_TILE); + } +} diff --git a/src/test/java/EmptyTileTest.java b/src/test/java/EmptyTileTest.java new file mode 100644 index 0000000000000000000000000000000000000000..75d07fd7eed70959f5eab68e65a61ec5e36daea0 --- /dev/null +++ b/src/test/java/EmptyTileTest.java @@ -0,0 +1,17 @@ +import model.CardinalDirection; +import model.EmptySide; +import model.EmptyTile; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EmptyTileTest { + + @Test + void testSide(){ + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.NORTH)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.SOUTH)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.EAST)).isEqualTo(EmptySide.EMPTY_SIDE); + assertThat(EmptyTile.EMPTY_TILE.side(CardinalDirection.WEST)).isEqualTo(EmptySide.EMPTY_SIDE); + } +}