/* OrthoCoordsys.java * * Copyright (c) 2002, Benja Fallenstein * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Benja Fallenstein and Tuomas Lukka */ package gzz.vob.impl; import gzz.vob.*; class OrthoCoordsys { OrthoDepthSorter sorter; boolean[] active; float[] depth, x, y, sx, sy, w, h; int[] parent; int[] nancestors; int[] nextHashtableEntry; int nsys; OrthoCoordsys(float mw, float mh) { this(mw, mh, 50); } OrthoCoordsys(float mw, float mh, int initialSize) { sorter = new OrthoDepthSorter(this, initialSize); active = new boolean[initialSize]; depth = new float[initialSize]; x = new float[initialSize]; y = new float[initialSize]; sx = new float[initialSize]; sy = new float[initialSize]; w = new float[initialSize]; h = new float[initialSize]; parent = new int[initialSize]; nancestors = new int[initialSize]; nextHashtableEntry = new int[initialSize]; clear(mw, mh); } void clear(float mw, float mh) { active[0] = false; depth[0] = 0; x[0] = 0; y[0] = 0; sx[0] = mw; sy[0] = mh; w[0] = 1; h[0] = 1; parent[0] = -1; nancestors[0] = 0; nsys = 1; sorter.clear(); } int add(int mparent, float mdepth, float mx, float my, float msx, float msy, float mw, float mh) { int cs = next(); active[cs] = false; parent[cs] = mparent; setParams(cs, mdepth, mx, my, msx, msy, mw, mh); nancestors[cs] = nancestors[mparent] + 1; nextHashtableEntry[cs] = 0; return cs; } void setParams(int cs, float mdepth, float mx, float my, float msx, float msy, float mw, float mh) { int mparent = parent[cs]; sx[cs] = msx; sy[cs] = msy; w[cs] = mw; h[cs] = mh; // depth are stored as absolute, not relative to parent depth[cs] = depth[mparent] + mdepth; // XXX Depth doesn't change right with setXParams later x[cs] = mx; y[cs] = my; } public void getSqSize(int cs, float[] into) { into[0] = w[cs]; into[1] = h[cs]; } void transformRect(int cs, float[] rect) { if(cs == 0) return; rect[0] *= sx[cs]; rect[1] *= sy[cs]; rect[2] *= sx[cs]; rect[3] *= sy[cs]; rect[0] += x[cs]; rect[1] += y[cs]; transformRect(parent[cs], rect); } protected int next() { int n = nsys; nsys++; if(nsys > depth.length) { int o = depth.length, l = depth.length * 2; boolean[] nactive = new boolean[l]; float[] ndepth = new float[l]; float[] nx = new float[l]; float[] ny = new float[l]; float[] nsx = new float[l]; float[] nsy = new float[l]; float[] nw = new float[l]; float[] nh = new float[l]; int[] nparent = new int[l]; int[] nnancestors = new int[l]; int[] nnext = new int[l]; System.arraycopy(active, 0, nactive, 0, o); System.arraycopy(depth, 0, ndepth, 0, o); System.arraycopy(x, 0, nx, 0, o); System.arraycopy(y, 0, ny, 0, o); System.arraycopy(sx, 0, nsx, 0, o); System.arraycopy(sy, 0, nsy, 0, o); System.arraycopy(w, 0, nw, 0, o); System.arraycopy(h, 0, nh, 0, o); System.arraycopy(parent, 0, nparent, 0, o); System.arraycopy(nancestors, 0, nnancestors, 0, o); System.arraycopy(nextHashtableEntry, 0, nnext, 0, o); active = nactive; depth = ndepth; x = nx; y = ny; sx = nsx; sy = nsy; w = nw; h = nh; parent = nparent; nancestors = nnancestors; nextHashtableEntry = nnext; } return n; } float cx(int cs) { if(cs == 0) return x[0]; float x1 = x[cs]; float x2 = cx(parent[cs]); return x1>x2 ? x1 : x2; } float cy(int cs) { if(cs == 0) return x[0]; float y1 = y[cs]; float y2 = cy(parent[cs]); return y1>y2 ? y1 : y2; } float cw(int cs) { return cx2(cs) - cx(cs); } float ch(int cs) { return cy2(cs) - cy(cs); } float cx2(int cs) { if(cs == 0) return x[0] + sx[0]; float x1 = x[cs] + sx[cs]; float x2 = cx2(parent[cs]); return x1