- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/flowlayout/DimensionExtent.java
r919 r1102 19 19 package org.expeditee.io.flowlayout; 20 20 21 import java.awt.Polygon;22 import java.awt.Rectangle;23 import java.awt.geom.Area;24 21 import java.util.List; 25 22 23 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 24 import org.expeditee.core.bounds.PolygonBounds; 26 25 import org.expeditee.items.Item; 27 26 … … 44 43 45 44 for (Item item : items) { 46 Area area = item.getArea(); 47 Rectangle rect = area.getBounds(); 48 int xl = rect.x; 49 int xr = xl + rect.width-1; 45 AxisAlignedBoxBounds bounds = item.getBoundingBox(); 46 int xl = bounds.getMinX(); 47 int xr = xl + bounds.getWidth()-1; 50 48 51 49 min_x = Math.min(min_x, xl); … … 66 64 67 65 for (Item item : items) { 68 Area area = item.getArea(); 69 Rectangle rect = area.getBounds(); 70 int yt = rect.y; 71 int yb = yt + rect.height-1; 66 AxisAlignedBoxBounds bounds = item.getBoundingBox(); 67 int yt = bounds.getMinY(); 68 int yb = yt + bounds.getHeight()-1; 72 69 73 70 min_y = Math.min(min_y, yt); … … 82 79 83 80 84 public static DimensionExtent calcMinMaxXExtent(Polygon polygon)81 public static DimensionExtent calcMinMaxXExtent(PolygonBounds polygon) 85 82 { 86 83 87 int min_x = Integer.MAX_VALUE; 88 int max_x = Integer.MIN_VALUE; 89 90 int npoints = polygon.npoints; 91 92 for (int i=0; i<npoints; i++) { 93 94 int x = polygon.xpoints[i]; 95 96 min_x = Math.min(min_x, x); 97 max_x = Math.max(max_x, x); 98 } 99 100 DimensionExtent extent = new DimensionExtent(min_x,max_x); 84 DimensionExtent extent = new DimensionExtent(polygon.getMinX(), polygon.getMaxX()); 101 85 102 86 return extent; 103 87 } 104 88 105 public static DimensionExtent calcMinMaxYExtent(Polygon polygon)89 public static DimensionExtent calcMinMaxYExtent(PolygonBounds polygon) 106 90 { 107 91 108 int min_y = Integer.MAX_VALUE; 109 int max_y = Integer.MIN_VALUE; 110 111 int npoints = polygon.npoints; 112 113 for (int i=0; i<npoints; i++) { 114 115 int y = polygon.ypoints[i]; 116 117 min_y = Math.min(min_y, y); 118 max_y = Math.max(max_y, y); 119 } 120 121 DimensionExtent extent = new DimensionExtent(min_y,max_y); 92 DimensionExtent extent = new DimensionExtent(polygon.getMinY(), polygon.getMaxY()); 122 93 123 94 return extent; 124 95 } 125 96 126 public static Polygon boundingBoxPolygon(List<Item> items)97 public static PolygonBounds boundingBoxPolygon(List<Item> items) 127 98 { 128 DimensionExtent xextent = DimensionExtent.calcMinMaxXExtent(items); 129 DimensionExtent yextent = DimensionExtent.calcMinMaxYExtent(items); 130 131 int xl=xextent.min; 132 int xr=xextent.max; 133 int yt=yextent.min; 134 int yb=yextent.max; 99 AxisAlignedBoxBounds box = null; 135 100 136 int[] xpoints = new int[]{xl,xr,xr,xl}; 137 int[] ypoints = new int[]{yt,yt,yb,yb}; 101 for (Item i : items) { 102 if (box == null) { 103 box = i.getBoundingBox(); 104 } else { 105 box.combineWith(i.getBoundingBox()); 106 } 107 } 138 108 139 140 Polygon polygon = new Polygon(xpoints,ypoints,4); 141 142 return polygon; 109 return new PolygonBounds(box.getBorderLines()); 143 110 } 144 111 }
Note:
See TracChangeset
for help on using the changeset viewer.