diff gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java @ 805:bb7afd783321

Removed trailing whitespace. Added more javadoc. gnv-artifacts/trunk@887 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 08 Apr 2010 11:31:44 +0000
parents 6cff63d0c434
children a645bd23c1c8
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java	Thu Apr 08 10:10:04 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/L1Comparator.java	Thu Apr 08 11:31:44 2010 +0000
@@ -5,6 +5,11 @@
 import java.util.Comparator;
 
 /**
+ * Compares two coordinates a and b by their L1(Matnhattan) distance
+ * relative to a reference point r.
+ * da = L1(a, r)<br>
+ * db = L1(b, r)<br>
+ * -1 if da &lt; db, +1 if da &gt; db, 0 else.
  * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
  */
 public  class L1Comparator
@@ -12,17 +17,35 @@
 {
     private Coordinate ref;
 
+    /**
+     * Default constructor.
+     */
     public L1Comparator() {
     }
 
+    /**
+     * Constructor to create a L1Comparator with a given reference point.
+     * @param ref The reference point.
+     */
     public L1Comparator(Coordinate ref) {
         this.ref = ref;
     }
 
+    /**
+     * Explicitly sets the reference point.
+     * @param ref The reference point.
+     */
     public void setReference(Coordinate ref) {
         this.ref = ref;
     }
 
+    /**
+     * Compares to coordinate by their L1 distance to the reference point.
+     * @param a The first coordinate.
+     * @param b The second coordinate.
+     * @return -1 if L1(a, ref) &lt; L1(b, ref),
+     * +1 if L1(a, ref) &gt; L1(b, ref), 0 else.
+     */
     public int compare(Object a, Object b) {
         Coordinate pa = (Coordinate)a;
         Coordinate pb = (Coordinate)b;
@@ -33,9 +56,15 @@
         return 0;
     }
 
+    /**
+     * Computes the L1 distance between two points a and b:<br>
+     * L1(a, b) = abs(a.x - b.x) + abs(a.y - b.y)
+     * @param a The first point.
+     * @param b The second point.
+     * @return The L1 distance.
+     */
     public static double L1(Coordinate a, Coordinate b) {
         return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
     }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org