diff gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java @ 807:a645bd23c1c8

Added more javadoc. Removed trailing whitespace. gnv-artifacts/trunk@889 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 08 Apr 2010 15:24:45 +0000
parents d766fe2d917a
children 22c18083225e
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java	Thu Apr 08 13:10:39 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java	Thu Apr 08 15:24:45 2010 +0000
@@ -21,28 +21,51 @@
 import org.apache.log4j.Logger;
 
 /**
- *  @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
+ * Spans a rectangle of points to be used in spatial indexing.
+ *
+ * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
  */
 public class GridCell
 implements   Serializable
 {
     private static Logger log = Logger.getLogger(GridCell.class);
 
+    /**
+     * Callback for {@link com.vividsolutions.jts.index.SpatialIndex}
+     * to find a GridCell which contains a given point.
+     */
     public static final class CellFinder
     implements                ItemVisitor
     {
+        /**
+         * Stores the found GridCell.
+         */
         public    GridCell found;
 
+        /**
+         * The query point.
+         */
         protected Point    point;
 
+        /**
+         * Default constructor.
+         */
         public CellFinder() {
         }
 
+        /**
+         * Prepares a spatial index lookup.
+         * @param center The query point.
+         */
         public void prepare(Coordinate center) {
             found = null;
             point = GEOMETRY_FACTORY.createPoint(center);
         }
 
+        /**
+         * Called by the spatial index as a 2nd order filter.
+         * @param item The GridCell to test.
+         */
         public void visitItem(Object item) {
             if (found == null) {
                 GridCell cell = (GridCell)item;
@@ -53,19 +76,47 @@
         }
     } // class CellFinder
 
+    /**
+     * The first point.
+     */
     public Point2d p1;
+    /**
+     * The second point.
+     */
     public Point2d p2;
+    /**
+     * The third point.
+     */
     public Point2d p3;
+    /**
+     * The fourth point.
+     */
     public Point2d p4;
 
+    /**
+     * Polygon created from the four points.
+     */
     protected Polygon polygon;
 
+    /**
+     * Geometry factory to create the query points and the polygons.
+     */
     public static final GeometryFactory GEOMETRY_FACTORY
         = new GeometryFactory();
 
+    /**
+     * Default constructor.
+     */
     public GridCell() {
     }
 
+    /**
+     * Constructor to create a GridCell out of four given points..
+     * @param p1 The first point.
+     * @param p2 The second point.
+     * @param p3 The thrid point.
+     * @param p4 The fourth point.
+     */
     public GridCell(Point2d p1, Point2d p2, Point2d p3, Point2d p4) {
         this.p1 = p1;
         this.p2 = p2;
@@ -74,6 +125,9 @@
         createPolygon();
     }
 
+    /**
+     * Creates the polygon from the four points.
+     */
     protected void createPolygon() {
         Coordinate [] coords = new Coordinate [] { p1, p2, p3, p4, p1 };
         if (!CGAlgorithms.isCCW(coords)) {
@@ -93,20 +147,41 @@
         polygon = GEOMETRY_FACTORY.createPolygon(shell, null);
     }
 
+    /**
+     * Returns the envelope of the four point polygon.
+     * @return
+     */
     public Envelope getEnvelope() {
         return polygon.getEnvelopeInternal();
     }
 
+    /**
+     * Test if a given point is inside this grid cell.
+     * @param coord
+     * @return
+     */
     public boolean contains(Geometry coord) {
         return polygon.contains(coord);
     }
 
+    /**
+     * Converts a list of points to a list of grid cells.
+     * @param points This list of points.
+     * @return This list of grid cells.
+     */
     public static List<GridCell> pointsToGridCells(
         List<? extends Point2d> points
     ) {
         return pointsToGridCells(points, null);
     }
 
+    /**
+     * Converts a list of points to a list of grid cells.
+     * Points that are not in a relevant area are ignored.
+     * @param points The list of points.
+     * @param relevantArea The relevant area.
+     * @return The list of grid cells.
+     */
     public static List<GridCell> pointsToGridCells(
         List<? extends Point2d> points,
         Envelope                relevantArea
@@ -125,6 +200,17 @@
         {  0, -1 }  // 7
     };
 
+    /**
+     * Generate points by extrapolating border points.
+     * @param rows (i, j) indexed map of points.
+     * @param minI min known i.
+     * @param maxI max known i.
+     * @param minJ min known j.
+     * @param maxJ max known j.
+     * @param rounds Deternine how many extra rings should be generated.
+     * @param relevantArea The relevant area.
+     * @return number of newly generated points.
+     */
     public static int extrapolate(
         HashMap<Integer, HashMap<Integer, Point2d>> rows,
         int minI, int maxI,
@@ -212,6 +298,15 @@
         return total;
     }
 
+    /**
+     * Converts a list of points to a list of grid cells.
+     * @param points The list of points.
+     * @param relevantArea The relevant area. If a point is
+     * not inside this area it is ignored during the build process.
+     * @param extrapolationRounds Number of extra point rings.
+     * 0 = no extrpolation.
+     * @return The list of grid cells.
+     */
     public static List<GridCell> pointsToGridCells(
         List<? extends Point2d> points,
         Envelope                relevantArea,

http://dive4elements.wald.intevation.org