altosuilib: Show launch sites at all visible locations on map
[fw/altos] / altoslib / AltosMapTransform.java
index ba9d1ae46121ca5ce72895562dd13ec736e88a38..3f8f290c9f87faa419358de317a3210ea879d583 100644 (file)
@@ -29,6 +29,8 @@ public class AltosMapTransform {
 
        double  offset_x, offset_y;
 
+       int     width, height;
+
        public AltosLatLon lat_lon (AltosPointDouble point) {
                double lat, lon;
                double rads;
@@ -110,6 +112,39 @@ public class AltosMapTransform {
                return screen(point(lat, lon));
        }
 
+       /* Return first longitude value which ends up on-screen */
+       public double first_lon(double lon) {
+               /* Find a longitude left of the screen */
+               for (;;) {
+                       double x = lon * scale_x - offset_x;
+                       if (x < 0)
+                               break;
+                       lon -= 360.0;
+               }
+               /* Find the first longitude on the screen */
+               for (;;) {
+                       double x = lon * scale_x - offset_x;
+                       if (x >= 0)
+                               break;
+                       lon += 360.0;
+               }
+               return lon;
+       }
+
+       /* Return last longitude value which ends up on-screen */
+       public double last_lon(double lon) {
+               lon = first_lon(lon);
+
+               for(;;) {
+                       double next_lon = lon + 360.0;
+                       double next_x = next_lon * scale_x - offset_x;
+                       if (next_x >= width)
+                               break;
+                       lon = next_lon;
+               }
+               return lon;
+       }
+
        private boolean has_location;
 
        public boolean has_location() {
@@ -120,6 +155,9 @@ public class AltosMapTransform {
                scale_x = 256/360.0 * Math.pow(2, zoom);
                scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom);
 
+               this.width = width;
+               this.height = height;
+
                AltosPointDouble centre_pt = point(centre_lat_lon);
 
                has_location = (centre_lat_lon.lat != 0 || centre_lat_lon.lon != 0);