source: trunk/src/org/expeditee/io/flowlayout/DimensionExtent.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

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

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1/**
2 * DimensionExtent.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io.flowlayout;
20
21import java.util.List;
22
23import org.expeditee.core.bounds.AxisAlignedBoxBounds;
24import org.expeditee.core.bounds.PolygonBounds;
25import org.expeditee.items.Item;
26
27public class DimensionExtent
28{
29 public int min;
30 public int max;
31
32 public DimensionExtent(int min, int max)
33 {
34 this.min = min;
35 this.max = max;
36 }
37
38 public static DimensionExtent calcMinMaxXExtent(List<Item>items)
39 {
40
41 int min_x = Integer.MAX_VALUE;
42 int max_x = Integer.MIN_VALUE;
43
44 for (Item item : items) {
45 AxisAlignedBoxBounds bounds = item.getBoundingBox();
46 int xl = bounds.getMinX();
47 int xr = xl + bounds.getWidth()-1;
48
49 min_x = Math.min(min_x, xl);
50 max_x = Math.max(max_x, xr);
51
52 }
53
54 DimensionExtent extent = new DimensionExtent(min_x,max_x);
55
56 return extent;
57 }
58
59 public static DimensionExtent calcMinMaxYExtent(List<Item>items)
60 {
61
62 int min_y = Integer.MAX_VALUE;
63 int max_y = Integer.MIN_VALUE;
64
65 for (Item item : items) {
66 AxisAlignedBoxBounds bounds = item.getBoundingBox();
67 int yt = bounds.getMinY();
68 int yb = yt + bounds.getHeight()-1;
69
70 min_y = Math.min(min_y, yt);
71 max_y = Math.max(max_y, yb);
72
73 }
74
75 DimensionExtent extent = new DimensionExtent(min_y,max_y);
76
77 return extent;
78 }
79
80
81 public static DimensionExtent calcMinMaxXExtent(PolygonBounds polygon)
82 {
83
84 DimensionExtent extent = new DimensionExtent(polygon.getMinX(), polygon.getMaxX());
85
86 return extent;
87 }
88
89 public static DimensionExtent calcMinMaxYExtent(PolygonBounds polygon)
90 {
91
92 DimensionExtent extent = new DimensionExtent(polygon.getMinY(), polygon.getMaxY());
93
94 return extent;
95 }
96
97 public static PolygonBounds boundingBoxPolygon(List<Item> items)
98 {
99 AxisAlignedBoxBounds box = null;
100
101 for (Item i : items) {
102 if (box == null) {
103 box = i.getBoundingBox();
104 } else {
105 box.combineWith(i.getBoundingBox());
106 }
107 }
108
109 return new PolygonBounds(box.getBorderLines());
110 }
111}
Note: See TracBrowser for help on using the repository browser.