comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 657:af3f56758f59

merged gnv-artifacts/0.5
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:53 +0200
parents aec85d00d82c
children 6cff63d0c434
comparison
equal deleted inserted replaced
590:5f5f273c8566 657:af3f56758f59
1 package de.intevation.gnv.math;
2
3 import com.vividsolutions.jts.geom.Coordinate;
4
5 /**
6 * @author Sascha L. Teichmann
7 */
8 public final class LinearMetrics
9 implements Metrics
10 {
11 public static final Metrics INSTANCE =
12 new LinearMetrics();
13
14 public static final class LinearInterpolator
15 implements Interpolator
16 {
17 private double mx;
18 private double bx;
19 private double my;
20 private double by;
21
22 public LinearInterpolator(Coordinate p1, Coordinate p2) {
23
24 /*
25 I) p1.x = 0*m + bx
26 II) p2.x = 1*m + bx
27
28 bx = p1.x
29
30 p2.x = m + p1.x
31
32 mx = p2.x - p1.x
33 */
34
35 bx = p1.x;
36 mx = p2.x - bx;
37
38 by = p1.y;
39 my = p2.y - by;
40 }
41
42 public void interpolate(double t, Coordinate v) {
43 v.x = t*mx + bx;
44 v.y = t*my + by;
45 }
46 } // class LinearInterpolator
47
48 private LinearMetrics() {
49 }
50
51 public double distance(Coordinate p1, Coordinate p2) {
52 return p1.distance(p2);
53 }
54
55 public Interpolator getInterpolator(Coordinate p1, Coordinate p2) {
56 return new LinearInterpolator(p1, p2);
57 }
58 }
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org