Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 1119:7c4f81f74c47
merged gnv-artifacts
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:00 +0200 |
parents | f953c9a559d8 |
children |
comparison
equal
deleted
inserted
replaced
1027:fca4b5eb8d2f | 1119:7c4f81f74c47 |
---|---|
1 /* | |
2 * Copyright (c) 2010 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 | |
9 package de.intevation.gnv.math; | |
10 | |
11 import com.vividsolutions.jts.geom.Coordinate; | |
12 | |
13 /** | |
14 * Implements {@link de.intevation.gnv.math.Metrics} | |
15 * for linear interpolations and distance measurements. | |
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
17 */ | |
18 public final class LinearMetrics | |
19 implements Metrics | |
20 { | |
21 /** | |
22 * Instance to prevent needless creations of instances. | |
23 */ | |
24 public static final Metrics INSTANCE = | |
25 new LinearMetrics(); | |
26 | |
27 /** | |
28 * Implements the corresponding linear interpolator. | |
29 */ | |
30 public static final class LinearInterpolator | |
31 implements Interpolator | |
32 { | |
33 private double mx; | |
34 private double bx; | |
35 private double my; | |
36 private double by; | |
37 | |
38 /** | |
39 * Constructor to create a linear interpolator between two | |
40 * given points. | |
41 * @param p1 The first point. | |
42 * @param p2 The second point. | |
43 */ | |
44 public LinearInterpolator(Coordinate p1, Coordinate p2) { | |
45 | |
46 /* | |
47 I) p1.x = 0*m + bx | |
48 II) p2.x = 1*m + bx | |
49 | |
50 bx = p1.x | |
51 | |
52 p2.x = m + p1.x | |
53 | |
54 mx = p2.x - p1.x | |
55 */ | |
56 | |
57 bx = p1.x; | |
58 mx = p2.x - bx; | |
59 | |
60 by = p1.y; | |
61 my = p2.y - by; | |
62 } | |
63 | |
64 public void interpolate(double t, Coordinate v) { | |
65 v.x = t*mx + bx; | |
66 v.y = t*my + by; | |
67 } | |
68 } // class LinearInterpolator | |
69 | |
70 private LinearMetrics() { | |
71 } | |
72 | |
73 public double distance(Coordinate p1, Coordinate p2) { | |
74 return p1.distance(p2); | |
75 } | |
76 | |
77 public Interpolator getInterpolator(Coordinate p1, Coordinate p2) { | |
78 return new LinearInterpolator(p1, p2); | |
79 } | |
80 } | |
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |