Update of /cvsroot/bprocessor/test/src/net/sourceforge/bprocessor/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13233/src/net/sourceforge/bprocessor/test
Added Files:
SurfaceDirection.java SurfaceNormal.java
Removed Files:
SurfaceAngle.java
Log Message:
Test for directions added (direction in wich edges are traversed around the boundary of a surface).
--- NEW FILE: SurfaceNormal.java ---
//---------------------------------------------------------------------------------
// $Id: SurfaceNormal.java,v 1.1 2006/12/08 10:55:20 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.test;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.sourceforge.bprocessor.model.Entity;
import net.sourceforge.bprocessor.model.Persistence;
import net.sourceforge.bprocessor.model.Project;
import net.sourceforge.bprocessor.model.Surface;
import net.sourceforge.bprocessor.model.Vertex;
/**
*
*/
public class SurfaceNormal {
/**
* @param args args
*/
public static void main(String[] args) {
File input = new File(args[0]);
try {
Persistence.load(input);
printNormals(Project.getInstance().world().getSurfaces());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Prints the normals of the surfaces
* @param surfaces collection of Surface whose normals are to be printed
*/
private static void printNormals(Collection surfaces) {
List sorted = new LinkedList(surfaces);
Entity.sort(sorted);
Iterator iter = sorted.iterator();
while (iter.hasNext()) {
Surface current = (Surface) iter.next();
Vertex normal = current.normal();
System.out.println(current.getName() + " normal: " + normal);
}
}
}
--- SurfaceAngle.java DELETED ---
--- NEW FILE: SurfaceDirection.java ---
//---------------------------------------------------------------------------------
// $Id: SurfaceDirection.java,v 1.1 2006/12/08 10:55:20 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.test;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.sourceforge.bprocessor.model.CoordinateSystem;
import net.sourceforge.bprocessor.model.Entity;
import net.sourceforge.bprocessor.model.Persistence;
import net.sourceforge.bprocessor.model.Project;
import net.sourceforge.bprocessor.model.Surface;
import net.sourceforge.bprocessor.model.Vertex;
/**
*
*/
public class SurfaceDirection {
/**
* Runs this test on the file named by args[0]
* @param args arguments are filename
*/
public static void main(String[] args) {
File input = new File(args[0]);
try {
Persistence.load(input);
test(Project.getInstance().world().getSurfaces());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void test(Collection surfaces) {
List sorted = new LinkedList(surfaces);
Entity.sort(sorted);
Vertex origin = new Vertex(0, 0, 0);
Vertex i = new Vertex(1, 0, 0);
Vertex j = new Vertex(0, 1, 0);
Vertex k = new Vertex(0, 0, 1);
CoordinateSystem xy = new CoordinateSystem(i, j, k, origin);
CoordinateSystem yx = new CoordinateSystem(j, i, k, origin);
CoordinateSystem xynegz = new CoordinateSystem(i, j, origin.minus(k), origin);
CoordinateSystem yz = new CoordinateSystem(j, k, i, origin);
CoordinateSystem zx = new CoordinateSystem(k, i, j, origin);
printDirections(sorted);
printDirections(sorted, xy);
printDirections(sorted, yx);
printDirections(sorted, xynegz);
printDirections(sorted, yz);
printDirections(sorted, zx);
}
/**
* Prints the direction of all surfaces in a list
* translated to the CoordinateSystem
* @param surfaces the list of surfaces whose directions are to be printed
* @param system the CoordinateSystem to translate the surface to
*/
private static void printDirections(List surfaces, CoordinateSystem system) {
System.out.println(" in " + system + ":");
Iterator iter = surfaces.iterator();
while (iter.hasNext()) {
Surface current = (Surface) iter.next();
int direction = Surface.direction(current.getEdges(), system);
if (direction == Surface.LEFT) {
System.out.println(" " + current.getName() + " direction: LEFT");
} else if (direction == Surface.RIGHT) {
System.out.println(" " + current.getName() + " direction: RIGHT");
} else if (direction == Surface.PARALLEL) {
System.out.println(" " + current.getName() + " direction: PARALLEL");
}
}
}
private static void printDirections(List surfaces) {
System.out.println(" in own coordinate system:");
Iterator iter = surfaces.iterator();
while (iter.hasNext()) {
Surface current = (Surface) iter.next();
CoordinateSystem system = current.coordinateSystem();
int direction = Surface.direction(current.getEdges(), system);
if (direction == Surface.LEFT) {
System.out.println(" " + current.getName() + " direction: LEFT in " + system);
} else if (direction == Surface.RIGHT) {
System.out.println(" " + current.getName() + " direction: RIGHT in " + system);
} else if (direction == Surface.PARALLEL) {
System.out.println(" " + current.getName() + " direction: PARALLEL in " + system);
}
}
}
}
|