| 1 |
|
|---|
| 2 |
void doCoreTest() { |
|---|
| 3 |
|
|---|
| 4 |
println(); |
|---|
| 5 |
println("core test"); |
|---|
| 6 |
println(); |
|---|
| 7 |
|
|---|
| 8 |
Coordinate c = new Coordinate(0, 1, 2); |
|---|
| 9 |
println( c.toString().equals("(0.000, 1.000 @2.000)") ); |
|---|
| 10 |
println( c.row == 0 ); |
|---|
| 11 |
println( c.column == 1 ); |
|---|
| 12 |
println( c.zoom == 2 ); |
|---|
| 13 |
|
|---|
| 14 |
println( c.zoomTo(3).toString().equals("(0.000, 2.000 @3.000)") ); |
|---|
| 15 |
|
|---|
| 16 |
println( c.zoomTo(1).toString().equals("(0.000, 0.500 @1.000)") ); |
|---|
| 17 |
|
|---|
| 18 |
println( c.up().toString().equals("(-1.000, 1.000 @2.000)") ); |
|---|
| 19 |
|
|---|
| 20 |
println( c.right().toString().equals("(0.000, 2.000 @2.000)") ); |
|---|
| 21 |
|
|---|
| 22 |
println( c.down().toString().equals("(1.000, 1.000 @2.000)") ); |
|---|
| 23 |
|
|---|
| 24 |
println( c.left().toString().equals("(0.000, 0.000 @2.000)") ); |
|---|
| 25 |
|
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
class Point { |
|---|
| 30 |
|
|---|
| 31 |
float x; |
|---|
| 32 |
float y; |
|---|
| 33 |
|
|---|
| 34 |
Point(float x, float y) { |
|---|
| 35 |
this.x = x; |
|---|
| 36 |
this.y = y; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
String toString() { |
|---|
| 40 |
return "(" + nf(x,1,3) + ", " + nf(y,1,3) + ")"; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
class Coordinate { |
|---|
| 46 |
|
|---|
| 47 |
int MAX_ZOOM = 20; |
|---|
| 48 |
|
|---|
| 49 |
float row, column, zoom; |
|---|
| 50 |
|
|---|
| 51 |
Coordinate(float row, float column, float zoom) { |
|---|
| 52 |
this.row = row; |
|---|
| 53 |
this.column = column; |
|---|
| 54 |
this.zoom = zoom; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
String toString() { |
|---|
| 58 |
return "(" + nf(row,1,3) + ", " + nf(column,1,3) + " @" + nf(zoom,1,3) + ")"; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
Coordinate copy() { |
|---|
| 62 |
return new Coordinate(row, column, zoom); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
Coordinate container() { |
|---|
| 66 |
return new Coordinate(floor(row), floor(column), zoom); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
Coordinate zoomTo(float destination) { |
|---|
| 70 |
return new Coordinate(row * pow(2, destination - zoom), |
|---|
| 71 |
column * pow(2, destination - zoom), |
|---|
| 72 |
destination); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
Coordinate zoomBy(float distance) { |
|---|
| 76 |
return new Coordinate(row * pow(2, distance), |
|---|
| 77 |
column * pow(2, distance), |
|---|
| 78 |
zoom + distance); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
Coordinate up() { |
|---|
| 82 |
return up(1); |
|---|
| 83 |
} |
|---|
| 84 |
Coordinate up(float distance) { |
|---|
| 85 |
return new Coordinate(row - distance, column, zoom); |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
Coordinate right() { |
|---|
| 89 |
return right(1); |
|---|
| 90 |
} |
|---|
| 91 |
Coordinate right(float distance) { |
|---|
| 92 |
return new Coordinate(row, column + distance, zoom); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
Coordinate down() { |
|---|
| 96 |
return down(1); |
|---|
| 97 |
} |
|---|
| 98 |
Coordinate down(float distance) { |
|---|
| 99 |
return new Coordinate(row + distance, column, zoom); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
Coordinate left() { |
|---|
| 103 |
return left(1); |
|---|
| 104 |
} |
|---|
| 105 |
Coordinate left(float distance) { |
|---|
| 106 |
return new Coordinate(row, column - distance, zoom); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
} |
|---|