aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/packrect
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/packrect')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java62
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java40
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java17
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java48
6 files changed, 98 insertions, 97 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java
index 7b6a1b479..c1b5025f8 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/BackingStoreManager.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
index 5ba3f7330..9aadfba93 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Level.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -47,22 +47,22 @@ public class Level {
private int yPos;
private LevelSet holder;
- private List/*<Rect>*/ rects = new ArrayList/*<Rect>*/();
- private List/*<Rect>*/ freeList;
+ private List<Rect> rects = new ArrayList<Rect>();
+ private List<Rect> freeList;
private int nextAddX;
- static class RectXComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Rect r1 = (Rect) o1;
- Rect r2 = (Rect) o2;
+ static class RectXComparator implements Comparator<Rect> {
+ @Override
+ public int compare(Rect r1, Rect r2) {
return r1.x() - r2.x();
}
+ @Override
public boolean equals(Object obj) {
return this == obj;
}
}
- private static final Comparator rectXComparator = new RectXComparator();
+ private static final Comparator<Rect> rectXComparator = new RectXComparator();
public Level(int width, int height, int yPos, LevelSet holder) {
this.width = width;
@@ -108,8 +108,8 @@ public class Level {
// See whether we can add from the free list
if (freeList != null) {
Rect candidate = null;
- for (Iterator iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = (Rect) iter.next();
+ for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ Rect cur = iter.next();
if (cur.canContain(rect)) {
candidate = cur;
break;
@@ -128,7 +128,7 @@ public class Level {
candidate.setSize(candidate.w() - rect.w(), height);
freeList.add(candidate);
}
-
+
coalesceFreeList();
return true;
@@ -149,7 +149,7 @@ public class Level {
nextAddX -= rect.w();
} else {
if (freeList == null) {
- freeList = new ArrayList/*<Rect>*/();
+ freeList = new ArrayList<Rect>();
}
freeList.add(new Rect(rect.x(), rect.y(), rect.w(), height, null));
coalesceFreeList();
@@ -171,8 +171,8 @@ public class Level {
if (freeList == null)
return false;
int freeListWidth = 0;
- for (Iterator iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = (Rect) iter.next();
+ for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ Rect cur = iter.next();
freeListWidth += cur.w();
}
// Add on the remaining space at the end
@@ -184,8 +184,8 @@ public class Level {
Collections.sort(rects, rectXComparator);
int nextCompactionDest = 0;
manager.beginMovement(backingStore, backingStore);
- for (Iterator iter = rects.iterator(); iter.hasNext(); ) {
- Rect cur = (Rect) iter.next();
+ for (Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
+ Rect cur = iter.next();
if (cur.x() != nextCompactionDest) {
manager.move(backingStore, cur,
backingStore, new Rect(nextCompactionDest, cur.y(), cur.w(), cur.h(), null));
@@ -198,14 +198,14 @@ public class Level {
manager.endMovement(backingStore, backingStore);
}
- public Iterator iterator() {
+ public Iterator<Rect> iterator() {
return rects.iterator();
}
/** Visits all Rects contained in this Level. */
public void visit(RectVisitor visitor) {
- for (Iterator iter = rects.iterator(); iter.hasNext(); ) {
- Rect rect = (Rect) iter.next();
+ for (Iterator<Rect> iter = rects.iterator(); iter.hasNext(); ) {
+ Rect rect = iter.next();
visitor.visit(rect);
}
}
@@ -216,7 +216,7 @@ public class Level {
original Rects. */
public void updateRectangleReferences() {
for (int i = 0; i < rects.size(); i++) {
- Rect cur = (Rect) rects.get(i);
+ Rect cur = rects.get(i);
Rect next = cur.getNextLocation();
next.setPosition(cur.x(), cur.y());
if (cur.w() != next.w() || cur.h() != next.h())
@@ -235,8 +235,8 @@ public class Level {
Collections.sort(freeList, rectXComparator);
int i = 0;
while (i < freeList.size() - 1) {
- Rect r1 = (Rect) freeList.get(i);
- Rect r2 = (Rect) freeList.get(i+1);
+ Rect r1 = freeList.get(i);
+ Rect r2 = freeList.get(i+1);
if (r1.maxX() + 1 == r2.x()) {
// Coalesce r1 and r2 into one block
freeList.remove(i+1);
@@ -246,7 +246,7 @@ public class Level {
}
}
// See whether the last block bumps up against the addition point
- Rect last = (Rect) freeList.get(freeList.size() - 1);
+ Rect last = freeList.get(freeList.size() - 1);
if (last.maxX() + 1 == nextAddX) {
nextAddX -= last.w();
freeList.remove(freeList.size() - 1);
@@ -262,8 +262,8 @@ public class Level {
public void dumpFreeSpace() {
int freeListWidth = 0;
- for (Iterator iter = freeList.iterator(); iter.hasNext(); ) {
- Rect cur = (Rect) iter.next();
+ for (Iterator<Rect> iter = freeList.iterator(); iter.hasNext(); ) {
+ Rect cur = iter.next();
System.err.println(" Free rectangle at " + cur);
freeListWidth += cur.w();
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
index 6783aec3b..433421f1a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/LevelSet.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -47,7 +47,7 @@ import java.util.*;
public class LevelSet {
// Maintained in sorted order by increasing Y coordinate
- private List/*<Level>*/ levels = new ArrayList/*<Level>*/();
+ private List<Level> levels = new ArrayList<Level>();
private int nextAddY;
private int w;
private int h;
@@ -73,7 +73,7 @@ public class LevelSet {
// Go in reverse order through the levels seeing whether we can
// trivially satisfy the allocation request
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = (Level) levels.get(i);
+ Level level = levels.get(i);
if (level.add(rect))
return true;
}
@@ -82,7 +82,7 @@ public class LevelSet {
// increases the computational complexity of the addition process,
// but prevents us from expanding unnecessarily.
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = (Level) levels.get(i);
+ Level level = levels.get(i);
if (level.couldAllocateIfCompacted(rect))
return false;
}
@@ -104,11 +104,11 @@ public class LevelSet {
/** Removes the given Rect from this LevelSet. */
public boolean remove(Rect rect) {
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = (Level) levels.get(i);
+ Level level = levels.get(i);
if (level.remove(rect))
return true;
}
-
+
return false;
}
@@ -120,7 +120,7 @@ public class LevelSet {
Object backingStore,
BackingStoreManager manager) {
for (int i = levels.size() - 1; i >= 0; --i) {
- Level level = (Level) levels.get(i);
+ Level level = levels.get(i);
if (level.couldAllocateIfCompacted(rect)) {
level.compact(backingStore, manager);
boolean res = level.add(rect);
@@ -173,8 +173,8 @@ public class LevelSet {
int usedHeight = getUsedHeight();
if (usedHeight == 0)
return 0.0f;
- for (Iterator iter = iterator(); iter.hasNext(); ) {
- Level level = (Level) iter.next();
+ for (Iterator<Level> iter = iterator(); iter.hasNext(); ) {
+ Level level = iter.next();
if (level.isEmpty()) {
freeHeight += level.h();
}
@@ -182,14 +182,14 @@ public class LevelSet {
return (float) freeHeight / (float) usedHeight;
}
- public Iterator iterator() {
+ public Iterator<Level> iterator() {
return levels.iterator();
}
/** Visits all Rects contained in this LevelSet. */
public void visit(RectVisitor visitor) {
- for (Iterator iter = levels.iterator(); iter.hasNext(); ) {
- Level level = (Level) iter.next();
+ for (Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
+ Level level = iter.next();
level.visit(visitor);
}
}
@@ -199,8 +199,8 @@ public class LevelSet {
update the new Rects in a newly laid-out LevelSet with the
original Rects. */
public void updateRectangleReferences() {
- for (Iterator iter = levels.iterator(); iter.hasNext(); ) {
- Level level = (Level) iter.next();
+ for (Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
+ Level level = iter.next();
level.updateRectangleReferences();
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
index 6206c4a11..89f594230 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/Rect.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -72,7 +72,7 @@ public class Rect {
// there is no room left due either to fragmentation or just being
// out of space)
private Rect nextLocation;
-
+
public Rect() {
this(null);
}
@@ -144,6 +144,7 @@ public class Rect {
h() >= other.h());
}
+ @Override
public String toString() {
return "[Rect x: " + x() + " y: " + y() + " w: " + w() + " h: " + h() + "]";
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java
index 49cfc82e6..5db216742 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectVisitor.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
diff --git a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
index 1496a04a6..44faa44b0 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/packrect/RectanglePacker.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -60,18 +60,18 @@ public class RectanglePacker {
private int maxWidth = -1;
private int maxHeight = -1;
- static class RectHComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Rect r1 = (Rect) o1;
- Rect r2 = (Rect) o2;
+ static class RectHComparator implements Comparator<Rect> {
+ @Override
+ public int compare(Rect r1, Rect r2) {
return r2.h() - r1.h();
}
+ @Override
public boolean equals(Object obj) {
return this == obj;
}
}
- private static final Comparator rectHComparator = new RectHComparator();
+ private static final Comparator<Rect> rectHComparator = new RectHComparator();
public RectanglePacker(BackingStoreManager manager,
int initialWidth,
@@ -203,13 +203,13 @@ public class RectanglePacker {
}
nextLevelSet = new LevelSet(newWidth, newHeight);
-
+
// Make copies of all existing rectangles
- List/*<Rect>*/ newRects = new ArrayList/*<Rect>*/();
- for (Iterator i1 = levels.iterator(); i1.hasNext(); ) {
- Level level = (Level) i1.next();
- for (Iterator i2 = level.iterator(); i2.hasNext(); ) {
- Rect cur = (Rect) i2.next();
+ List<Rect> newRects = new ArrayList<Rect>();
+ for (Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
+ Level level = i1.next();
+ for (Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
+ Rect cur = i2.next();
Rect newRect = new Rect(0, 0, cur.w(), cur.h(), null);
cur.setNextLocation(newRect);
// Hook up the reverse mapping too for easier replacement
@@ -222,8 +222,8 @@ public class RectanglePacker {
Collections.sort(newRects, rectHComparator);
// Try putting all of these rectangles into the new level set
done = true;
- for (Iterator iter = newRects.iterator(); iter.hasNext(); ) {
- if (!nextLevelSet.add((Rect) iter.next())) {
+ for (Iterator<Rect> iter = newRects.iterator(); iter.hasNext(); ) {
+ if (!nextLevelSet.add(iter.next())) {
done = false;
break;
}
@@ -271,10 +271,10 @@ public class RectanglePacker {
Object newBackingStore = manager.allocateBackingStore(nextLevelSet.w(),
nextLevelSet.h());
manager.beginMovement(backingStore, newBackingStore);
- for (Iterator i1 = levels.iterator(); i1.hasNext(); ) {
- Level level = (Level) i1.next();
- for (Iterator i2 = level.iterator(); i2.hasNext(); ) {
- Rect cur = (Rect) i2.next();
+ for (Iterator<Level> i1 = levels.iterator(); i1.hasNext(); ) {
+ Level level = i1.next();
+ for (Iterator<Rect> i2 = level.iterator(); i2.hasNext(); ) {
+ Rect cur = i2.next();
manager.move(backingStore, cur,
newBackingStore, cur.getNextLocation());
}