Corrected tests and implemented rotation of points.

pull/35/head
James Ball 2020-01-29 18:47:25 +00:00
rodzic 891eebe79a
commit 33f867dba4
4 zmienionych plików z 29 dodań i 26 usunięć

Wyświetl plik

@ -1,5 +1,8 @@
import com.xtaudio.xt.*;
import java.util.ArrayList;
import java.util.List;
public class AudioClient {
public static void main(String[] args) throws Exception {
int sampleRate = 192000;
@ -25,4 +28,12 @@ public class AudioClient {
}
}
public static List<Line> generatePolygon(int sides, double scale) {
List<Line> polygon = new ArrayList<>();
Point start = new Point(scale, scale);
return null;
}
}

Wyświetl plik

@ -17,19 +17,7 @@ public class Line {
}
public Line rotate(double theta) {
double x1 = getX1();
double y1 = getY1();
double x2 = getX2();
double y2 = getY2();
Line line = new Line(x1, y1, x2, y2);
line.setX1(x1 * Math.cos(theta) - y1 * Math.sin(theta));
line.setY1(x1 * Math.sin(theta) + y1 * Math.cos(theta));
line.setX2(x2 * Math.cos(theta) - y2 * Math.sin(theta));
line.setY2(x2 * Math.sin(theta) + y2 * Math.cos(theta));
return line;
return new Line(getA().rotate(theta), getB().rotate(theta));
}
public Point getA() {

Wyświetl plik

@ -38,6 +38,18 @@ public class Point {
}
}
public Point rotate(double theta) {
double oldX = getX();
double oldY = getY();
Point point = new Point(oldX, oldY);
point.setX(oldX * Math.cos(theta) - oldY * Math.sin(theta));
point.setY(oldX * Math.sin(theta) + oldY * Math.cos(theta));
return point;
}
private boolean approxEquals(double m, double n) {
return Math.abs(m - n) < EPSILON;
}

Wyświetl plik

@ -7,24 +7,16 @@ public class TestSuite {
public void lineRotationTest1() {
Line line = new Line(-0.5, 0.5, 0.5, 0.5);
line.rotate(Math.PI / 2);
assertEquals(new Line(-0.5, -0.5, -0.5, 0.5), line);
line.rotate(Math.PI / 2);
assertEquals(new Line(0.5, -0.5, -0.5, -0.5), line);
line.rotate(Math.PI / 2);
assertEquals(new Line(0.5, 0.5, 0.5, -0.5), line);
line.rotate(Math.PI / 2);
assertEquals(new Line(-0.5, 0.5, 0.5, 0.5), line);
assertEquals(new Line(-0.5, -0.5, -0.5, 0.5), line.rotate(Math.PI / 2));
assertEquals(new Line(0.5, -0.5, -0.5, -0.5), line.rotate(Math.PI));
assertEquals(new Line(0.5, 0.5, 0.5, -0.5), line.rotate(3 * Math.PI / 2));
assertEquals(new Line(-0.5, 0.5, 0.5, 0.5), line.rotate(2 * Math.PI));
}
@Test
public void lineRotationTest2() {
Line line = new Line(-0.5, -0.5, -0.25, 0.5);
line.rotate(Math.PI / 2);
assertEquals(new Line(0.5, -0.5, -0.5, -0.25), line);
assertEquals(new Line(0.5, -0.5, -0.5, -0.25), line.rotate(Math.PI / 2));
}
}