Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 1142:12abbf15f18a
dummy merge for repo head
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:15:20 +0200 |
parents | f953c9a559d8 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.math; import com.vividsolutions.jts.geom.Coordinate; /** * Implements {@link de.intevation.gnv.math.Metrics} * for linear interpolations and distance measurements. * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ public final class LinearMetrics implements Metrics { /** * Instance to prevent needless creations of instances. */ public static final Metrics INSTANCE = new LinearMetrics(); /** * Implements the corresponding linear interpolator. */ public static final class LinearInterpolator implements Interpolator { private double mx; private double bx; private double my; private double by; /** * Constructor to create a linear interpolator between two * given points. * @param p1 The first point. * @param p2 The second point. */ public LinearInterpolator(Coordinate p1, Coordinate 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.x; mx = p2.x - bx; by = p1.y; my = p2.y - by; } public void interpolate(double t, Coordinate v) { v.x = t*mx + bx; v.y = t*my + by; } } // class LinearInterpolator private LinearMetrics() { } public double distance(Coordinate p1, Coordinate p2) { return p1.distance(p2); } public Interpolator getInterpolator(Coordinate p1, Coordinate p2) { return new LinearInterpolator(p1, p2); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :