Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
  • master
2 results

Target

Select target project
  • s21226517/image-template
  • c19028886/tp-3-rayane-chorfi
  • s23026062/image-sahin
  • t21233923/image-template
  • z23012739/image-template
  • a23026569/image-template-amroun-said
  • boukenze.b/image-template-tp-4
  • l3_s3_infoamu/s3/programmation-2/tp-4-manipulation-dimages
  • c22029830/image-template-rafi
  • m22023183/image-template
  • l3_s3_infoamu/s3/programmation-2/image-template
  • a19029459/image-template
  • a19021078/image-template
  • b23003912/image-template-tp-4-baron-law-yoann
  • alaboure/image-template
  • saddem.r/image-template
  • b21229750/image-template-tp-4
17 results
Select Git revision
  • main
  • master
2 results
Show changes
package viewer;
import javafx.scene.paint.Color;
/**
* Histogram of colors, used to generate a list of colors made
* from several gradients combined, so that the list looks smooth.
*/
record Histogram(double[] breakpoints, Color[] colors) {
/**
* Creates a schema of colors.
* <code>breakpoints</code> and <code>colors</code> must have the same length.
* Two consecutive indices of <code>colors</code> define a gradient of colors.
* Those colors will be linearly mapped to the interval defined by the same
* indices taken in <code>breakpoints</code>
* For instance, { 0, 0.4, 1.} with { BLACK, RED, WHITE} represents a black
* to red to white spectrum, where 40% of the point are the black to red
* gradient, 60% are the red to white gradient.
*
* @param breakpoints values from 0 to 1, in increasing order, the first value must be 0 and the last one.
* @param colors colors assigned to each breakpoint.
*/
Histogram {
assert (breakpoints[0] == 0);
assert (breakpoints[breakpoints.length - 1] == 1);
assert (colors.length == breakpoints.length);
}
/**
* Generates a list of colors of given length representing this spectrum.
*
* @param howManyPoints the number of colors returned
* @return a list of colors following the schema defined in the constructor
*/
Color[] generate(int howManyPoints) {
Color[] result = new Color[howManyPoints];
int bpIndex = 0;
for (int ptIndex = 0; ptIndex < howManyPoints; ptIndex++) {
double absolute = (double) ptIndex / (double) howManyPoints;
while (absolute > breakpoints[bpIndex + 1] && bpIndex < breakpoints.length - 1)
bpIndex++;
double relative = (absolute - breakpoints[bpIndex]) / (breakpoints[bpIndex + 1] - breakpoints[bpIndex]);
result[ptIndex] = colors[bpIndex].interpolate(colors[bpIndex + 1], relative);
}
return result;
}
}
package viewer;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.Collection;
/**
* A Pixel. Because of antialiasing, each pixel is further decomposed into
* sub-pixels. Each sub-pixels has a color, the color of the pixel is the average
* of the sub-pixels' colors.
*/
record Pixel(int x, int y, Collection<SubPixel> subPixels) {
/**
* Creates a pixel with given coordinates and sub-pixels.
*
* @param x the horizontal coordinate of the pixel on the screen
* @param y the vertical coordinate of the pixel on the screen
* @param subPixels a collection of sub-pixels for this pixel
*/
Pixel {
}
/**
* @return the list of sub-pixels in this pixel
*/
Collection<SubPixel> getSubPixels() {
return subPixels;
}
private Color getAverageColor() {
double red = 0;
double green = 0;
double blue = 0;
int count = 0;
for (SubPixel subPixel : subPixels) {
count++;
Color col = subPixel.getColor();
red += col.getRed();
green += col.getGreen();
blue += col.getBlue();
}
double c = count;
return new Color(red / c, green / c, blue / c, 1.);
}
/**
* Displays the pixel.
*
* @param context the context of the canvas on which to paint.
*/
void render(GraphicsContext context) {
context.setFill(getAverageColor());
context.fillRect(x, y, 1, 1);
}
}
package viewer;
import javafx.scene.paint.Color;
/**
* A subpixel contributes to the color of one pixel. Pixels are usually
* composed of several sub-pixels, whose colors are averaged.
*/
class SubPixel {
private Color color = Color.BLACK;
/**
* Each subpixel has a value that will be used to color them.
*/
final double value;
/**
* Creates a subpixel.
*
* @param value divergence for the corresponding pixel. This will be mapped to a color.
*/
SubPixel(double value) {
this.value = value;
}
/**
* Attributes a color to a subpixel.
*
* @param color the color to give to the subpixel
*/
void setColor(Color color) {
this.color = color;
}
/**
* @return the color of the subpixel. Default is black.
*/
Color getColor() {
return color;
}
/**
* Comparison of two sub-pixels by their values.
*
* @param pix1 first subpixel to compare
* @param pix2 second subpixel to compare
* @return an integer representing the result of the comparison, with the usual convention.
*/
static int compare(SubPixel pix1, SubPixel pix2) {
return Double.compare(pix1.value, pix2.value);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.canvas.Canvas?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Display">
<Canvas fx:id="canvas"/>
</AnchorPane>
This diff is collapsed.
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.canvas.Canvas?>
<GridPane fx:controller="viewer.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<Canvas fx:id="canvas" width="1200" height="900"/>
</GridPane>
\ No newline at end of file
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
public class ByteGrayColorTest {
@Test
@Disabled
public void testGetLuminosity_whenColorCreatedWithGrayLevel(){
ByteGrayColor black = new ByteGrayColor(0);
ByteGrayColor white = new ByteGrayColor(255);
assertThat(black.getLuminosity()).isCloseTo(0., within(.01));
assertThat(white.getLuminosity()).isCloseTo(1., within(.01));
}
@Test
@Disabled
public void testGetLuminosity_whenColorCreatedWithLuminosity(){
ByteGrayColor color1 = new ByteGrayColor(.25);
ByteGrayColor color2 = new ByteGrayColor(.75);
assertThat(color1.getLuminosity()).isCloseTo(.25, within(.01));
assertThat(color2.getLuminosity()).isCloseTo(.75, within(.01));
}
@Test
@Disabled
public void testCompareTo_whenColorsCreatedWithGrayLevel(){
ByteGrayColor color1 = new ByteGrayColor(100);
ByteGrayColor color2 = new ByteGrayColor(150);
ByteGrayColor color3 = new ByteGrayColor(200);
ByteGrayColor sameGrayLevelAsColor1 = new ByteGrayColor(100);
assertThat(color1.compareTo(color2)).isNegative();
assertThat(color2.compareTo(color3)).isNegative();
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color2.compareTo(color1)).isPositive();
assertThat(color1.compareTo(sameGrayLevelAsColor1)).isZero();
assertThat(color1.compareTo(color2)).isEqualTo(sameGrayLevelAsColor1.compareTo(color2));
}
@Test
@Disabled
public void testCompareTo_whenColorsCreatedWithLuminosity(){
ByteGrayColor color1 = new ByteGrayColor(0.20);
ByteGrayColor color2 = new ByteGrayColor(0.60);
ByteGrayColor color3 = new ByteGrayColor(0.80);
ByteGrayColor sameLuminosityAsColor1 = new ByteGrayColor(0.20);
assertThat(color1.compareTo(color2)).isNegative();
assertThat(color2.compareTo(color3)).isNegative();
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color2.compareTo(color1)).isPositive();
assertThat(color1.compareTo(sameLuminosityAsColor1)).isZero();
assertThat(color1.compareTo(color2)).isEqualTo(sameLuminosityAsColor1.compareTo(color2));
}
@Test
@Disabled
public void testCompareTo_whenColorsCreatedWithLuminosityAndGrayLevel(){
ByteGrayColor color1 = new ByteGrayColor(0.);
ByteGrayColor color2 = new ByteGrayColor(150);
ByteGrayColor color3 = new ByteGrayColor(1.);
assertThat(color1.compareTo(color2)).isNegative();
assertThat(color2.compareTo(color3)).isNegative();
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color2.compareTo(color1)).isPositive();
}
}
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
class MatrixGrayImageTest {
@Test
@Disabled
void testGetWidth() {
assertThat(new MatrixGrayImage(0,0).getWidth()).isEqualTo(0);
assertThat(new MatrixGrayImage(10,20).getWidth()).isEqualTo(10);
assertThat(new MatrixGrayImage(400,300).getWidth()).isEqualTo(400);
}
@Test
@Disabled
void testGetHeight() {
assertThat(new MatrixGrayImage(0,0).getHeight()).isEqualTo(0);
assertThat(new MatrixGrayImage(10,20).getHeight()).isEqualTo(20);
assertThat(new MatrixGrayImage(400,300).getHeight()).isEqualTo(300);
}
@Test
@Disabled
void testGetPixel_whenPixelHasBeenSet() {
GrayColor grey1 = new ByteGrayColor(0.2);
GrayColor grey2 = new ByteGrayColor(0.8);
MatrixGrayImage image = new MatrixGrayImage(10, 10);
image.setPixel(grey1, 1, 1);
assertThat(image.getPixelGrayColor(1,1)).isEqualTo(grey1);
image.setPixel(grey2, 3, 9);
assertThat(image.getPixelGrayColor(3,9)).isEqualTo(grey2);
}
}
\ No newline at end of file
package mandelbrot;
import static net.obvj.junit.utils.matchers.AdvancedMatchers.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class ComplexTest {
private Complex onePlusI;
private Complex minusI;
private Complex minusOne;
private Complex oneMinusI;
private Complex twoI;
private Complex two;
private Complex one;
private Complex i;
private Complex zero;
@BeforeEach
void initializeTestValues(){
onePlusI = new Complex(1,1);
minusI = new Complex(0,-1);
minusOne = new Complex(-1,0);
oneMinusI = new Complex(1, -1);
twoI = new Complex(0,2);
two = new Complex(2,0);
one = new Complex(1,0);
i = new Complex(0,1);
zero = new Complex(0,0);
}
@Test
void testEquals(){
assertThat(onePlusI, is(equalTo(onePlusI)));
assertThat(onePlusI, is(equalTo(new Complex(1, 1))));
assertThat(two, is(not(equalTo(twoI))));
}
@Test
void testGetReal(){
assertThat(two.getReal(), is(closeTo(2., Helpers.EPSILON)));
assertThat(onePlusI.getReal(), is(closeTo(1., Helpers.EPSILON)));
assertThat(oneMinusI.getReal(), is(closeTo(1., Helpers.EPSILON)));
}
@Test
void testGetImaginary(){
assertThat(two.getImaginary(), is(closeTo(0., Helpers.EPSILON)));
assertThat(onePlusI.getImaginary(), is(closeTo(1., Helpers.EPSILON)));
assertThat(oneMinusI.getImaginary(), is(closeTo(-1., Helpers.EPSILON)));
}
@Test
void testOne(){
assertThat(Complex.ONE.getReal(), is(closeTo(1., Helpers.EPSILON)));
assertThat(Complex.ONE.getImaginary(), is(closeTo(0., Helpers.EPSILON)));
}
@Test
void testI(){
assertThat(Complex.I.getReal(), is(closeTo(0., Helpers.EPSILON)));
assertThat(Complex.I.getImaginary(), is(closeTo(1., Helpers.EPSILON)));
}
@Test
void testZero(){
assertThat(Complex.ZERO.getReal(), is(closeTo(0., Helpers.EPSILON)));
assertThat(Complex.ZERO.getImaginary(), is(closeTo(0., Helpers.EPSILON)));
}
@Test
void testNegate(){
assertThat(two.negate(), is(equalTo(new Complex(-2,0))));
assertThat(minusI.negate(), is(equalTo(i)));
assertThat(oneMinusI.negate(), is(equalTo(new Complex(-1, 1))));
}
@Test
void testReciprocal(){
assertThat(one.reciprocal(), is(equalTo(one)));
assertThat(minusI.reciprocal(), is(equalTo(i)));
assertThat(two.reciprocal(), is(equalTo(new Complex(0.5,0))));
assertThat(oneMinusI.reciprocal(), is(equalTo(new Complex(0.5,0.5))));
}
@Test
void testReciprocalOfZero(){
assertThat(()->zero.reciprocal(), throwsException(ArithmeticException.class));
}
@Test
void testSubtract(){
assertThat(zero.subtract(one), is(equalTo(minusOne)));
assertThat(one.subtract(i), is(equalTo(oneMinusI)));
}
@Test
void testDivide(){
assertThat(onePlusI.divide(Complex.ONE), equalTo(onePlusI));
assertThat(Complex.ONE.divide(two), equalTo(new Complex(0.5, 0)));
assertThat(oneMinusI.divide(onePlusI), equalTo(minusI));
}
@Test
void testDivideByZero(){
assertThat(()->one.divide(zero), throwsException(ArithmeticException.class));
}
@Test
void testConjugate(){
assertThat(two.conjugate(), equalTo(two));
assertThat(oneMinusI.conjugate(), equalTo(onePlusI));
}
@Test
void testRotation(){
assertThat(Complex.rotation(Math.PI/2), equalTo(i));
assertThat(Complex.rotation(-Math.PI/2), equalTo(minusI));
assertThat(Complex.rotation(0), equalTo(one));
assertThat(Complex.rotation(Math.PI/4), equalTo(new Complex(Math.sqrt(2)/2., Math.sqrt(2)/2.)));
assertThat(Complex.rotation(Math.PI/3), equalTo(new Complex(1./2., Math.sqrt(3)/2.)));
}
@Test
void testBasicToString(){
assertThat(two.toString(), containsString("2.0"));
assertThat(i.toString(), containsString("i"));
}
@Test
void testToStringFormat(){
assertThat(oneMinusI.toString(), is(equalTo("1.0 - 1.0i")));
assertThat(onePlusI.toString(), is(equalTo("1.0 + 1.0i")));
assertThat(minusI.toString(), is(equalTo("-1.0i")));
assertThat(twoI.toString(), is(equalTo("2.0i")));
assertThat(two.toString(), is(equalTo("2.0")));
}
}
\ No newline at end of file