Shape.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 }