/* * vec2dTest.java * * Created on March 23, 2007, 4:19 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ /** * * @author Sui Huang */ public class vec2dTest { private static void dispVec(vec2d v, String name){ System.out.println( name+"=("+Double.toString(v.getX())+"," +Double.toString(v.getY())+")"); } public static void main(String[] args) { vec2d ux, uy, v0, v1, v2, v3, v4; ux = new vec2d(1,0); uy = new vec2d(0,1); v0 = new vec2d(0,0); v1 = new vec2d(1,1); v2 = vec2d.add(vec2d.mul(-3,v1), new vec2d(0,-1)); v3 = vec2d.proj(v2,v1); v4 = vec2d.add(v2,vec2d.mul(-1,v3)); System.out.println("basic constructor test"); dispVec(ux, "ux"); dispVec(uy, "uy"); dispVec(v0, "v0"); dispVec(v1, "v1"); dispVec(v2, "v2=-3*v1+(0,-1)"); dispVec(v3, "v3=proj(v2,v1) "); dispVec(v4, "v4=v2-v3 "); System.out.println(); System.out.print("further constructor test"); vec2d t; t = ux.clone(); t.normalize(); dispVec(t, "normalized ux = "); t = uy.clone(); t.normalize(); dispVec(t, "normalized uy = "); try{ t = v0.clone(); t.normalize(); dispVec(t, "normalized v0 = "); }catch (java.lang.IllegalStateException e){ System.out.println("caught exception successfully"); }catch (java.lang.Exception e){ System.out.println("couldn't catch the expected exception"); } t = v2.clone(); t.normalize(); dispVec(t, "normalized v2 = "); t = v3.clone(); t.normalize(); dispVec(t, "normalized v3 = "); t = v4.clone(); t.normalize(); dispVec(t, "normalized v4 = "); System.out.println(); System.out.println("test triangleArea()"); try{ System.out.println("area(v0,v0,v0)="+Double.toString(vec2d.triangleArea(v0,v0,v0))); System.out.println("area(v0,v0,v1)="+Double.toString(vec2d.triangleArea(v0,v0,v1))); System.out.println("area(v0,ux,uy)="+Double.toString(vec2d.triangleArea(v0,ux,uy))); System.out.println("area(v1,ux,v0)="+Double.toString(vec2d.triangleArea(v1,ux,v0))); }catch(Exception e){ System.out.println("caught unexpected exception"); } System.out.println(); try{ boolean b; if ((vec2d.coline(v1,v1,v1)==true)&& (vec2d.coline(v0,v1,v1)==true)&& (vec2d.coline(v0,v1,v2)==false)) { System.out.println("coline() test passed"); }else{ System.out.println("coline() test failed"); } }catch(Exception e){ System.out.println("coline() test failed with unexpected exception"); } } }