Subversion Repositories display

Rev

Blame | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2014 Steve Ratcliffe
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 or
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package test.svg;

import uk.me.parabola.imgfmt.Utils;

/**
* @author Steve Ratcliffe
*/

class XY {
        private static final int SHRINK = 1;

        // These are used so that the numbers are not too big. We just save the first values we
        // see and subtract them from each x and y coord.
        private static int latOrigin;
        private static int lonOrigin;

        private final int lat;
        private final int lon;

        XY(int lat, int lon) {
                this.lat = lat;
                this.lon = lon;

                if (latOrigin == 0 && lonOrigin == 0) {
                        latOrigin = lat;
                        lonOrigin = lon;
                }
        }

        public final int getYi() {
                return (latOrigin - lat) / SHRINK;
        }

        public String getY() {
                return String.valueOf(getYi());
        }

        public final int getXi() {
                return (lon - lonOrigin) / SHRINK;
        }

        public String getX() {
                return String.valueOf(getXi());
        }

        public double getLatitude() {
                return Utils.toDegrees(lat);
        }

        public double getLongitude() {
                return Utils.toDegrees(lon);
        }

        public String toString() {
                return String.format("(%.4f,%.4f)", getLatitude(), getLongitude());
        }
}