algorithms-for-computing-li.../src/main/java/Presenter/Presenter.java

165 lines
4.0 KiB
Java
Raw Normal View History

2017-05-28 12:00:01 +00:00
package Presenter;
import Model.Arrangement;
2017-05-30 10:28:59 +00:00
import Model.Coordinates;
import View.*;
import java.util.Collections;
import java.util.LinkedList;
2017-05-28 12:00:01 +00:00
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class Presenter {
private Arrangement model;
2017-05-29 15:08:58 +00:00
private MainFrame view;
private Double max;
private Double min;
2017-05-29 15:08:58 +00:00
public Presenter(Arrangement model, MainFrame view){
this.model = model;
this.view = view;
2017-05-29 16:08:47 +00:00
2017-05-29 13:42:25 +00:00
Double[] x = {1d,2d,3d,4d,10d,12d,18d};
Double[] y = {9d,15d,19d,20d,45d,55d,78d};
// Float[] x = {18f,24f,30f,34f,38f};
// Float[] y = {18f,26f,30f,40f,70f};
// Double[] x = {1d,3d,4d,5d,8d};
// Double[] y = {4d,2d,1d,0d,0d};
2017-05-29 15:08:58 +00:00
view.log("Koordinaten der Punkte:");
2017-05-29 13:42:25 +00:00
for (int j=0;j<7;j++){
2017-05-30 10:28:59 +00:00
Coordinates p = new Coordinates(x[j], y[j]);
2017-05-29 15:08:58 +00:00
view.log("f(x) = "+p.getX()+"* x + "+p.getY());
2017-05-29 16:08:47 +00:00
this.model.addLine(p);
2017-05-29 13:42:25 +00:00
}
2017-05-29 15:08:58 +00:00
view.log("");
2017-05-29 16:08:47 +00:00
calcArrangementNodes();
//print
2017-05-30 10:28:59 +00:00
for (Coordinates p : model.getNodes()) {
2017-05-29 16:08:47 +00:00
view.log(p.getX()+", "+p.getY());
}
2017-05-29 13:42:25 +00:00
extractBounds();
}
public void getDataFromModel() {
}
public void setDataByModel() {
}
public void getActionsFromView() {
}
2017-05-29 13:42:25 +00:00
public void startArrangementVisualization() {
view.createArrangement();
}
2017-05-29 13:42:25 +00:00
public void startScatterPlotVisualization(){
view.createPlot();
}
private void extractBounds(){
2017-05-30 10:28:59 +00:00
Coordinates pmax = Collections.max(model.getLines());
Coordinates pmin = Collections.min(model.getLines());
max = pmax.getX() >= pmax.getY() ? pmax.getX() : pmax.getY();
min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
}
2017-05-30 10:28:59 +00:00
public Coordinates calcIntersection(Coordinates a, Coordinates b){
Coordinates p1;
Coordinates p2;
2017-05-29 16:08:47 +00:00
2017-05-30 10:28:59 +00:00
if (a.compareTo(b) > 0){
2017-05-29 16:08:47 +00:00
p1 = a;
p2 = b;
} else {
p1 = b;
p2 = a;
}
2017-05-30 10:28:59 +00:00
Double x = (p1.getY() - p2.getY()) / (p2.getX() - p1.getX());
Double y = ((p1.getX() * p2.getY()) - (p2.getX() * p1.getY())) / (p1.getX() - p2.getX());
2017-05-29 16:08:47 +00:00
System.out.printf("RESULT: (%3.3f, %3.3f)\n",x, y);
2017-05-30 10:28:59 +00:00
return new Coordinates(x,y);
2017-05-29 16:08:47 +00:00
}
public void calcArrangementNodes(){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for (int i=0;i<getLines().size();i++){
for (int j=i;j<getLines().size();j++){
if (i != j)
2017-05-30 10:28:59 +00:00
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
2017-05-29 16:08:47 +00:00
}
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
2017-05-29 13:42:25 +00:00
/***************************************************************************************************************************
* Getter und Setter Methoden
***************************************************************************************************************************/
public Arrangement getModel() {
return model;
}
public void setModel(Arrangement model) {
this.model = model;
}
2017-05-29 15:08:58 +00:00
public MainFrame getView() {
return view;
}
2017-05-29 15:08:58 +00:00
public void setView(MainFrame view) {
this.view = view;
}
2017-05-30 10:28:59 +00:00
public LinkedList<Coordinates> getLines() {
2017-05-29 16:08:47 +00:00
return this.model.getLines();
}
2017-05-28 12:00:01 +00:00
2017-05-30 10:28:59 +00:00
public void setLines(LinkedList<Coordinates> lines) {
2017-05-29 16:08:47 +00:00
this.model.setLines(lines);
}
2017-05-28 12:00:01 +00:00
public Double getMax() {
return max;
}
2017-05-28 12:00:01 +00:00
public void setMax(Double max) {
this.max = max;
}
2017-05-28 12:00:01 +00:00
public Double getMin() {
return min;
}
2017-05-28 12:00:01 +00:00
public void setMin(Double min) {
this.min = min;
}
2017-05-28 12:00:01 +00:00
}