Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Лагодич И.Р. 250504 #954

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/demo/parallel/Complex.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ public Complex plus(Complex b) {
return this;
}

/**
* Subtract operation.
* @param b minuend
* @return this Complex object whose value is (this - b)
*/
public Complex minus(Complex b) {
re -= b.re;
im -= b.im;
return this;
}

public double getRe() {
return re;
}

public double getIm() {
return im;
}

/**
* Multiply operation.
* @param b multiplier
Expand Down
16 changes: 8 additions & 8 deletions src/demo/parallel/MandelbrotSetTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ protected Long call() throws Exception {
*/
private int calc(Complex comp) {
int count = 0;
Complex c = new Complex(0, 0);
Complex c = new Complex(0.308, 0);
do {
c = c.times(c).plus(comp);
c = c.times(c).minus(comp);
count++;
} while (count < CAL_MAX_COUNT && c.lengthSQ() < LENGTH_BOUNDARY);
return count;
Expand Down Expand Up @@ -351,20 +351,20 @@ private Color getColor(int count) {
* Color stops for colors table: color values
*/
Color[] cc = {
Color.rgb(40, 0, 0),
Color.VIOLET,
Color.RED,
Color.WHITE,
Color.RED,
Color.rgb(100, 0, 0),
Color.RED,
Color.rgb(50, 0, 0)
Color.CYAN,
Color.PURPLE,
Color.HOTPINK,
Color.MISTYROSE
};

/**
* Color stops for colors table: relative position in the table
*/
double[] cp = {
0, 0.17, 0.25, 0.30, 0.5, 0.75, 1,};
0, 0.10, 0.20, 0.30, 0.5, 0.70, 1,};

/**
* Color table population
Expand Down
19 changes: 19 additions & 0 deletions src/test/demo/parallel/ComplexTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.demo.parallel;

import demo.parallel.Complex;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ComplexTest {

@Test
public void subtractTest() {
Complex a = new Complex(7.0, 2.0);
Complex b = new Complex(3.0, 1.0);
Complex difference = a.minus(b);

assertEquals(4.0, difference.getRe(), 1e-10, "Real part must be 4.0" );
assertEquals(1.0, difference.getIm(), 1e-10, "Imaginary part must be 1.0");
}
}