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 |
|
---|
19 | package org.expeditee.io.flowlayout;
|
---|
20 |
|
---|
21 | import java.util.List;
|
---|
22 |
|
---|
23 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
24 | import org.expeditee.core.bounds.PolygonBounds;
|
---|
25 | import org.expeditee.items.Item;
|
---|
26 |
|
---|
27 | public 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 | }
|
---|