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

Initial commit

parent 9b139b96
......@@ -32,8 +32,10 @@ public class Coordinate{
}
public void fitToFrame(int offsetX, int offsetY, double scaleX, double scaleY){
this.x = (int)Math.round(lat * scaleX + offsetX);
this.y = (int)Math.round(lon * scaleY + offsetY);
// this.x = (int)Math.round(lat * scaleX + offsetX);
// 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{
@Override
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){
......
......@@ -188,7 +188,26 @@ public class Coordinates extends ArrayList<Coordinate>{
private int getIndexFromCoord(int row, int col){
int index;
index = row * getCols() + col;
index = row * getCols()-1 + col;
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;
public class GUI extends JFrame{
private final Polygons polygons = new Polygons();
private final Coordinates coords;
int offsetX = 1000;
int offsetY = 3000;//-2000;
double scaleX = -25;
double scaleY = -40;
int offsetX = 100;
int offsetY = 100;//3000;//-2000;
double scaleX = 1;
double scaleY = 1;
public GUI(Coordinates coords){
this.coords = coords;
......@@ -50,34 +50,58 @@ public class GUI extends JFrame{
coords.fitToFrame(offsetX, offsetY, scaleX, scaleY);
g.setColor(Color.LIGHT_GRAY);
int s = 15;
for(int r = 0; r<coords.getRows()-s; r=r+s)
for(int c = 0; c<coords.getCols()-s; c=c+s){
int x11 = coords.getCoordinate(r, c).x;
int x12 = coords.getCoordinate(r, c+s).x;
int x21 = coords.getCoordinate(r+s, c).x;
int y11 = coords.getCoordinate(r, c).y;
int y12 = coords.getCoordinate(r, c+s).y;
int y21 = coords.getCoordinate(r+s, c).y;
int x11;
int x21;
int x12;
int y11;
int y21;
int y12;
int x1;
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, x21, y21);
}
int cc=coords.getCols()-1; // last row
for(int r = 0; r<coords.getRows()-s; r=r+s){
int x1 = coords.getCoordinate(r, cc).x;
int x2 = coords.getCoordinate(r+s, cc).x;
int y1 = coords.getCoordinate(r, cc).y;
int y2 = coords.getCoordinate(r+s, cc).y;
x1 = coords.getCoordinate(r, cMax).x;
x2 = coords.getCoordinate(r+s, cMax).x;
y1 = coords.getCoordinate(r, cMax).y;
y2 = coords.getCoordinate(r+s, cMax).y;
g.drawLine(x1, y1, x2, y2);
}
int rr=coords.getRows()-1; // last col
for(int c = 0; c<coords.getCols()-s; c=c+s){
int x1 = coords.getCoordinate(rr, c).x;
int x2 = coords.getCoordinate(rr, c+s).x;
int y1 = coords.getCoordinate(rr, c).y;
int y2 = coords.getCoordinate(rr, c+s).y;
x1 = coords.getCoordinate(rMax, c).x;
x2 = coords.getCoordinate(rMax, c+s).x;
y1 = coords.getCoordinate(rMax, c).y;
y2 = coords.getCoordinate(rMax, c+s).y;
g.drawLine(x1, y1, x2, y2);
}
......
......@@ -61,6 +61,7 @@ public class JSONMatrix{
}
prevLat=lat;
}
System.out.println(coords.toString());
Iterator<Long> keys = statistics.keySet().iterator();
Long key;
while(keys.hasNext()){
......
......@@ -5,7 +5,6 @@
*/
package isospline;
import java.awt.Color;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
......
......@@ -39,38 +39,41 @@ public class Polygon extends ArrayList<CoordinatePair>{
public Polygons getSeparatePolygons(String name, Color color){
Polygons polygons = new Polygons();
int index;
int sortIndex;
while(size()>0){
CoordinatePair start = get(0);
Coordinate next1 = defineNext(start.coord1);
Coordinate next2 = defineNext(start.coord2);
Coordinate template1 = defineTemplateForNextCoordinatePair(start.coord1);
Coordinate template2 = defineTemplateForNextCoordinatePair(start.coord2);
Polygon polygon = new Polygon(start.coord1.value, name, color);
index = 0;
sortIndex = 0;
remove(0);
for(int i = 1; i<size(); i++){
if(get(i).hasEqual(next1)){
CoordinatePair coordPair = get(i);
coordPair.polygonOrder=index;
polygon.add(coordPair);
remove(i);
next1 = coordPair.getOpposite(next1);
index++;
break;
}
boolean closed = false;
int searchIndex = findIndexFor(template1);
while(searchIndex>0){
CoordinatePair coordPair = get(searchIndex);
coordPair.polygonOrder=sortIndex;
polygon.add(coordPair);
remove(searchIndex);
template1 = coordPair.getOpposite(template1);
sortIndex++;
searchIndex = findIndexFor(template1);
}
index = -1;
for(int i = 1; i<size(); i++){
if(get(i).hasEqual(next2) ){
CoordinatePair coordPair = get(i);
coordPair.polygonOrder=index;
polygon.add(coordPair);
remove(i);
next2 = coordPair.getOpposite(next2);
index--;
break;
if(!closed){
// Search backwards
sortIndex = -1;
for(int i = 1; i<size(); i++){
if(get(i).hasEqual(template2) ){
CoordinatePair coordPair = get(i);
coordPair.polygonOrder=sortIndex;
polygon.add(coordPair);
remove(i);
template2 = coordPair.getOpposite(template2);
sortIndex--;
break;
}
}
}
polygons.add(polygon);
......@@ -78,7 +81,16 @@ public class Polygon extends ArrayList<CoordinatePair>{
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);
double value = template.value;
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