dcel rdy for test

This commit is contained in:
Armin Wolf 2017-05-30 14:59:06 +02:00
parent 9b986b74f2
commit 6df2c38c14
14 changed files with 155 additions and 95 deletions

11
pom.xml
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -28,5 +28,12 @@
<artifactId>jfreechart</artifactId>
<version>1.0.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>

View File

@ -14,13 +14,13 @@ import javax.swing.*;
public class App {
public static void main(String[] args) {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
MainFrame view = new MainFrame();
view.setPresenter(new Presenter(new Arrangement(), view));
});
SwingUtilities.invokeLater(() -> {
MainFrame view = new MainFrame();
view.setPresenter(new Presenter(new Arrangement(), view));
});
}
}
}

View File

@ -14,16 +14,16 @@ public class Arrangement {
private LinkedList<Coordinates> nodes;
private LinkedList<Coordinates> lines;
public Arrangement(){
public Arrangement() {
nodes = new LinkedList<>();
lines = new LinkedList<>();
}
public void addNode(Coordinates node){
public void addNode(Coordinates node) {
this.nodes.add(node);
}
public void addLine(Coordinates line){
public void addLine(Coordinates line) {
this.lines.add(line);
}
@ -40,5 +40,4 @@ public class Arrangement {
}
}

View File

@ -35,13 +35,13 @@ public class Coordinates implements Comparable<Coordinates> {
@Override
public int compareTo(Coordinates o) {
if(this.getX() == o.getX()){
if (this.getY() <= o.getY()){
if (this.getX() == o.getX()) {
if (this.getY() <= o.getY()) {
return -1;
} else {
return 1;
}
} else if (this.getX() < o.getX()){
} else if (this.getX() < o.getX()) {
return -1;
} else {
return 1;

View File

@ -15,13 +15,13 @@ public class DoublyConnectedEdgeList {
private LinkedList<Edge> edges;
private LinkedList<Face> faces;
public DoublyConnectedEdgeList(){
public DoublyConnectedEdgeList() {
this.nodes = new LinkedList<>();
this.edges = new LinkedList<>();
this.faces = new LinkedList<>();
}
public Node createNode(Coordinates point, String id){
public Node createNode(Coordinates point, String id) {
Node node = new Node();
node.setCoordinates(point);
@ -30,15 +30,17 @@ public class DoublyConnectedEdgeList {
return node;
}
public Edge createEdge(Node source, Node destination, String id){
public Edge createEdge(Node source, Node destination, String id) {
Edge edge = new Edge();
Edge twin = new Edge();
edge.setOrigin(source);
edge.setID(id);
edge.setTwin(twin);
twin.setOrigin(destination);
twin.setID("#"+id);
twin.setID("#" + id);
twin.setTwin(edge);
source.setIncidentEdge(edge);
destination.setIncidentEdge(twin);
@ -46,14 +48,14 @@ public class DoublyConnectedEdgeList {
return edge;
}
public Face createFace(Edge outerComponent, Edge innerComponent, String id){
public Face createFace(Edge outerComponent, Edge innerComponent, String id) {
Face face = new Face();
face.setOuterComponent(outerComponent);
face.setID(id);
Edge tempEdge;
if (!outerComponent.equals(null)){
if (outerComponent != null) {
tempEdge = outerComponent;
do {
tempEdge.setIncidentFace(face);
@ -61,8 +63,9 @@ public class DoublyConnectedEdgeList {
} while (!tempEdge.equals(outerComponent));
}
if (!innerComponent.equals(null)){
LinkedList<Edge> componentlist = face.getInnerComponents();
if (innerComponent != null) {
LinkedList<Edge> componentlist;
componentlist = face.getInnerComponents();
componentlist.add(innerComponent);
tempEdge = innerComponent;
do {
@ -74,12 +77,32 @@ public class DoublyConnectedEdgeList {
return null;
}
public void createConnection(Edge edge, Edge pred){
edge.setPrev(pred);
pred.setNext(edge);
public void createConnection(Edge edge, Edge succ) {
edge.setNext(succ);
succ.setPrev(edge);
}
public LinkedList<Node> getNodes() {
return nodes;
}
public void setNodes(LinkedList<Node> nodes) {
this.nodes = nodes;
}
public LinkedList<Edge> getEdges() {
return edges;
}
public void setEdges(LinkedList<Edge> edges) {
this.edges = edges;
}
public LinkedList<Face> getFaces() {
return faces;
}
public void setFaces(LinkedList<Face> faces) {
this.faces = faces;
}
}

View File

@ -16,11 +16,11 @@ public class Edge {
private Edge prev;
private String id;
public Edge(){
public Edge() {
new Edge(null, null, null, null, null);
}
public Edge(Node origin, Edge twin, Edge next, Edge prev, Face incidentFace){
public Edge(Node origin, Edge twin, Edge next, Edge prev, Face incidentFace) {
this.origin = origin;
this.twin = twin;
this.next = next;
@ -68,8 +68,8 @@ public class Edge {
this.prev = prev;
}
public boolean hasNext(){
if (getNext() == null){
public boolean hasNext() {
if (getNext() == null) {
return false;
} else {
return true;
@ -77,7 +77,7 @@ public class Edge {
}
public Edge insertNode(Node node){
public Edge insertNode(Node node) {
Edge edge = new Edge();
Edge twin = new Edge();
@ -107,11 +107,11 @@ public class Edge {
return edge;
}
public String getID(){
public String getID() {
return this.id;
}
public void setID(String id){
public void setID(String id) {
this.id = id;
}
}

View File

@ -1,6 +1,5 @@
package Model;
import java.util.Iterator;
import java.util.LinkedList;
/**
@ -16,11 +15,12 @@ public class Face {
private Edge outerComponent;
private String id;
public Face(){
public Face() {
new Face(null, null);
this.innerComponents = new LinkedList<>();
}
public Face(Edge outerComponent, LinkedList<Edge> innerComponents){
public Face(Edge outerComponent, LinkedList<Edge> innerComponents) {
this.outerComponent = outerComponent;
this.innerComponents = innerComponents;
}
@ -41,9 +41,9 @@ public class Face {
this.outerComponent = outerComponent;
}
public Face insertEdge(Edge edgeWithSameDestination, Edge edgeToMySource){
public Face insertEdge(Edge edgeWithSameDestination, Edge edgeToMySource) {
if (edgeWithSameDestination.getIncidentFace().equals(this) || edgeToMySource.getIncidentFace().equals(this)){
if (edgeWithSameDestination.getIncidentFace().equals(this) || edgeToMySource.getIncidentFace().equals(this)) {
LinkedList<Edge> components = new LinkedList<Edge>();
for (Edge e : innerComponents) {
components.add(e);
@ -65,12 +65,12 @@ public class Face {
Edge tempEdge = edge.getNext();
Edge tempTwin = twin.getNext();
//kreis umlaufen um festzustellen welche fläche kleiner ist
while ((tempEdge.equals(edge) == false) && (tempTwin.equals(twin) == false)){
while ((tempEdge.equals(edge) == false) && (tempTwin.equals(twin) == false)) {
tempEdge = tempEdge.getNext();
tempTwin = tempTwin.getNext();
}
if (tempEdge.equals(edge)){
if (tempEdge.equals(edge)) {
setOuterComponent(twin);
twin.setIncidentFace(this);
face.setOuterComponent(edge);
@ -80,18 +80,18 @@ public class Face {
face.setOuterComponent(twin);
}
LinkedList<Edge> bla = new LinkedList<Edge>();
LinkedList<Edge> bla = new LinkedList<Edge>();
Edge iterEdge = face.getOuterComponent();
bla.add(face.getOuterComponent());
while (iterEdge.hasNext()){
while (iterEdge.hasNext()) {
bla.add(iterEdge.getNext());
iterEdge = iterEdge.getNext();
}
for (Edge e : face.getInnerComponents()) {
iterEdge = e;
while (iterEdge.hasNext()){
while (iterEdge.hasNext()) {
bla.add(iterEdge.getNext());
iterEdge = iterEdge.getNext();
}
@ -107,11 +107,11 @@ public class Face {
}
public String getID(){
public String getID() {
return this.id;
}
public void setID(String id){
public void setID(String id) {
this.id = id;
}
}

View File

@ -13,11 +13,11 @@ public class Node {
private Edge incidentEdge;
private String id;
public Node(){
public Node() {
new Node(null, null);
}
public Node(Coordinates coordinates, Edge incidentEdge){
public Node(Coordinates coordinates, Edge incidentEdge) {
this.coordinates = coordinates;
this.incidentEdge = incidentEdge;
}
@ -38,11 +38,11 @@ public class Node {
this.incidentEdge = incidentEdge;
}
public String getID(){
public String getID() {
return this.id;
}
public void setID(String id){
public void setID(String id) {
this.id = id;
}
}

View File

@ -2,7 +2,7 @@ package Presenter;
import Model.Arrangement;
import Model.Coordinates;
import View.*;
import View.MainFrame;
import java.util.Collections;
import java.util.LinkedList;
@ -24,28 +24,28 @@ public class Presenter {
private Double max;
private Double min;
public Presenter(Arrangement model, MainFrame view){
public Presenter(Arrangement model, MainFrame view) {
this.model = model;
this.view = view;
this.view = view;
Double[] x = {1d,2d,3d,4d,10d,12d,18d};
Double[] y = {9d,15d,19d,20d,45d,55d,78d};
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};
view.log("Koordinaten der Punkte:");
for (int j=0;j<7;j++){
for (int j = 0; j < 7; j++) {
Coordinates p = new Coordinates(x[j], y[j]);
view.log("f(x) = "+p.getX()+"* x + "+p.getY());
view.log("f(x) = " + p.getX() + "* x + " + p.getY());
this.model.addLine(p);
}
view.log("");
calcArrangementNodes();
//print
for (Coordinates p : model.getNodes()) {
view.log(p.getX()+", "+p.getY());
view.log(p.getX() + ", " + p.getY());
}
extractBounds();
}
@ -66,11 +66,11 @@ public class Presenter {
view.createArrangement();
}
public void startScatterPlotVisualization(){
public void startScatterPlotVisualization() {
view.createPlot();
}
private void extractBounds(){
private void extractBounds() {
Coordinates pmax = Collections.max(model.getLines());
Coordinates pmin = Collections.min(model.getLines());
@ -78,11 +78,11 @@ public class Presenter {
min = pmin.getX() <= pmin.getY() ? pmin.getX() : pmin.getY();
}
public Coordinates calcIntersection(Coordinates a, Coordinates b){
public Coordinates calcIntersection(Coordinates a, Coordinates b) {
Coordinates p1;
Coordinates p2;
if (a.compareTo(b) > 0){
if (a.compareTo(b) > 0) {
p1 = a;
p2 = b;
} else {
@ -92,17 +92,17 @@ public class Presenter {
Double x = (p1.getY() - p2.getY()) / (p2.getX() - p1.getX());
Double y = ((p1.getX() * p2.getY()) - (p2.getX() * p1.getY())) / (p1.getX() - p2.getX());
System.out.printf("RESULT: (%3.3f, %3.3f)\n",x, y);
System.out.printf("RESULT: (%3.3f, %3.3f)\n", x, y);
return new Coordinates(x,y);
return new Coordinates(x, y);
}
public void calcArrangementNodes(){
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++){
for (int i = 0; i < getLines().size(); i++) {
for (int j = i; j < getLines().size(); j++) {
if (i != j)
model.addNode(calcIntersection(getLines().get(j), getLines().get(i)));
}
@ -117,6 +117,7 @@ public class Presenter {
}
}
/***************************************************************************************************************************
* Getter und Setter Methoden
***************************************************************************************************************************/

View File

@ -4,16 +4,15 @@ import Model.Coordinates;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import javax.swing.*;
import java.awt.*;
import java.awt.Dimension;
import java.util.LinkedList;
/**
@ -34,12 +33,12 @@ public class ArrangementDialog extends JPanel {
private double domainMin, domainMax;
private double rangeMin, rangeMax;
public ArrangementDialog(){
public ArrangementDialog() {
super();
this.setPreferredSize(new Dimension(800,500));
this.setPreferredSize(new Dimension(800, 500));
}
public void setPrameters(Double pmax, Double pmin, LinkedList<Coordinates> lines, LinkedList<Coordinates> points){
public void setPrameters(Double pmax, Double pmin, LinkedList<Coordinates> lines, LinkedList<Coordinates> points) {
this.max = pmax;
this.min = pmin;
this.lines = lines;
@ -50,11 +49,11 @@ public class ArrangementDialog extends JPanel {
this.rangeMax = Double.MIN_VALUE;
}
public void createArrangement(){
public void createArrangement() {
XYSeriesCollection dataset = new XYSeriesCollection();
for (Coordinates p : lines) {
XYSeries series = new XYSeries(p.getX()+p.getY());
XYSeries series = new XYSeries(p.getX() + p.getY());
series.add((-1 * this.max), (((-1 * this.max) * p.getX()) + p.getY()));
series.add(this.max, ((this.max * p.getX()) + p.getY()));
dataset.addSeries(series);
@ -72,14 +71,14 @@ public class ArrangementDialog extends JPanel {
chart = ChartFactory.createXYLineChart(
null, null, null, dataset,
PlotOrientation.HORIZONTAL, false, false, false );
PlotOrientation.HORIZONTAL, false, false, false);
final XYPlot plot = chart.getXYPlot();
ValueAxis domain = plot.getDomainAxis();
ValueAxis range = plot.getRangeAxis();
ValueAxis range = plot.getRangeAxis();
domain.setRange(domainMin-1,domainMax+1);
range.setRange(rangeMin-1,rangeMax+1);
domain.setRange(domainMin - 1, domainMax + 1);
range.setRange(rangeMin - 1, rangeMax + 1);
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
@ -93,6 +92,4 @@ public class ArrangementDialog extends JPanel {
}
}

View File

@ -32,7 +32,7 @@ public class MainFrame extends JFrame {
private ArrangementDialog arrangement;
private PlotDialog plot;
public MainFrame(){
public MainFrame() {
initGUI();
}
@ -49,7 +49,7 @@ public class MainFrame extends JFrame {
*/
public void createArrangement() {
if (arrangement == null){
if (arrangement == null) {
arrangement = new ArrangementDialog();
arrangement.setPrameters(getPresenter().getMax(), getPresenter().getMin(), getPresenter().getLines(), getPresenter().getModel().getNodes());
arrangement.createArrangement();
@ -70,7 +70,7 @@ public class MainFrame extends JFrame {
}
public void createPlot() {
if (plot == null){
if (plot == null) {
plot = new PlotDialog();
plot.createPlot(getPresenter().getLines());
SwingUtilities.invokeLater(new Runnable() {
@ -90,7 +90,7 @@ public class MainFrame extends JFrame {
* log Methode
*/
public void log(String s){
public void log(String s) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
@ -102,9 +102,9 @@ public class MainFrame extends JFrame {
/**
* init GUI
*/
protected void initGUI(){
protected void initGUI() {
this.setTitle("MainFrame");
this.setSize(500,400);
this.setSize(500, 400);
this.setLayout(new BorderLayout());
pane = new JPanel();
pane.setLayout(new FlowLayout());
@ -112,9 +112,9 @@ public class MainFrame extends JFrame {
menupanel = new MenuPanel();
arrangementDialog = new JDialog();
plotDialog = new JDialog();
arrangementDialog.setSize(new Dimension(700,470));
plotDialog.setSize(new Dimension(700,470));
plotDialog = new JDialog();
arrangementDialog.setSize(new Dimension(700, 470));
plotDialog.setSize(new Dimension(700, 470));
arrangementDialog.setTitle("Arrangement Dialog");
plotDialog.setTitle("Scatter Plot Dialog");
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

View File

@ -1,7 +1,5 @@
package View;
import org.jfree.ui.action.ActionMenuItem;
import javax.swing.*;
import java.awt.*;
@ -12,17 +10,17 @@ import java.awt.*;
* @Email: a_wolf28@uni-muenster.de
* @Date: 29.05.2017.
*/
public class MenuPanel extends JPanel{
public class MenuPanel extends JPanel {
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem item;
public MenuPanel(){
public MenuPanel() {
this.setLayout(new BorderLayout());
this.menuBar = new JMenuBar();
this.menu = new JMenu("File");
this.item = new JMenuItem("Exit");
this.menu = new JMenu("File");
this.item = new JMenuItem("Exit");
menu.add(item);

View File

@ -39,7 +39,7 @@ public class PlotDialog extends JPanel {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
convertData(points);
convertData(points);
}
});
thread.start();

View File

@ -0,0 +1,35 @@
package Model;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 30.05.2017.
*/
public class DoublyConnectedEdgeListTest {
private static DoublyConnectedEdgeList dcel;
private static Node v1, v2, v3 ,v4, v5;
private static Edge e1, e2, e3, e4, e5, e6;
private static Face f1, f2, f3;
@Before
public void setUp() throws Exception {
dcel = new DoublyConnectedEdgeList();
}
@Test
public void testCases(){
}
}