aboutsummaryrefslogtreecommitdiff
path: root/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java
diff options
context:
space:
mode:
Diffstat (limited to 'Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java')
-rw-r--r--Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java
index 43909fe..ec05939 100644
--- a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java
+++ b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotFractal.java
@@ -39,11 +39,24 @@ public class MandelbrotFractal {
*/
private static final Map<Point,Result> mandelNumbers = new HashMap<>();
+ /**
+ * Calculate the Mandelbrot number for a specific point up to some maximum
+ * @param x the x coordinate of the point
+ * @param y the y coordinate of the point
+ * @param repetitions the maximum
+ * @return the mandelbrot number
+ */
public synchronized static int mandelNumber(double x, double y, int repetitions) {
Point p = new Point(x, y);
return mandelNumber(p, repetitions);
}
+ /**
+ * Calculate the Mandelbrot number for a specific point up to some maximum
+ * @param p the point
+ * @param repetitions the maximum
+ * @return the mandelbrot number
+ */
public synchronized static int mandelNumber(Point p, int repetitions) {
if (mandelNumbers.containsKey(p)) {
Result result = mandelNumbers.get(p);
@@ -61,6 +74,12 @@ public class MandelbrotFractal {
}
}
+ /**
+ * Calculate the Mandelbrot number for a specifc point up to some maximum
+ * @param p the point
+ * @param repetitions the maximum
+ * @return the result
+ */
protected synchronized static Result calculateMandelNumber(Point p, int repetitions) {
Result start = new Result();
start.x = p.x;
@@ -69,6 +88,13 @@ public class MandelbrotFractal {
return start;
}
+ /**
+ * Calculate the Mandelbrot number for a specific point up to some maximum,
+ * starting from an earlier result
+ * @param p the point
+ * @param repetitions the maximum
+ * @param start the earlier result; will be updated with the new result
+ */
protected synchronized static void calculateMandelNumber(Point p, int repetitions, Result start) {
int n = start.repetitions;
@@ -82,6 +108,9 @@ public class MandelbrotFractal {
start.mandelNumber = n;
}
+ /**
+ * A point on a coordinate system
+ */
public static class Point {
double x, y;
@@ -113,6 +142,10 @@ public class MandelbrotFractal {
}
}
+ /**
+ * A Mandelbrot result consists of a point, the mandelbrot number and the
+ * maximum with which we calculated that result.
+ */
protected static class Result {
int mandelNumber = -1, repetitions = 0;
double x, y;