+++ /dev/null
-package edu.berkeley.qfat.geom;
-import javax.media.opengl.*;
-
-public class IntervalTree<V extends HasBoundingBox> {
-
-
- private static final int X_AXIS = 0;
- private static final int Y_AXIS = 1;
- private static final int Z_AXIS = 2;
-
- private class Node {
- int axis; /* 0, 1, 2 */
- V vthis;
- float maxmax, minmin;
- Node small, large;
- float bias = 0;
-
- public Node(V vthis, int axis) {
- this.vthis = vthis;
- this.axis = axis;
- maxmax = getMax(vthis);
- minmin = getMin(vthis);
- }
-
- private float getMin(V v) {
- switch(axis) {
- case X_AXIS: return v.getMinX();
- case Y_AXIS: return v.getMinY();
- case Z_AXIS: return v.getMinZ();
- }
- throw new Error();
- }
- private float getMax(V v) {
- switch(axis) {
- case X_AXIS: return v.getMaxX();
- case Y_AXIS: return v.getMaxY();
- case Z_AXIS: return v.getMaxZ();
- }
- throw new Error();
- }
- public Node insert(V vnew) {
- // FIXME bias
- if (getMax(vnew) > maxmax && getMin(vnew) < minmin) {
- float diff = Math.abs(maxmax - getMax(vnew)) - Math.abs(minmin - getMin(vnew));
- if (diff < 0) {
- maxmax = getMax(vnew);
- } else {
- minmin = getMin(vnew);
- }
- }
- if (getMax(vnew) <= maxmax) {
- right++;
- small = small == null ? new Node(vnew, (axis+1)%3) : small.insert(vnew);
- bias = (left - right) / (float)(left + right);
- if (Math.abs(bias) > Math.abs(maxbias)) maxbias = bias;
- return this;
-
- } else if (getMin(vnew) >= minmin) {
- left++;
- large = large == null ? new Node(vnew, (axis+1)%3) : large.insert(vnew);
- bias = (left - right) / (float)(left + right);
- if (Math.abs(bias) > Math.abs(maxbias)) maxbias = bias;
- return this;
- }
-
- throw new Error();
- }
- int left=0, right=0;
-
- }
-
- private Node root;
-
- public void insert(V v) {
- if (root==null) {
- root = new Node(v, X_AXIS);
- } else {
- root.insert(v);
- }
- System.out.println(maxbias + " " + size);
- size++;
- }
- int size = 0;
- float maxbias = 0;
-
- public V nearest(Point p) {
- return null;
- }
-
-}