sascha@360: package de.intevation.gnv.math;
sascha@360: 
sascha@361: import com.vividsolutions.jts.geom.Coordinate;
sascha@360: 
sascha@360: /**
sascha@360:  *  @author Sascha L. Teichmann
sascha@360:  */
sascha@360: public final class LinearMetrics
sascha@360: implements         Metrics
sascha@360: {
sascha@360:     public static final Metrics INSTANCE =
sascha@360:         new LinearMetrics();
sascha@360: 
sascha@360:     public static final class LinearInterpolator
sascha@360:     implements                Interpolator
sascha@360:     {
sascha@360:         private double mx;
sascha@360:         private double bx;
sascha@360:         private double my;
sascha@360:         private double by;
sascha@360: 
sascha@361:         public LinearInterpolator(Coordinate p1, Coordinate p2) {
sascha@360: 
sascha@360:             /*
sascha@360:              I) p1.x = 0*m + bx
sascha@360:             II) p2.x = 1*m + bx
sascha@360: 
sascha@360:             bx = p1.x
sascha@360: 
sascha@360:             p2.x = m + p1.x
sascha@360: 
sascha@360:             mx = p2.x - p1.x
sascha@360:             */
sascha@360: 
sascha@361:             bx = p1.x;
sascha@361:             mx = p2.x - bx;
sascha@360: 
sascha@361:             by = p1.y;
sascha@361:             my = p2.y - by;
sascha@360:         }
sascha@360: 
sascha@361:         public void interpolate(double t, Coordinate v) {
sascha@361:             v.x = t*mx + bx;
sascha@361:             v.y = t*my + by;
sascha@360:         }
sascha@360:     } // class LinearInterpolator
sascha@360: 
sascha@360:     private LinearMetrics() {
sascha@360:     }
sascha@360: 
sascha@361:     public double distance(Coordinate p1, Coordinate p2) {
sascha@360:         return p1.distance(p2);
sascha@360:     }
sascha@360: 
sascha@361:     public Interpolator getInterpolator(Coordinate p1, Coordinate p2) {
sascha@360:         return new LinearInterpolator(p1, p2);
sascha@360:     }
sascha@360: }
sascha@360: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: