// By Haw-ren Fang, TA of cmsc420-0401, Spring 2002 import java.lang.*; import java.io.*; import java.util.*; public class QuadtreeDriver1 { public static void main(String args[]) { int score = 0; Quadtree qtree = new QuadtreeImpl(); Quadnode qroot = new Quadnode(); qtree.setRoot(qroot); if(qroot.equals(qtree.getRoot())) { System.out.println("setRoot()/getRoot() test: 5/5"); score += 5; } else System.out.println("setRoot()/getRoot() test: 0/5"); qroot = new Quadnode(new Patch(new String("w01"))); qroot.setChild(0, new Quadnode(new Patch(new String("w0100")))); qroot.setChild(1, new Quadnode(new Patch(new String("w0101")))); qroot.setChild(2, new Quadnode(new Patch(new String("w0110")))); qroot.setChild(3, new Quadnode(new Patch(new String("w0111")))); Quadnode qnode = qroot.getChild(1); qnode.setChild(0, new Quadnode(new Patch(new String("w010100")))); qnode.setChild(1, new Quadnode(new Patch(new String("w010101")))); qnode.setChild(2, new Quadnode(new Patch(new String("w010110")))); qnode.setChild(3, new Quadnode(new Patch(new String("w010111")))); qtree.setRoot(qroot); // now the tree looks like this // w01 // |----w0100 // |----w0101 // | |----w0101000 // | |----w0101001 // | |----w0101010 // | \----w0101011 // |----w0110 // \----w0111 if(!qtree.containsNodeWithPatchName("w01")) System.out.println("containsNodeWithPatchName() test #1: 0/5"); else if(qtree.containsNodeWithPatchName("zz")) System.out.println("containsNodeWithPatchName() test #1: 0/5"); else { System.out.println("containsNodeWithPatchName() test #1: 5/5"); score += 5; } if(!qtree.containsNodeWithPatchName("w0100")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w0101")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w0110")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w0111")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w010100")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w010101")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w010110")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(!qtree.containsNodeWithPatchName("w010111")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else if(qtree.containsNodeWithPatchName("w010000")) System.out.println("containsNodeWithPatchName() test #2: 0/5"); else { System.out.println("containsNodeWithPatchName() test #2: 5/5"); score += 5; } Patch f = new Patch("f"); f.setPoints(0,0,0, 0,1,0, 1,0,0, 1,1,0); Patch w = new Patch("w"); w.setPoints(0,0,0, 0,0,1, 0,1,0, 0,1,1); try { LightInteractionObject lio = qtree.lightInteraction(f,w,0,-1); System.out.println("NonPositiveEpsException test: 0/5"); } catch(NonPositiveEpsException e) { System.out.println("NonPositiveEpsException test: 5/5"); score += 5; } try { System.out.println("lightInteraction() test #1:"); LightInteractionObject lio = qtree.lightInteraction(f,w,0.75,0.75); // These are all the links: // link(w, f00) // link(w, f01) // link(w, f10) // link(w, f11) // This is the quadtree of f: // f // |----f00 // |----f01 // |----f10 // \----f11 // The quadtree of w is just a single node w. Quadtree wall = lio.wall; if(!wall.containsNodeWithPatchName("w")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w00")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w01")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w10")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w11")) System.out.println("LightInteractionObject.wall: 0/5"); else { System.out.println("LightInteractionObject.wall: 5/5"); score += 5; } Quadtree floor = lio.floor; if(!floor.containsNodeWithPatchName("f")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f00")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f01")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f10")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f11")) System.out.println("LightInteractionObject.floor: 0/5"); else if(floor.containsNodeWithPatchName("f0000")) System.out.println("LightInteractionObject.floor: 0/5"); else if(floor.containsNodeWithPatchName("f0110")) System.out.println("LightInteractionObject.floor: 0/5"); else { System.out.println("LightInteractionObject.floor: 5/5"); score += 5; } AbstractHashTable links = lio.links; PatchSet ps; if(links.containsKey("w00")) System.out.println("LightInteractionObject.links: 0/5"); else if((ps=(PatchSet)links.get("w")) == null) System.out.println("LightInteractionObject.links: 0/5"); else { Iterator it = ps.iterator(); int level1=0, levelx=0; while(it.hasNext()) { String name = ((Patch)it.next()).getName(); if(name.length() == 3) level1 ++; else levelx ++; } if(levelx!=0 || level1!=4) { System.out.println("LightInteractionObject.links: 0/5"); } else { System.out.println("LightInteractionObject.links: 5/5"); score += 5; } } } catch(NonPositiveEpsException e) { System.out.println("lightInteraction() test: 0/30"); } try { System.out.println("lightInteraction() test #1:"); LightInteractionObject lio = qtree.lightInteraction(f,w,.75,0.125); // These are all the links: // link(w, f0000) // link(w, f0001) // link(w, f0010) // link(w, f0011) // link(w, f0100) // link(w, f0101) // link(w, f0110) // link(w, f0111) // link(w, f10) // link(w, f11) // This is the quadtree of f: // f // |----f00 // | |----f0000 // | |----f0001 // | |----f0010 // | \----f0011 // |----f01 // | |----f0100 // | |----f0101 // | |----f0110 // | \----f0111 // |----f10 // \----f11 // The quadtree of w is just a single node w. Quadtree wall = lio.wall; if(!wall.containsNodeWithPatchName("w")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w00")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w01")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w10")) System.out.println("LightInteractionObject.wall: 0/5"); else if(wall.containsNodeWithPatchName("w11")) System.out.println("LightInteractionObject.wall: 0/5"); else { System.out.println("LightInteractionObject.wall: 5/5"); score += 5; } Quadtree floor = lio.floor; if(!floor.containsNodeWithPatchName("f")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f00")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f01")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f0000")) System.out.println("LightInteractionObject.floor: 0/5"); else if(!floor.containsNodeWithPatchName("f0100")) System.out.println("LightInteractionObject.floor: 0/5"); else if(floor.containsNodeWithPatchName("f1000")) System.out.println("LightInteractionObject.floor: 0/5"); else if(floor.containsNodeWithPatchName("f1100")) System.out.println("LightInteractionObject.floor: 0/5"); else { System.out.println("LightInteractionObject.floor: 5/5"); score += 5; } AbstractHashTable links = lio.links; PatchSet ps; if(links.containsKey("w00")) System.out.println("LightInteractionObject.links: 0/5"); else if((ps=(PatchSet)links.get("w")) == null) System.out.println("LightInteractionObject.links: 0/5"); else { Iterator it = ps.iterator(); int level1=0, level2=0, levelx=0; while(it.hasNext()) { String name = ((Patch)it.next()).getName(); switch(name.length()) { case 3: level1 ++; break; case 5: level2 ++; break; default: levelx ++; } } if(levelx!=0 || level1!=2 || level2!=8) { System.out.println("LightInteractionObject.links: 0/5"); } else { System.out.println("LightInteractionObject.links: 5/5"); score += 5; } } } catch(NonPositiveEpsException e) { System.out.println("lightInteraction() test: 0/30"); } System.out.println("Total: " + score + "/50"); } }