Skip to content
Snippets Groups Projects
Commit 7f8974fa authored by Edvard Berdal Eek's avatar Edvard Berdal Eek
Browse files

Merge branch 'feat/linalg' into 'main'

Feat/linalg

See merge request !1
parents e9064d3b eb7a5ea1
No related branches found
Tags v0.1
1 merge request!1Feat/linalg
Pipeline #288201 passed with stages
in 1 minute and 16 seconds
package org.example.chaosgame.linalg;
public class Complex {
public class Complex extends Vector2D {
public Complex(double x, double y) {
super(x, y);
}
public Complex sqrt(double cRe, double cIm) {
double a = Math.pow(cRe, 2) + Math.pow(cIm, 2);
double r = Math.sqrt(0.5 * (Math.sqrt(a) + cRe));
double i = Math.signum(cIm) * Math.sqrt(0.5 * (Math.sqrt(a) - cRe));
return new Complex(r, i);
}
}
package org.example.chaosgame.linalg;
public class Matrix2x2 {
private final double a, b, c, d;
public Matrix2x2(double a, double b, double c, double d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public double getA() {
return a;
}
public double getB() {
return b;
}
public double getC() {
return c;
}
public double getD() {
return d;
}
public Vector2D multiply(Vector2D vector) {
return new Vector2D(
a * vector.getX() + b * vector.getY(),
c * vector.getX() + d * vector.getY()
);
}
}
package org.example.chaosgame.linalg;
public class Vector2D {
private final double x;
private final double y;
public Vector2D(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public Vector2D add(Vector2D other) {
return new Vector2D(x + other.x, y + other.y);
}
public Vector2D subtract(Vector2D other) {
return new Vector2D(x - other.x, y - other.y);
}
}
package org.example.chaosgame.transformations;
public class AffineTransform2D {
public class AffineTransform2D implements Transform2D{
}
package org.example.chaosgame.transformations;
public class JuliaTransform {
public class JuliaTransform implements Transform2D{
}
package org.example.chaosgame.transformations;
public class Transform2D {
public interface Transform2D{
}
package org.example.chaosgame.linalg;
import org.junit.jupiter.api.Test;
import java.text.DecimalFormat;
import static org.junit.jupiter.api.Assertions.*;
class ComplexTest {
private final double x = 0.1;
private final double y = -0.4;
Complex complex = new Complex(x, y);
@Test
void sqrt() {
Complex z = complex.sqrt(x, y);
assertEquals(0.5061178531536732, z.getX());
assertEquals(-0.3951648786024424, z.getY());
}
}
\ No newline at end of file
package org.example.chaosgame.linalg;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class Matrix2x2Test {
private final double a = 1.0;
private final double b = 2.0;
private final double c = 3.0;
private final double d = 4.0;
Matrix2x2 matrix = new Matrix2x2(a, b, c, d);
Vector2D vector = new Vector2D(1.0, 2.0);
@Test
void getA() {
}
@Test
void getB() {
}
@Test
void getC() {
}
@Test
void getD() {
}
@Test
void multiply() {
Vector2D w = matrix.multiply(vector);
assertEquals(5.0, w.getX());
assertEquals(11.0, w.getY());
}
}
\ No newline at end of file
package org.example.chaosgame.linalg;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class Vector2DTest {
private final double x = 1.0;
private final double y = 2.0;
Vector2D vector = new Vector2D(x, y);
@Test
void getX() {
assertEquals(1.0, vector.getX());
}
@Test
void getY() {
assertEquals(2.0, vector.getY());
}
@Test
void add() {
Vector2D w = vector.add(new Vector2D(1.0, 1.0));
assertEquals(2.0, w.getX());
assertEquals(3.0, w.getY());
}
@Test
void subtract() {
Vector2D w = vector.subtract(new Vector2D(1.0, 1.0));
assertEquals(0.0, w.getX());
assertEquals(1.0, w.getY());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment