Commit da932333 authored by Peter Lundin's avatar Peter Lundin
Browse files

Initial commit

parent 9b139b96
...@@ -32,8 +32,10 @@ public class Coordinate{ ...@@ -32,8 +32,10 @@ public class Coordinate{
} }
public void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY){ public void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY){
this.x = (int)Math.round(lat * scaleX + offsetX); // this.x = (int)Math.round(lat * scaleX + offsetX);
this.y = (int)Math.round(lon * scaleY + offsetY); // this.y = (int)Math.round(lon * scaleY + offsetY);
this.x = (int)Math.round(c * scaleX + offsetX);
this.y = (int)Math.round(r * scaleY + offsetY);
} }
...@@ -49,7 +51,24 @@ public class Coordinate{ ...@@ -49,7 +51,24 @@ public class Coordinate{
@Override @Override
public String toString(){ public String toString(){
return "[" + lat + ", " + lon + "] => " + value; StringBuilder sb = new StringBuilder();
sb.append("(lat,lon) [");
sb.append(lat);
sb.append( ", ");
sb.append(lon);
sb.append("] => ");
sb.append("Matrix (r,c) [");
sb.append(r);
sb.append( ", ");
sb.append(c);
sb.append("] => ");
sb.append("Canvas(x,y) [");
sb.append(x);
sb.append( ", ");
sb.append(y);
sb.append("] => ");
sb.append(value);
return sb.toString();
} }
public boolean equals(Coordinate coord){ public boolean equals(Coordinate coord){
......
...@@ -188,7 +188,26 @@ public class Coordinates extends ArrayList<Coordinate>{ ...@@ -188,7 +188,26 @@ public class Coordinates extends ArrayList<Coordinate>{
private int getIndexFromCoord(int row, int col){ private int getIndexFromCoord(int row, int col){
int index; int index;
index = row * getCols() + col; index = row * getCols()-1 + col;
return index; return index;
} }
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("Matrix corners:\r\n");
sb.append(getCoordinate(0,0));
sb.append("\r\n");
sb.append(getCoordinate(0,getCols()));
sb.append("\r\n");
sb.append(getCoordinate(getRows(),0));
sb.append("\r\n");
sb.append(getCoordinate(getRows(),getCols()));
sb.append("\r\n");
sb.append("Number of grindpoints: ");
sb.append(size());
sb.append("\r\n");
return sb.toString();
}
} }
...@@ -17,10 +17,10 @@ import javax.swing.JFrame; ...@@ -17,10 +17,10 @@ import javax.swing.JFrame;
public class GUI extends JFrame{ public class GUI extends JFrame{
private final Polygons polygons = new Polygons(); private final Polygons polygons = new Polygons();
private final Coordinates coords; private final Coordinates coords;
int offsetX = 1000; int offsetX = 100;
int offsetY = 3000;//-2000; int offsetY = 100;//3000;//-2000;
double scaleX = -25; double scaleX = 1;
double scaleY = -40; double scaleY = 1;
public GUI(Coordinates coords){ public GUI(Coordinates coords){
this.coords = coords; this.coords = coords;
...@@ -50,34 +50,58 @@ public class GUI extends JFrame{ ...@@ -50,34 +50,58 @@ public class GUI extends JFrame{
coords.fitToFrame(offsetX, offsetY, scaleX, scaleY); coords.fitToFrame(offsetX, offsetY, scaleX, scaleY);
g.setColor(Color.LIGHT_GRAY); g.setColor(Color.LIGHT_GRAY);
int s = 15; int s = 15;
for(int r = 0; r<coords.getRows()-s; r=r+s) int x11;
for(int c = 0; c<coords.getCols()-s; c=c+s){ int x21;
int x11 = coords.getCoordinate(r, c).x; int x12;
int x12 = coords.getCoordinate(r, c+s).x; int y11;
int x21 = coords.getCoordinate(r+s, c).x; int y21;
int y11 = coords.getCoordinate(r, c).y; int y12;
int y12 = coords.getCoordinate(r, c+s).y; int x1;
int y21 = coords.getCoordinate(r+s, c).y; int x2;
int y1;
int y2;
int rMax=coords.getRows()-1; // last col
int cMax=coords.getCols()-1; // last row
for(int r = 0; r<coords.getRows(); r=r+s)
for(int c = 0; c<coords.getCols(); c=c+s){
x11 = coords.getCoordinate(r, c).x;
y11 = coords.getCoordinate(r, c).y;
if(c+s < cMax){
x12 = coords.getCoordinate(r, c+s).x;
y12 = coords.getCoordinate(r, c+s).y;
}
else{
x12 = coords.getCoordinate(r, cMax).x;
y12 = coords.getCoordinate(r, cMax).y;
}
if(r+s < rMax){
x21 = coords.getCoordinate(r+s, c).x;
y21 = coords.getCoordinate(r+s, c).y;
}
else{
x21 = coords.getCoordinate(rMax, c).x;
y21 = coords.getCoordinate(rMax, c).y;
}
g.drawLine(x11, y11, x12, y12); g.drawLine(x11, y11, x12, y12);
g.drawLine(x11, y11, x21, y21); g.drawLine(x11, y11, x21, y21);
} }
int cc=coords.getCols()-1; // last row
for(int r = 0; r<coords.getRows()-s; r=r+s){ for(int r = 0; r<coords.getRows()-s; r=r+s){
int x1 = coords.getCoordinate(r, cc).x; x1 = coords.getCoordinate(r, cMax).x;
int x2 = coords.getCoordinate(r+s, cc).x; x2 = coords.getCoordinate(r+s, cMax).x;
int y1 = coords.getCoordinate(r, cc).y; y1 = coords.getCoordinate(r, cMax).y;
int y2 = coords.getCoordinate(r+s, cc).y; y2 = coords.getCoordinate(r+s, cMax).y;
g.drawLine(x1, y1, x2, y2); g.drawLine(x1, y1, x2, y2);
} }
int rr=coords.getRows()-1; // last col
for(int c = 0; c<coords.getCols()-s; c=c+s){ for(int c = 0; c<coords.getCols()-s; c=c+s){
int x1 = coords.getCoordinate(rr, c).x; x1 = coords.getCoordinate(rMax, c).x;
int x2 = coords.getCoordinate(rr, c+s).x; x2 = coords.getCoordinate(rMax, c+s).x;
int y1 = coords.getCoordinate(rr, c).y; y1 = coords.getCoordinate(rMax, c).y;
int y2 = coords.getCoordinate(rr, c+s).y; y2 = coords.getCoordinate(rMax, c+s).y;
g.drawLine(x1, y1, x2, y2); g.drawLine(x1, y1, x2, y2);
} }
......
...@@ -61,6 +61,7 @@ public class JSONMatrix{ ...@@ -61,6 +61,7 @@ public class JSONMatrix{
} }
prevLat=lat; prevLat=lat;
} }
System.out.println(coords.toString());
Iterator<Long> keys = statistics.keySet().iterator(); Iterator<Long> keys = statistics.keySet().iterator();
Long key; Long key;
while(keys.hasNext()){ while(keys.hasNext()){
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
package isospline; package isospline;
import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
......
...@@ -39,38 +39,41 @@ public class Polygon extends ArrayList<CoordinatePair>{ ...@@ -39,38 +39,41 @@ public class Polygon extends ArrayList<CoordinatePair>{
public Polygons getSeparatePolygons(String name, Color color){ public Polygons getSeparatePolygons(String name, Color color){
Polygons polygons = new Polygons(); Polygons polygons = new Polygons();
int index; int sortIndex;
while(size()>0){ while(size()>0){
CoordinatePair start = get(0); CoordinatePair start = get(0);
Coordinate next1 = defineNext(start.coord1); Coordinate template1 = defineTemplateForNextCoordinatePair(start.coord1);
Coordinate next2 = defineNext(start.coord2); Coordinate template2 = defineTemplateForNextCoordinatePair(start.coord2);
Polygon polygon = new Polygon(start.coord1.value, name, color); Polygon polygon = new Polygon(start.coord1.value, name, color);
index = 0; sortIndex = 0;
remove(0); remove(0);
boolean closed = false;
for(int i = 1; i<size(); i++){ int searchIndex = findIndexFor(template1);
if(get(i).hasEqual(next1)){
CoordinatePair coordPair = get(i); while(searchIndex>0){
coordPair.polygonOrder=index; CoordinatePair coordPair = get(searchIndex);
polygon.add(coordPair); coordPair.polygonOrder=sortIndex;
remove(i); polygon.add(coordPair);
next1 = coordPair.getOpposite(next1); remove(searchIndex);
index++; template1 = coordPair.getOpposite(template1);
break; sortIndex++;
} searchIndex = findIndexFor(template1);
} }
index = -1;
for(int i = 1; i<size(); i++){ if(!closed){
if(get(i).hasEqual(next2) ){ // Search backwards
CoordinatePair coordPair = get(i); sortIndex = -1;
coordPair.polygonOrder=index; for(int i = 1; i<size(); i++){
polygon.add(coordPair); if(get(i).hasEqual(template2) ){
remove(i); CoordinatePair coordPair = get(i);
next2 = coordPair.getOpposite(next2); coordPair.polygonOrder=sortIndex;
index--; polygon.add(coordPair);
break; remove(i);
template2 = coordPair.getOpposite(template2);
sortIndex--;
break;
}
} }
} }
polygons.add(polygon); polygons.add(polygon);
...@@ -78,7 +81,16 @@ public class Polygon extends ArrayList<CoordinatePair>{ ...@@ -78,7 +81,16 @@ public class Polygon extends ArrayList<CoordinatePair>{
return polygons; return polygons;
} }
private Coordinate defineNext(Coordinate template){
private int findIndexFor(Coordinate template){
for(int i = 1; i<size(); i++)
if(get(i).hasEqual(template))
return i;
return -1;
}
private Coordinate defineTemplateForNextCoordinatePair(Coordinate template){
String direction = Directions.oppsiteDirection(template.direction); String direction = Directions.oppsiteDirection(template.direction);
double value = template.value; double value = template.value;
int r = getNewRow(direction, template.r); int r = getNewRow(direction, template.r);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment