Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
KURDYK louis committed Dec 30, 2021
1 parent 8747e44 commit fdf23d3
Show file tree
Hide file tree
Showing 16 changed files with 302 additions and 28 deletions.
14 changes: 14 additions & 0 deletions src/main/java/fr/josso/fractales/CmdLine/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
import java.util.List;
import java.util.regex.Pattern;

/**
* The type Command parser.
*/
public class CommandParser {

/**
* Validate the arguments.
* @param commandLine the structure with the arguments.
* @throws ParseException in case of invalid arguments.
*/
private static void validate(CommandLine commandLine) throws ParseException {
Pattern floatPattern = Pattern.compile("-?\\d+(\\.\\d+)?");
Pattern positiveFloatPattern = Pattern.compile("\\d+(\\.\\d+)?");
Expand Down Expand Up @@ -50,6 +58,12 @@ private static void validate(CommandLine commandLine) throws ParseException {
}
}

/**
* Parse command line.
*
* @param argv the argv
* @return the command line
*/
public static CommandLine parse(String[] argv) {
Options options = new Options();
Option juliaOption = Option.builder("j")
Expand Down
61 changes: 57 additions & 4 deletions src/main/java/fr/josso/fractales/Core/BigBufferedImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* https://www.facebook.com/pulispace
* http://nyomdmegteis.hu/en/
*/

import java.awt.Point;
import java.awt.color.ColorSpace;
import java.awt.image.BandedSampleModel;
Expand All @@ -27,14 +28,22 @@
import java.util.HashSet;
import java.util.Hashtable;

/**
* A class to store big image.
*/
public class BigBufferedImage extends BufferedImage {

private static final String TMP_DIR = System.getProperty("java.io.tmpdir");
/**
* The constant MAX_PIXELS_IN_MEMORY.
*/
public static final int MAX_PIXELS_IN_MEMORY = 1024 * 1024;

/**
* @param width wanted width of the image.
* @param height wanted height if the image.
* a Constructor.
*
* @param width wanted width of the image.
* @param height wanted height if the image.
* @param imageType wanted type of the image.
* @return a BufferedImage or BigBufferedImage depending on the wanted size.
*/
Expand All @@ -52,6 +61,7 @@ public static BufferedImage create(int width, int height, int imageType) {
}

/**
* a Constructor.
* @param tempDir the buffer directory.
* @param width wanted width of the image.
* @param height wanted height if the image.
Expand Down Expand Up @@ -90,6 +100,7 @@ private static BufferedImage createBigBufferedImage(File tempDir, int width, int
}

/**
* a Constructor.
* @param cm ColorModel for the new image.
* @param raster Raster for the image data.
* @param isRasterPremultiplied if true, the data in the raster has been premultiplied with alpha.
Expand All @@ -102,24 +113,35 @@ private BigBufferedImage(ColorModel cm, SimpleRaster raster, boolean isRasterPre
private static class SimpleRaster extends WritableRaster {

/**
* Instantiates a new Simple raster.
*
* @param sampleModel the sampleModel of the new SimpleRaster.
* @param dataBuffer the dataBuffer of the new SimpleRaster.
* @param origin the origin of the new SimpleRaster.
* @param dataBuffer the dataBuffer of the new SimpleRaster.
* @param origin the origin of the new SimpleRaster.
*/
public SimpleRaster(SampleModel sampleModel, FileDataBuffer dataBuffer, Point origin) {
super(sampleModel, dataBuffer, origin);
}

}

/**
* An intern class to dispose of the buffers.
*/
private static final class FileDataBufferDeleterHook extends Thread {

static {
Runtime.getRuntime().addShutdownHook(new FileDataBufferDeleterHook());
}

/**
* Set the structure that contains the buffers to dispose.
*/
private static final HashSet<FileDataBuffer> undisposedBuffers = new HashSet<>();

/**
* Dispose of the buffers.
*/
@Override
public void run() {
final FileDataBuffer[] buffers = undisposedBuffers.toArray(new FileDataBuffer[0]);
Expand All @@ -129,6 +151,9 @@ public void run() {
}
}

/**
* An intern class to buff file data.
*/
private static class FileDataBuffer extends DataBuffer {

private final String id = "buffer-" + System.currentTimeMillis() + "-" + ((int) (Math.random() * 1000));
Expand All @@ -138,12 +163,24 @@ private static class FileDataBuffer extends DataBuffer {
private RandomAccessFile[] accessFiles;
private MappedByteBuffer[] buffer;

/**
* Instantiates a new File data buffer.
*
* @param dir the dir
* @param size the size
* @param numBanks the num banks
* @throws IOException the io exception
*/
public FileDataBuffer(File dir, int size, int numBanks) throws IOException {
super(TYPE_BYTE, size, numBanks);
this.dir = dir;
init();
}

/**
* Initialise the buffer.
* @throws IOException in case of unreachable directory.
*/
private void init() throws IOException {
FileDataBufferDeleterHook.undisposedBuffers.add(this);
if (dir == null) {
Expand All @@ -168,16 +205,32 @@ private void init() throws IOException {
}
}

/**
* Getter for an element.
* @param bank index of bank of the element.
* @param i index of the element in bank.
* @return the wanted element.
*/
@Override
public int getElem(int bank, int i) {
return buffer[bank].get(i) & 0xff;
}


/**
* Setter for an element.
* @param bank index of bank of the element.
* @param i index of the element in bank.
* @param val value to store.
*/
@Override
public void setElem(int bank, int i, int val) {
buffer[bank].put(i, (byte) val);
}

/**
* Dispose of the buffer.
*/
private void disposeNow() {
this.buffer = null;
if (accessFiles != null) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/josso/fractales/Core/Complex.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package fr.josso.fractales.Core;

/**
* A representation for a complex number.
*/
public record Complex(double realPart, double imaginaryPart) {

/**
* Getter for realPart.
* @return The imaginary part of that number.
*/
public double getRealPart() {
return realPart;
}

/**
* Getter for imaginaryPart.
* @return The imaginary part of that number.
*/
public double getImaginaryPart() {
Expand All @@ -18,6 +23,7 @@ public double getImaginaryPart() {


/**
* Add to complex numbers into a new one.
* @param z1 First term of the addition
* @param z2 Second term of the addition
* @return The addition of z1 and z2
Expand All @@ -29,6 +35,7 @@ public static Complex add(Complex z1, Complex z2) {


/**
* Multiply to complex numbers into a new one.
* @param z1 First factor of the multiplication
* @param z2 Second factor of the multiplication
* @return The multiplication of z1 and z2
Expand All @@ -39,6 +46,7 @@ public static Complex multiply(Complex z1, Complex z2) {
}

/**
* This complex at the power exponent.
* @param exponent the wanted power
* @return this number to the power exponent
*/
Expand All @@ -52,6 +60,7 @@ public Complex pow(long exponent) {


/**
* Give the modulus.
* @return this number's modulus
*/
public double modulus() {
Expand All @@ -60,6 +69,7 @@ public double modulus() {


/**
* Give a string representation.
* @return a string representation of this number
*/
@Override
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/fr/josso/fractales/Core/ComplexPlane.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.josso.fractales.Core;

/**
* A representation of the complex plane.
*/
public class ComplexPlane {
private final float maxX;
private final float maxY;
Expand All @@ -10,6 +13,7 @@ public class ComplexPlane {


/**
* A constructor for a builder pattern.
* @param builder an intern class to build a plane.
*/
private ComplexPlane(ComplexPlaneBuilder builder) {
Expand All @@ -22,54 +26,64 @@ private ComplexPlane(ComplexPlaneBuilder builder) {
}

/**
* Create a builder.
* @return a builder necessary for instantiation.
*/
public static ComplexPlaneBuilder builder() {
return new ComplexPlaneBuilder();
}

/**
* Getter for step.
* @return return the step between to point in real and imaginary part.
*/
public double getStep() {
return step;
}

/**
* Getter for minX.
* @return minimal real part of any point of the plane.
*/
public float getMinX() {
return minX;
}

/**
* Getter for minY.
* @return minimal imaginary part of any point of the plane.
*/
public float getMinY() {
return minY;
}

/**
* Getter for scale.
* @return the scale of this plane.
*/
public int getScale() {
return scale;
}

/**
* @return the number of points on the X axis.
* Getter for the number of points on the X-axis.
* @return the number of points on the X-axis.
*/
public int getNbPointsX(){
return (int) (this.getScale() * (this.maxX - this.minX));
}

/**
* @return the number of points on the Y axis.
* Getter for the number of points on the Y-axis.
* @return the number of points on the Y-axis.
*/
public int getNbPointsY(){
return (int) (this.getScale() * (this.maxY - this.minY));
}

/**
* A builder for ComplexPlane.
*/
public static class ComplexPlaneBuilder {
private float maxX = 1;
private float maxY = 1;
Expand All @@ -79,6 +93,7 @@ public static class ComplexPlaneBuilder {


/**
* Set maxX.
* @param maxX wanted maximal real part.
* @return this builder with maxX updated (default at 1).
*/
Expand All @@ -89,6 +104,7 @@ public ComplexPlaneBuilder maxX(float maxX) {


/**
* Set minX.
* @param minX wanted minimal real part.
* @return this builder with minX updated (default at -1).
*/
Expand All @@ -98,6 +114,7 @@ public ComplexPlaneBuilder minX(float minX) {
}

/**
* Set maxY.
* @param maxY wanted maximal imaginary part.
* @return this builder with maxY updated (default at 1).
*/
Expand All @@ -107,6 +124,7 @@ public ComplexPlaneBuilder maxY(float maxY) {
}

/**
* Set minY.
* @param minY wanted minimal imaginary part.
* @return this builder with minY updated (default at -1).
*/
Expand All @@ -116,6 +134,7 @@ public ComplexPlaneBuilder minY(float minY) {
}

/**
* Set step.
* @param step wanted difference in imaginary or real part between two points.
* @return this builder with maxY updated (default at 0.01).
*/
Expand All @@ -125,6 +144,7 @@ public ComplexPlaneBuilder step(double step) {
}

/**
* Builde a ComplexPlane.
* @return a ComplexPlane with the same parameters as this builder.
*/
public ComplexPlane build() {
Expand All @@ -134,6 +154,7 @@ public ComplexPlane build() {
}

/**
* Give a string representation.
* @return a string representation of this ComplexPlane.
*/
@Override
Expand Down
Loading

0 comments on commit fdf23d3

Please sign in to comment.