1 /*
2 * Trip Tracker, a real-time position tracking system for the Internet.
3 * Copyright (C) 2006 Team Trip Tracker
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 package triptracker.testing;
21
22 import java.awt.Color;
23 import java.awt.Graphics;
24 import java.awt.Point;
25
26 import javax.swing.JApplet;
27
28 /***
29 * Test class for plotting coordinates.
30 */
31 public class CoordinateTest extends JApplet {
32 int OVAL_SIZE = 2;
33 int xMaxCoord,yMaxCoord,xMinCoord, yMinCoord;
34 Point point = new Point();
35 Point prevPoint = new Point();
36
37 public CoordinateTest() {
38 System.out.println("A test for plotting coordinates");
39
40 // Coordinate coord1 = new Coordinate(5858.3766,536.6659);
41 // Coordinate coord2 = new Coordinate(5858.3766,536.6659);
42
43
44 //double t1 = coord1.sexToDec(5858.3767);
45 //double t2 = coord1.decToSex(t1);
46
47 //System.out.println("dec: "+ coord1.sexToDec(5858.3767));
48 //System.out.println("sex: " + t2);
49
50 // System.out.println("--\ndist (haversine): "
51 // + Coordinate.haversineDist(coord1, coord2)*100000);
52 // System.out.println("--\ndist (cosine): "
53 // + Coordinate.cosineDist(coord1, coord2));
54
55 // System.out.println("distance :" + coord1.cosineLawDist(coord1, coord2));
56 }
57
58 /***
59 * TEMP, just for testing, draws some random
60 * points and draws a line between them.
61 */
62 @Override
63 public void paint(Graphics g) {
64
65 // Generates 10 random points
66 for (int i = 0; i < 20; i++) {
67
68 if (i > 0) {
69 prevPoint.setLocation(point.getLocation());
70 }
71
72 // Generates a random x and y
73 point.setLocation(((int) (i * (Math.random()) * 20)),
74 ((10 * ((i / 10) + Math.random() * 10))));
75
76 // Do this if you have a previous point to work with
77 if (i > 0) {
78
79 // TODO just for testing purposes
80 //System.out.println(point.toString());
81 //System.out.println(prevPoint.toString());
82
83 g.setColor(Color.RED);
84
85 // Draws a line from the previous point to the active point
86 if (point.equals(prevPoint)) {
87 System.out.println("prevPoint and current point is"
88 + "identical, no need for drawing that one");
89 } else {
90 g.drawLine(point.x, point.y, prevPoint.x, prevPoint.y);
91 }
92 }
93
94 // Determening min/max values for x & y,
95 // used for scaling.
96 if (xMaxCoord < point.getX()) {
97 xMaxCoord = (int) point.getX();
98 }
99 if (xMinCoord > point.getX()) {
100 xMinCoord = (int) point.getX();
101 }
102 if (yMaxCoord < point.getY()) {
103 yMaxCoord = (int) point.getY();
104 }
105 if (yMinCoord > point.getY()) {
106 yMinCoord = (int) point.getY();
107 }
108
109 g.setColor(Color.BLUE);
110 // Draws the coordinate as a oval with a given size
111 // if the point isnt already drawn
112 if (point.equals(prevPoint)) {
113 System.out.println("prevPoint and current point is identical");
114 } else {
115 g.fillOval(point.x, point.y, OVAL_SIZE, OVAL_SIZE);
116 }
117 }
118 }
119 }