Skip to content
Snippets Groups Projects
Commit ead47c02 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Mise à jour 2021

parent a07ddff5
No related branches found
No related tags found
No related merge requests found
Pipeline #4636 passed
Showing
with 50 additions and 89 deletions
...@@ -13,9 +13,9 @@ repositories { ...@@ -13,9 +13,9 @@ repositories {
} }
dependencies { dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.7.2', testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.1',
'org.hamcrest:hamcrest-library:2.2', 'net.obvj:junit-utils:1.3.1') 'org.assertj:assertj-core:3.21.0')
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
} }
test { test {
......
...@@ -2,9 +2,6 @@ package image; ...@@ -2,9 +2,6 @@ package image;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public abstract class AbstractImage implements Image{ public abstract class AbstractImage implements Image{
private int width; private int width;
private int height; private int height;
......
...@@ -15,7 +15,7 @@ public class BruteRasterImage extends RasterImage { ...@@ -15,7 +15,7 @@ public class BruteRasterImage extends RasterImage {
} }
@Override @Override
public void createRepresentation() { public void initializeRepresentation() {
pixels = new Color[getWidth()][getHeight()]; pixels = new Color[getWidth()][getHeight()];
} }
......
...@@ -2,9 +2,6 @@ package image; ...@@ -2,9 +2,6 @@ package image;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/**
* Created by Arnaud Labourel on 09/11/2018.
*/
public interface Image { public interface Image {
Color getPixelColor(int x, int y); Color getPixelColor(int x, int y);
int getWidth(); int getWidth();
......
package image; package image;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public interface ImageFactory { public interface ImageFactory {
Image makeImage(); Image makeImage();
} }
...@@ -9,13 +9,13 @@ public class LogoLISFactory implements ImageFactory{ ...@@ -9,13 +9,13 @@ public class LogoLISFactory implements ImageFactory{
@Override @Override
public Image makeImage() { public Image makeImage() {
Color dark = Color.rgb(35,31,32); Color dark = Color.rgb(35,31,32);
Color greenblue = Color.rgb(113,208,199); Color greenBlue = Color.rgb(113,208,199);
int[] xCoordinates = {60, 720, 660, 400, 0, 400, 660}; int[] xCoordinates = {60, 720, 660, 400, 0, 400, 660};
int[] yCoordinates = {0, 60, 140, 0, 0, 140, 0}; int[] yCoordinates = {0, 60, 140, 0, 0, 140, 0};
int[] widths = {140, 140, 140, 60, 200, 60, 200}; int[] widths = {140, 140, 140, 60, 200, 60, 200};
int[] heights = {280, 80, 140, 80, 340, 200, 340}; int[] heights = {280, 80, 140, 80, 340, 200, 340};
Color[] colors = {Color.WHITE, Color.WHITE, Color.WHITE, greenblue, dark, dark, dark}; Color[] colors = {Color.WHITE, Color.WHITE, Color.WHITE, greenBlue, dark, dark, dark};
List<Shape> list = new ArrayList<>(); List<Shape> list = new ArrayList<>();
......
package image; package image;
/**
* Created by Arnaud Labourel on 25/11/2018.
*/
class NotSupportedException extends RuntimeException { class NotSupportedException extends RuntimeException {
NotSupportedException(String message) { NotSupportedException(String message) {
super(message); super(message);
......
...@@ -5,9 +5,6 @@ import javafx.scene.paint.Color; ...@@ -5,9 +5,6 @@ import javafx.scene.paint.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public class PaletteRasterImage extends RasterImage { public class PaletteRasterImage extends RasterImage {
private List<Color> palette; private List<Color> palette;
...@@ -34,7 +31,7 @@ public class PaletteRasterImage extends RasterImage { ...@@ -34,7 +31,7 @@ public class PaletteRasterImage extends RasterImage {
} }
@Override @Override
public void createRepresentation() { public void initializeRepresentation() {
palette = new ArrayList<>(); palette = new ArrayList<>();
indexesOfColors = new int[getWidth()][getHeight()]; indexesOfColors = new int[getWidth()][getHeight()];
} }
......
package image;
import javafx.scene.paint.Color;
/**
* Created by Arnaud Labourel on 09/11/2018.
*/
public class Pixel extends Point{
private Color color;
Pixel(int x, int y, Color color) {
super(x, y);
this.color = color;
}
public Color getColor() {
return color;
}
}
...@@ -2,9 +2,6 @@ package image; ...@@ -2,9 +2,6 @@ package image;
import java.util.Objects; import java.util.Objects;
/**
* Created by Arnaud Labourel on 09/11/2018.
*/
public class Point { public class Point {
public final int x, y; public final int x, y;
...@@ -16,8 +13,7 @@ public class Point { ...@@ -16,8 +13,7 @@ public class Point {
@Override @Override
public final boolean equals(Object o) { public final boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof Point)) return false; if (!(o instanceof Point point)) return false;
Point point = (Point) o;
return x == point.x && return x == point.x &&
y == point.y; y == point.y;
} }
......
...@@ -4,12 +4,12 @@ import javafx.scene.paint.Color; ...@@ -4,12 +4,12 @@ import javafx.scene.paint.Color;
public class RasterFlagFactory implements ImageFactory { public class RasterFlagFactory implements ImageFactory {
private int width; private final int width;
private int height; private final int height;
private Color leftColor; private final Color leftColor;
private Color middleColor; private final Color middleColor;
private Color rightColor; private final Color rightColor;
private RasterImageType rasterImageType; private final RasterImageType rasterImageType;
public RasterFlagFactory(int width, int height, Color leftColor, Color middleColor, Color rightColor, RasterImageType rasterImageType) { public RasterFlagFactory(int width, int height, Color leftColor, Color middleColor, Color rightColor, RasterImageType rasterImageType) {
this.width = width; this.width = width;
...@@ -22,13 +22,7 @@ public class RasterFlagFactory implements ImageFactory { ...@@ -22,13 +22,7 @@ public class RasterFlagFactory implements ImageFactory {
@Override @Override
public Image makeImage() { public Image makeImage() {
Color[][] colors = new Color[width][height]; Color[][] colors = initializeImageMatrix();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
colors[x][y] = (x < width / 3) ? leftColor : ((x > 2 * width / 3) ? rightColor : middleColor);
}
}
switch (rasterImageType){ switch (rasterImageType){
case BRUTE: case BRUTE:
return new BruteRasterImage(colors); return new BruteRasterImage(colors);
...@@ -40,4 +34,15 @@ public class RasterFlagFactory implements ImageFactory { ...@@ -40,4 +34,15 @@ public class RasterFlagFactory implements ImageFactory {
throw new NotSupportedException(rasterImageType + " is not supported"); throw new NotSupportedException(rasterImageType + " is not supported");
} }
} }
private Color[][] initializeImageMatrix() {
Color[][] colors = new Color[width][height];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
colors[x][y] = (x < width / 3) ? leftColor : ((x > 2 * width / 3) ? rightColor : middleColor);
}
}
return colors;
}
} }
...@@ -3,9 +3,6 @@ package image; ...@@ -3,9 +3,6 @@ package image;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import util.Matrices; import util.Matrices;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public abstract class RasterImage extends AbstractImage { public abstract class RasterImage extends AbstractImage {
RasterImage(Color[][] colors) { RasterImage(Color[][] colors) {
...@@ -17,20 +14,19 @@ public abstract class RasterImage extends AbstractImage { ...@@ -17,20 +14,19 @@ public abstract class RasterImage extends AbstractImage {
setWidth(Matrices.getRowCount(colors)); setWidth(Matrices.getRowCount(colors));
setHeight(Matrices.getColumnCount(colors)); setHeight(Matrices.getColumnCount(colors));
createRepresentation(); initializeRepresentation();
setPixelsColor(colors); setPixelsColor(colors);
} }
RasterImage(Color color, int width, int height) { RasterImage(Color color, int width, int height) {
super(width, height); super(width, height);
initializeRepresentation();
createRepresentation();
setPixelsColor(color); setPixelsColor(color);
} }
public abstract void setPixelColor(Color color, int x , int y); public abstract void setPixelColor(Color color, int x , int y);
public abstract void createRepresentation(); public abstract void initializeRepresentation();
private void setPixelsColor(Color[][] pixels){ private void setPixelsColor(Color[][] pixels){
for(int x = 0; x<getWidth(); x++) for(int x = 0; x<getWidth(); x++)
......
...@@ -4,10 +4,10 @@ import javafx.scene.paint.Color; ...@@ -4,10 +4,10 @@ import javafx.scene.paint.Color;
public class RasterUniformImageFactory implements ImageFactory { public class RasterUniformImageFactory implements ImageFactory {
private int width; private final int width;
private int height; private final int height;
private Color color; private final Color color;
private RasterImageType rasterImageType; private final RasterImageType rasterImageType;
public RasterUniformImageFactory(int width, int height, Color color, RasterImageType rasterImageType) { public RasterUniformImageFactory(int width, int height, Color color, RasterImageType rasterImageType) {
this.width = width; this.width = width;
......
...@@ -2,14 +2,11 @@ package image; ...@@ -2,14 +2,11 @@ package image;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/**
* Created by Arnaud Labourel on 23/11/2018.
*/
public class Rectangle implements Shape { public class Rectangle implements Shape {
private int x; private final int x;
private int y; private final int y;
private int width; private final int width;
private int height; private final int height;
Color color; Color color;
Rectangle(int x, int y, int width, int height, Color color) { Rectangle(int x, int y, int width, int height, Color color) {
......
...@@ -32,7 +32,7 @@ public class SparseRasterImage extends RasterImage{ ...@@ -32,7 +32,7 @@ public class SparseRasterImage extends RasterImage{
} }
@Override @Override
public void createRepresentation() { public void initializeRepresentation() {
pixelsMap = new HashMap<>(); pixelsMap = new HashMap<>();
} }
} }
...@@ -9,7 +9,7 @@ import java.util.List; ...@@ -9,7 +9,7 @@ import java.util.List;
*/ */
public class VectorImage extends AbstractImage { public class VectorImage extends AbstractImage {
private List<Shape> shapes; private final List<Shape> shapes;
VectorImage(List<Shape> shapes, int width, int height) { VectorImage(List<Shape> shapes, int width, int height) {
super(width, height); super(width, height);
...@@ -18,8 +18,9 @@ public class VectorImage extends AbstractImage { ...@@ -18,8 +18,9 @@ public class VectorImage extends AbstractImage {
@Override @Override
public Color getPixelColor(int x, int y) { public Color getPixelColor(int x, int y) {
Point point = new Point(x, y);
for(Shape shape : shapes){ for(Shape shape : shapes){
if(shape.contains(new Point(x,y))) if(shape.contains(point))
return shape.getColor(); return shape.getColor();
} }
return Color.WHITE; return Color.WHITE;
......
...@@ -7,6 +7,7 @@ import javafx.scene.Scene; ...@@ -7,6 +7,7 @@ import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
public class Main extends Application public class Main extends Application
...@@ -18,7 +19,7 @@ public class Main extends Application ...@@ -18,7 +19,7 @@ public class Main extends Application
@Override @Override
public void start(Stage primaryStage) throws IOException { public void start(Stage primaryStage) throws IOException {
Parent root =FXMLLoader.load(getClass().getClassLoader().getResource("fxml/Display.fxml")); Parent root =FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("fxml/Display.fxml")));
primaryStage.setTitle("Image display"); primaryStage.setTitle("Image display");
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root));
primaryStage.show(); primaryStage.show();
......
import image.BlankImage; import image.BlankImage;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class BlankImageTest { public class BlankImageTest {
@Test @Test
public void testBlankImageGetWidth(){ public void testBlankImageGetWidth(){
BlankImage blankImage = new BlankImage(200, 300); BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getWidth(), is(equalTo(200))); assertThat(blankImage.getWidth()).isEqualTo(200);
} }
@Test @Test
public void testBlankImageGetHeight(){ public void testBlankImageGetHeight(){
BlankImage blankImage = new BlankImage(200, 300); BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getHeight(), is(equalTo(300))); assertThat(blankImage.getHeight()).isEqualTo(300);
} }
@Test @Test
public void testBlankImageGetPixelColor(){ public void testBlankImageGetPixelColor(){
BlankImage blankImage = new BlankImage(200, 300); BlankImage blankImage = new BlankImage(200, 300);
assertThat(blankImage.getPixelColor(0,0), is(equalTo(Color.WHITE))); assertThat(blankImage.getPixelColor(0,0)).isEqualTo(Color.WHITE);
assertThat(blankImage.getPixelColor(100,100), is(equalTo(Color.WHITE))); assertThat(blankImage.getPixelColor(100,100)).isEqualTo(Color.WHITE);
assertThat(blankImage.getPixelColor(199,299), is(equalTo(Color.WHITE))); assertThat(blankImage.getPixelColor(199,299)).isEqualTo(Color.WHITE);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment