Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

Shape.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Marco Kuhlmann, 2005
00009  *     Guido Tack, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-10-26 11:31:58 +0200 (Thu, 26 Oct 2006) $ by $Author: tack $
00013  *     $Revision: 3796 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
00022  *
00023  */
00024 
00025 package org.gecode.gist;
00026 
00027 import java.util.*;
00028 
00029 
00030 public class Shape {
00031 
00032     private ArrayList shape;
00033         
00034     public Shape() {
00035         shape = new ArrayList();
00036     }
00037         
00038     public Shape(Extent extent) {
00039         shape = new ArrayList(1);
00040         shape.add(extent);
00041     }
00042         
00043     public Shape(Extent extent, Shape subShape) {
00044         shape = new ArrayList(subShape.depth() + 1);
00045         shape.add(extent);
00046         Iterator extentIterator = subShape.iterator();
00047         while (extentIterator.hasNext()) {
00048             Extent currentExtent = (Extent) extentIterator.next();
00049             shape.add(currentExtent);
00050         }
00051     }
00052     
00053     public int depth() {
00054         return shape.size();
00055     }
00056     
00057     public void add(Extent Extent) {
00058         shape.add(Extent);
00059     }
00060     
00061     public Extent get(int i) {
00062         return ((Extent) shape.get(i));
00063     }
00064     
00065     public Iterator iterator() {
00066         return shape.iterator();
00067     }
00068     
00069     public void extend(int deltaL, int deltaR) {
00070         if (shape.size() > 0) {
00071             ((Extent) shape.get(0)).extend(deltaL, deltaR);
00072         }
00073     }
00074     
00075     public void move(int delta) {
00076         if (shape.size() > 0) {
00077             ((Extent) shape.get(0)).move(delta);
00078         }
00079     }
00080     
00081     public Extent getExtentAtDepth(int depth) {
00082         Iterator extentIterator = shape.iterator();
00083         int currentDepth = 0;
00084         int extentL = 0;
00085         int extentR = 0;
00086         while (extentIterator.hasNext() && currentDepth <= depth) {
00087             Extent currentExtent = (Extent) extentIterator.next();
00088             extentL += currentExtent.extentL;
00089             extentR += currentExtent.extentR;
00090             currentDepth++;
00091         }
00092         if (currentDepth == depth + 1) {
00093             return new Extent(extentL, extentR);
00094         } else {
00095             return null;
00096         }
00097     }
00098     
00099     public BoundingBox getBoundingBox() {
00100         Iterator extents = iterator();
00101         int lastLeft = 0;
00102         int lastRight = 0;
00103         int left = 0;
00104         int right = 0;
00105         int depth = 0;
00106         while (extents.hasNext()) {
00107             Extent curExtent = (Extent) extents.next();
00108             depth++;
00109             lastLeft = lastLeft + curExtent.extentL;
00110             lastRight = lastRight + curExtent.extentR;
00111             if (lastLeft < left)
00112                 left = lastLeft;
00113             if (lastRight > right)
00114                 right = lastRight;
00115         }
00116         return new BoundingBox(left, right, depth);
00117     }
00118 
00119     public String toString() {
00120         return shape.toString();
00121     }
00122     
00123 }