diff --git a/.idea/oscilloscope-experiments.iml b/.idea/oscilloscope-experiments.iml
index 2e47cbd..3d2d867 100644
--- a/.idea/oscilloscope-experiments.iml
+++ b/.idea/oscilloscope-experiments.iml
@@ -9,5 +9,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/AudioPlayer.java b/src/AudioPlayer.java
index c8c02bf..1414e8b 100644
--- a/src/AudioPlayer.java
+++ b/src/AudioPlayer.java
@@ -21,11 +21,11 @@ public class AudioPlayer extends Thread {
line.rotate(nextTheta(stream.getFormat().mix.rate, 0.000001));
int framesToDraw = (int) (line.length() * 100);
- //int neg = line.getX1() < line.getX2() || line.getY1() < line.getY2() ? 1 : -1;
+ int neg = line.getX1() < line.getX2() || line.getY1() < line.getY2() ? 1 : -1;
for (int c = 0; c < format.outputs; c++) {
- ((float[]) output)[f * format.outputs] = line.getX1() + Math.abs(line.getX2() - line.getX1()) * (float) (framesDrawn) / framesToDraw;
- ((float[]) output)[f * format.outputs + 1] = line.getY1() + Math.abs(line.getY2() - line.getY1()) * (float) (framesDrawn) / framesToDraw;
+ ((float[]) output)[f * format.outputs] = (float) (line.getX1() + Math.abs(line.getX2() - line.getX1()) * (neg * framesDrawn) / framesToDraw);
+ ((float[]) output)[f * format.outputs + 1] = (float) (line.getY1() + Math.abs(line.getY2() - line.getY1()) * (neg * framesDrawn) / framesToDraw);
}
framesDrawn++;
diff --git a/src/Line.java b/src/Line.java
index a2e19b3..1779378 100644
--- a/src/Line.java
+++ b/src/Line.java
@@ -7,20 +7,20 @@ public class Line {
this.b = b;
}
- public Line(float x1, float y1, float x2, float y2) {
+ public Line(double x1, double y1, double x2, double y2) {
this.a = new Point(x1, y1);
this.b = new Point(x2, y2);
}
- public float length() {
- return (float) Math.sqrt(Math.pow(getX1() - getX2(), 2) + Math.pow(getY1() - getY2(), 2));
+ public double length() {
+ return Math.sqrt(Math.pow(getX1() - getX2(), 2) + Math.pow(getY1() - getY2(), 2));
}
public void rotate(double theta) {
- setX1((float) (getX1() * Math.cos(theta) - getY1() * Math.sin(theta)));
- setY1((float) (getX1() * Math.sin(theta) + getY1() * Math.cos(theta)));
- setX2((float) (getX2() * Math.cos(theta) - getY2() * Math.sin(theta)));
- setY2((float) (getX2() * Math.sin(theta) + getY2() * Math.cos(theta)));
+ setX1(getX1() * Math.cos(theta) - getY1() * Math.sin(theta));
+ setY1(getX1() * Math.sin(theta) + getY1() * Math.cos(theta));
+ setX2(getX2() * Math.cos(theta) - getY2() * Math.sin(theta));
+ setY2(getX2() * Math.sin(theta) + getY2() * Math.cos(theta));
}
public Point getA() {
@@ -31,35 +31,48 @@ public class Line {
return b;
}
- public float getX1() {
+ public double getX1() {
return a.getX();
}
- public float getY1() {
+ public double getY1() {
return a.getY();
}
- public float getX2() {
+ public double getX2() {
return b.getX();
}
- public float getY2() {
+ public double getY2() {
return b.getY();
}
- public void setX1(float x1) {
+ public void setX1(double x1) {
a.setX(x1);
}
- public void setY1(float y1) {
+ public void setY1(double y1) {
a.setY(y1);
}
- public void setX2(float x2) {
+ public void setX2(double x2) {
b.setX(x2);
}
- public void setY2(float y2) {
+ public void setY2(double y2) {
b.setY(y2);
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof Line) {
+ Line line = (Line) obj;
+
+ return line.getA().equals(getA()) && line.getB().equals(getB());
+ } else {
+ return false;
+ }
+ }
}
diff --git a/src/Point.java b/src/Point.java
index d064af9..4669fc0 100644
--- a/src/Point.java
+++ b/src/Point.java
@@ -1,25 +1,44 @@
public class Point {
- private float x;
- private float y;
+ private double x;
+ private double y;
- public Point(float x, float y) {
+ private static final double EPSILON = 0.0001;
+
+ public Point(double x, double y) {
this.x = x;
this.y = y;
}
- public float getX() {
+ public double getX() {
return x;
}
- public float getY() {
+ public double getY() {
return y;
}
- public void setX(float x) {
+ public void setX(double x) {
this.x = x;
}
- public void setY(float y) {
+ public void setY(double y) {
this.y = y;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof Point) {
+ Point point = (Point) obj;
+
+ return approxEquals(point.getX(), getX()) && approxEquals(point.getY(), getY());
+ } else {
+ return false;
+ }
+ }
+
+ private boolean approxEquals(double m, double n) {
+ return Math.abs(m - n) < EPSILON;
+ }
}
diff --git a/test/TestSuite.java b/test/TestSuite.java
new file mode 100644
index 0000000..c3182dd
--- /dev/null
+++ b/test/TestSuite.java
@@ -0,0 +1,13 @@
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestSuite {
+ @Test
+ public void lineRotationTest() {
+ 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);
+ }
+}
\ No newline at end of file