Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/flowlayout/DimensionExtent.java

    r919 r1102  
    1919package org.expeditee.io.flowlayout;
    2020
    21 import java.awt.Polygon;
    22 import java.awt.Rectangle;
    23 import java.awt.geom.Area;
    2421import java.util.List;
    2522
     23import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     24import org.expeditee.core.bounds.PolygonBounds;
    2625import org.expeditee.items.Item;
    2726
     
    4443               
    4544                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;
    5048                       
    5149                        min_x = Math.min(min_x, xl);
     
    6664               
    6765                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;
    7269                       
    7370                        min_y = Math.min(min_y, yt);
     
    8279
    8380       
    84         public static DimensionExtent calcMinMaxXExtent(Polygon polygon)
     81        public static DimensionExtent calcMinMaxXExtent(PolygonBounds polygon)
    8582        {
    8683
    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());
    10185               
    10286                return extent;
    10387        }
    10488       
    105         public static DimensionExtent calcMinMaxYExtent(Polygon polygon)
     89        public static DimensionExtent calcMinMaxYExtent(PolygonBounds polygon)
    10690        {
    10791
    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());
    12293               
    12394                return extent;
    12495        }
    12596       
    126         public static Polygon boundingBoxPolygon(List<Item> items)
     97        public static PolygonBounds boundingBoxPolygon(List<Item> items)
    12798        {
    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;
    135100               
    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                }
    138108               
    139                
    140                 Polygon polygon = new Polygon(xpoints,ypoints,4);
    141                
    142                 return polygon;
     109                return new PolygonBounds(box.getBorderLines());
    143110        }
    144111}
Note: See TracChangeset for help on using the changeset viewer.