created mirror
This commit is contained in:
117
Modules/iter/DimRecursor.java
Normal file
117
Modules/iter/DimRecursor.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
DimRecursor.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* 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 Benjamin Fallenstein
|
||||
*/
|
||||
|
||||
package org.gzigzag;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
/** The dimension recursion the Vanishing view did formerly.
|
||||
* XXX remove verbose debugging messages
|
||||
*/
|
||||
|
||||
public class DimRecursor extends Iter.Any {
|
||||
public static final String rcsid = "$Id: DimRecursor.java,v 1.1 2000/11/16 20:28:53 bfallenstein Exp $";
|
||||
public static final boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
|
||||
public DimRecursor(String[] dims, Iter.Dim iter, boolean included,
|
||||
int maxlevel) {
|
||||
this.dims = dims;
|
||||
this.iter = iter;
|
||||
this.included = included;
|
||||
this.maxlevel = maxlevel;
|
||||
this.higher = new Vector[dims.length];
|
||||
this.curr = new Vector[dims.length];
|
||||
}
|
||||
|
||||
public Iter.Dim iter;
|
||||
public String[] dims;
|
||||
public int dim, level;
|
||||
|
||||
protected Enumeration enum;
|
||||
protected Vector[] curr, higher;
|
||||
|
||||
protected int higherdim, maxlevel;
|
||||
|
||||
protected static final Object NULL = new Object();
|
||||
|
||||
public void doStart() {
|
||||
Vector v = new Vector();
|
||||
v.addElement(root);
|
||||
enum = v.elements();
|
||||
higher[0] = v;
|
||||
for(int i=0; i<dims.length; i++) {
|
||||
curr[i] = new Vector();
|
||||
}
|
||||
dim = 0; level = 0; higherdim = 0;
|
||||
}
|
||||
|
||||
public Iter.Step getNext() {
|
||||
if(level == 0) {
|
||||
iter.start(root, dims[0]);
|
||||
level = 1;
|
||||
} else {
|
||||
iter.next();
|
||||
p("Got next: "+iter.here);
|
||||
}
|
||||
|
||||
while(iter.here == null) {
|
||||
p("null");
|
||||
while(!enum.hasMoreElements()) {
|
||||
if(level > 1) {
|
||||
higherdim++;
|
||||
p("no el on hdim "+higherdim);
|
||||
if(higherdim == dim) higherdim++;
|
||||
}
|
||||
if(level == 1 || higherdim >= dims.length) {
|
||||
p("Iter.Dims -- no higher dim on dim "+dim);
|
||||
dim++;
|
||||
higherdim = 0;
|
||||
if(dim >= dims.length) {
|
||||
p("Iter.Dims -- no dim on level "+level);
|
||||
level++;
|
||||
if(level > maxlevel) return null;
|
||||
dim = 0; higherdim = 1;
|
||||
p("Iter.Dims level: "+level);
|
||||
boolean doContinue = false;
|
||||
for(int d=0; d<dims.length; d++) {
|
||||
if(curr[d].size() > 0) doContinue = true;
|
||||
higher[d] = curr[d];
|
||||
curr[d] = new Vector();
|
||||
}
|
||||
if(!doContinue) return null;
|
||||
}
|
||||
}
|
||||
if(level > 1) enum = higher[higherdim].elements();
|
||||
else enum = higher[0].elements();
|
||||
}
|
||||
iter.start((Iter.Step)enum.nextElement(), dims[dim]);
|
||||
}
|
||||
|
||||
curr[dim].addElement(iter.here);
|
||||
p("ret: "+iter.here.cell);
|
||||
return iter.here;
|
||||
}
|
||||
|
||||
public void stop() { iter.stop(); }
|
||||
}
|
||||
177
Modules/iter/EnumVanishingView.zob
Normal file
177
Modules/iter/EnumVanishingView.zob
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
EnumVanishingView.zob
|
||||
*
|
||||
* Copyright (c) 1999-2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* 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 Benjamin Fallenstein, based on VanishingView by Tuomas Lukka
|
||||
*/
|
||||
|
||||
|
||||
package org.gzigzag;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
/** A reimplementation of the vanishing raster.
|
||||
* Much simpler than the original one since this one does not try
|
||||
* to do the hard rasters as well.
|
||||
*/
|
||||
|
||||
public class EnumVanishingView implements FlobView, ZOb {
|
||||
public static final String rcsid = "$Id: EnumVanishingView.zob,v 1.1 2000/11/16 20:28:53 bfallenstein Exp $";
|
||||
public static boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
static final void pa(String s) { System.out.println(s); }
|
||||
|
||||
// Following are the parameters out of which the constructor
|
||||
// is created.
|
||||
|
||||
STRUCTPARAMS {
|
||||
|
||||
/** The factor to shrink the cells with when moving away from
|
||||
* center.
|
||||
*/
|
||||
float[] shrink // 2..2
|
||||
= new float[] {(float)0.9, (float)0.9};
|
||||
|
||||
/** The factor the center cell is enlarged with from default.
|
||||
*/
|
||||
float[] initmul // 2..2
|
||||
= new float[] {(float)1.6, (float)1.6};
|
||||
|
||||
/** The factor to enlarge the center cell on top of initmul.
|
||||
* This only has an effect on the center cell whereas initmul
|
||||
* affects all cells.
|
||||
*/
|
||||
float[] centermul // 2..2
|
||||
= new float[] {(float)1.0, (float)1.0};
|
||||
|
||||
/** The distance between neighbouring cells.
|
||||
*/
|
||||
int gap
|
||||
= 5;
|
||||
|
||||
/** The depth to raster to.
|
||||
*/
|
||||
int depth
|
||||
= 5;
|
||||
|
||||
/** The precedence order of dimensions.
|
||||
*/
|
||||
int[] pref // 2..5
|
||||
= new int[] {0, 1, 2};
|
||||
|
||||
/** Whether to allow cell sizes to vary.
|
||||
*/
|
||||
boolean varsize
|
||||
= false;
|
||||
|
||||
}
|
||||
|
||||
// XXX This should be a structparam later on.
|
||||
FlobDecorator linker = new StdLinks();
|
||||
|
||||
public void raster(FlobSet into, FlobFactory fact,
|
||||
ZZCell view, String[] dims, ZZCell accursed) {
|
||||
|
||||
Dimension fs = into.getSize();
|
||||
|
||||
// Precalculate sizes and gaps.
|
||||
int[] gaps = new int[depth];
|
||||
Dimension[] size = new Dimension[depth+1];
|
||||
float[] sizfact = new float[depth+1];
|
||||
|
||||
float xf = initmul[0], xf0 = xf;
|
||||
float yf = initmul[1], yf0 = yf;
|
||||
sizfact[0] = yf;
|
||||
Dimension d0 = fact.getSize(null, yf);
|
||||
Dimension d = (varsize ? fact.getSize(accursed, yf) : d0);
|
||||
|
||||
for(int i=0; i<depth; i++) {
|
||||
xf *= shrink[0];
|
||||
yf *= shrink[1];
|
||||
if(!varsize) {
|
||||
Dimension dc = new Dimension();
|
||||
size[i+1] = dc;
|
||||
dc.width = (int)(d.width * xf/xf0);
|
||||
dc.height = (int)(d.height * yf/yf0);
|
||||
}
|
||||
sizfact[i+1] = yf;
|
||||
gaps[i] = (int)(gap * xf);
|
||||
}
|
||||
|
||||
d.width *= centermul[0];
|
||||
d.height *= centermul[1];
|
||||
|
||||
// flob depth multiplier and offset.
|
||||
// flob depth = d1 + dm*level
|
||||
int d1 = 1;
|
||||
int dm = 10;
|
||||
int maxd = d1 + dm * depth;
|
||||
|
||||
Iter.Alter alter = new Iter.Alter();
|
||||
alter.included = false;
|
||||
|
||||
DimRecursor dim = new DimRecursor(dims, alter, true, depth);
|
||||
|
||||
Iter.Limited limit = new Iter.Limited();
|
||||
limit.iter = dim;
|
||||
limit.n = depth;
|
||||
|
||||
Iter.Once once = new Iter.Once();
|
||||
once.iter = limit;
|
||||
|
||||
once.start(new Iter.Step(accursed));
|
||||
|
||||
Point ctr = new Point(fs.width/2, fs.height/2);
|
||||
Flob flob0 = fact.centerFlob(into, accursed, accursed, sizfact[0],
|
||||
ctr, 0, 0, d1, d);
|
||||
once.here.info = flob0;
|
||||
p("Start recursing really");
|
||||
|
||||
for(ZZCell c = once.next(); c != null; c = once.next()) {
|
||||
Flob f = (Flob)once.here.from.info;
|
||||
p("Flob: "+f+" from: "+once.here.from);
|
||||
if(f == null) throw new ZZError("XXX no flob found");
|
||||
|
||||
int dir = alter.ind>0 ? 1 : -1;
|
||||
int dpt = once.here.nth;
|
||||
|
||||
// Alignments
|
||||
int fxa, fya, txa, tya;
|
||||
if(dim.dim == 0) { fxa=dir; txa=-dir; fya=0; tya=0; }
|
||||
else if(dim.dim == 1) { fxa=0; txa=0; fya=dir; tya=-dir; }
|
||||
else { fxa=dir; fya=dir; txa=-dir; tya=-dir; }
|
||||
|
||||
Point p = f.getPoint(fxa, fya);
|
||||
Point q = ZZUtil.movePoint(p, fxa, fya, gaps[dpt]);
|
||||
|
||||
Flob g = fact.centerFlob(into, c, c, sizfact[dpt], q, txa, tya,
|
||||
d1+dpt*dm, size[dpt]);
|
||||
once.here.info = g;
|
||||
p("To "+once.here+" assign "+g);
|
||||
}
|
||||
|
||||
linker.decorate(into, "", view);
|
||||
|
||||
// Do the dimensions.
|
||||
if(true)
|
||||
ZZUtil.showFlobDims(into, fact, view, 3);
|
||||
}
|
||||
|
||||
}
|
||||
212
Modules/iter/Iter.java
Normal file
212
Modules/iter/Iter.java
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
Iter.java
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* 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 Benjamin Fallenstein
|
||||
*/
|
||||
|
||||
package org.gzigzag;
|
||||
import java.util.*;
|
||||
|
||||
/** Help for iterating along ranks in various ways.
|
||||
* A proposed alternative to ZZIter.
|
||||
* XXX make constructors work (how?)
|
||||
* XXX remove verbose debugging messages
|
||||
* XXX make MUCH faster!
|
||||
*/
|
||||
|
||||
public class Iter {
|
||||
public static final String rcsid = "$Id: Iter.java,v 1.1 2000/11/16 20:28:53 bfallenstein Exp $";
|
||||
public static final boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
|
||||
static public class Step {
|
||||
public ZZCell cell;
|
||||
public Step from;
|
||||
public int nth;
|
||||
|
||||
public Object info;
|
||||
|
||||
// Do not need to be set (then, dir == null).
|
||||
public String dim = null;
|
||||
public int dir;
|
||||
|
||||
public Step(ZZCell c) { from = null; cell = c; nth = 0; }
|
||||
public Step(Step f, ZZCell c, int n) { from = f; cell = c; nth = n; }
|
||||
|
||||
public Step go(ZZCell c) { return new Step(this, c, nth+1); }
|
||||
public Step go(String dim, int dir) {
|
||||
p("step "+cell+" "+dim+" "+dir);
|
||||
ZZCell tocell = cell.s(dim, dir);
|
||||
p("tocell "+tocell);
|
||||
if(tocell == null) return null;
|
||||
Step res = go(tocell);
|
||||
p("res.cell "+res.cell);
|
||||
res.dim = dim; res.dir = dir;
|
||||
return res;
|
||||
}
|
||||
|
||||
public String toString() { return "[Iter.Step for "+cell+"]"; }
|
||||
}
|
||||
|
||||
static public abstract class Any {
|
||||
public Step here, root;
|
||||
public boolean included;
|
||||
|
||||
protected abstract Step getNext();
|
||||
protected void doStart() {}
|
||||
|
||||
// public Any(boolean included) { this.included = included; }
|
||||
public ZZCell start(Step s) {
|
||||
here = s; root = s;
|
||||
doStart();
|
||||
if(!included) next();
|
||||
return here != null ? here.cell: null;
|
||||
}
|
||||
public ZZCell next() {
|
||||
if(here == null) return null;
|
||||
here = getNext();
|
||||
return here != null ? here.cell : null;
|
||||
}
|
||||
public boolean more() { return here != null; }
|
||||
public void stop() { here = null; }
|
||||
}
|
||||
|
||||
|
||||
static public abstract class Dim extends Any {
|
||||
String dim; int fdir = 1;
|
||||
|
||||
// public Dim(String dim, int fdir, boolean included) {
|
||||
// this.dim = dim;
|
||||
// this.fdir = fdir;
|
||||
// this.included = included;
|
||||
// }
|
||||
|
||||
public void start(Step s, String dim) {
|
||||
this.dim = dim; start(s);
|
||||
}
|
||||
public void start(Step s, String dim, int fdir) {
|
||||
this.dim = dim; this.fdir = fdir; start(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class Rank extends Dim {
|
||||
protected Step getNext() { return here.go(dim, fdir); }
|
||||
}
|
||||
|
||||
|
||||
static public class Alter extends Dim {
|
||||
/** Current position negwards and poswards. */
|
||||
Step neg, pos;
|
||||
|
||||
public int ind;
|
||||
|
||||
public void doStart() {
|
||||
neg = here.go(dim, -fdir);
|
||||
pos = here.go(dim, fdir);
|
||||
p("alter start: "+pos+" "+neg+" // "+(pos==root?"yes":"no"));
|
||||
ind = 0;
|
||||
}
|
||||
protected Step getNext() {
|
||||
if(neg == null && pos == null) { p("alter null"); return null; }
|
||||
// Trick: always change ind, only after see if we have something
|
||||
// to return. If not, recurse and get the next one from the other side.
|
||||
Step res;
|
||||
if(ind <= 0) {
|
||||
ind = -ind;
|
||||
ind ++;
|
||||
if(pos == null)
|
||||
return getNext();
|
||||
res = pos;
|
||||
pos = pos.go(dim, fdir);
|
||||
p("alter pos from "+res+" to "+pos);
|
||||
} else {
|
||||
ind = -ind;
|
||||
if(neg == null)
|
||||
return getNext();
|
||||
res = neg;
|
||||
neg = neg.go(dim, -fdir);
|
||||
p("alter neg from "+res+" to "+neg);
|
||||
}
|
||||
p("alter: "+res);
|
||||
// Don't loop XXX doesn't work yet
|
||||
// if(neg!=null && pos!=null && neg.cell==pos.cell) return null;
|
||||
return res;
|
||||
}
|
||||
public void stop() {
|
||||
if(ind > 0) neg = null;
|
||||
else if(ind < 0) pos = null;
|
||||
else super.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public abstract class Filter extends Any {
|
||||
protected Any iter;
|
||||
|
||||
protected abstract boolean check();
|
||||
protected void accepted() {}
|
||||
|
||||
// public Filter(Any iter) { this.iter = iter; }
|
||||
public ZZCell start(Step s) {
|
||||
iter.start(s);
|
||||
here = iter.here;
|
||||
doStart();
|
||||
return here.cell;
|
||||
}
|
||||
public ZZCell next() {
|
||||
if(here == null) return null;
|
||||
do {
|
||||
p("Filter get next...");
|
||||
iter.next();
|
||||
here = iter.here;
|
||||
p("Filter check: "+here);
|
||||
if(here == null) return null;
|
||||
} while(!check());
|
||||
accepted();
|
||||
p("Filter accept "+here);
|
||||
return here.cell;
|
||||
}
|
||||
public void stop() { iter.stop(); }
|
||||
protected Step getNext() { throw new ZZError("getNext on Filter"); }
|
||||
}
|
||||
|
||||
|
||||
static public class Once extends Filter {
|
||||
protected Hashtable done;
|
||||
|
||||
protected void doStart() { done = new Hashtable(); }
|
||||
protected boolean check() { return done.get(here.cell) == null; }
|
||||
protected void accepted() { done.put(here.cell, here.cell); }
|
||||
}
|
||||
|
||||
|
||||
static public class Limited extends Filter {
|
||||
protected int n, donenum;
|
||||
|
||||
// public Limited(Any iter, int n) { this.iter = iter; this.n = n; }
|
||||
protected void doStart() { donenum = 0; }
|
||||
protected boolean check() {
|
||||
if(donenum > n*n*2) return false;
|
||||
return iter.here.nth < n;
|
||||
}
|
||||
protected void accepted() { donenum++; }
|
||||
}
|
||||
}
|
||||
1
Modules/iter/README
Normal file
1
Modules/iter/README
Normal file
@@ -0,0 +1 @@
|
||||
Some experiments for advanced ways of iteration through the structure.
|
||||
Reference in New Issue
Block a user