view gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 360:ee760729f6b8

Added mapping from linear diagram space to 2D map coordinates. gnv-artifacts/trunk@434 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 15 Dec 2009 15:58:58 +0000
parents
children aec85d00d82c
line wrap: on
line source
package de.intevation.gnv.math;

import java.awt.geom.Point2D;

import de.intevation.gnv.math.LinearToMap.Metrics;
import de.intevation.gnv.math.LinearToMap.Interpolator;

/**
 *  @author Sascha L. Teichmann
 */
public final class LinearMetrics
implements         Metrics
{
    public static final Metrics INSTANCE =
        new LinearMetrics();

    public static final class LinearInterpolator
    implements                Interpolator
    {
        private double mx;
        private double bx;
        private double my;
        private double by;

        public LinearInterpolator(Point2D p1, Point2D p2) {

            /*
             I) p1.x = 0*m + bx
            II) p2.x = 1*m + bx

            bx = p1.x

            p2.x = m + p1.x

            mx = p2.x - p1.x
            */

            bx = p1.getX();
            mx = p2.getX() - bx;

            by = p1.getY();
            my = p2.getY() - by;
        }

        public void interpolate(double t, Point2D v) {
            double x = t*mx + bx;
            double y = t*my + by;
            v.setLocation(x, y);
        }
    } // class LinearInterpolator

    private LinearMetrics() {
    }

    public double distance(Point2D p1, Point2D p2) {
        return p1.distance(p2);
    }

    public Interpolator getInterpolator(Point2D p1, Point2D p2) {
        return new LinearInterpolator(p1, p2);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org