testVector2D.cc

 1 const char *help = "\
 2 progname: testVector2D.cc\n\
 3 code2html: This program tests Vector2D class methods.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Dan Sunday (http:www.softsurfer.com) and Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "general.h"
 8 #include "Point2D.h"
 9 #include "Vector2D.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16  	real x1, y1;
17  	real x2, y2;
18 	bool verbose;
19 
20 	// Construct the command line
21   	CmdLine cmd;
22 	cmd.setBOption("write log", false);
23 	
24   	// Put the help line at the beginning
25   	cmd.info(help);
26 
27   	cmd.addText("\nArguments:");
28   	cmd.addRCmdArg("x1", &x1, "x1");
29   	cmd.addRCmdArg("y1", &y1, "y1");
30   	cmd.addRCmdArg("x2", &x2, "x2");
31   	cmd.addRCmdArg("y2", &y2, "y2");
32   	cmd.addText("\nOptions:");
33   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
34 
35 	cmd.read(argc, argv);
36 
37 	double	 a, c[3];
38 	Vector2D u, v(1, 0), w(0,1);
39 	Vector2D vx[3];
40 
41 
42 	// output preset coords of v and w
43 	print("Initial v = %s\n", v.sprint());
44 	print("Initial w = %s\n", w.sprint());
45 
46 	// input new values 
47 	v.x = x1;
48 	v.y = y1;
49 
50 	w.x = x2;
51 	w.y = y2;
52 
53 	print("v = %s\n", v.sprint());
54 	print("w = %s\n", w.sprint());
55 
56 	// test operators
57 	u = -v;			print("-v = %s\n", u.sprint());
58 	u = ~v;			print("~v = %s\n", u.sprint());
59 	u = 2*v;		print("2*v = %s\n", u.sprint());
60 	u = v + w;		print("v + w = %s\n", u.sprint());
61 	u = (v + w)/2;		print("(v + w)/2 = %s\n", u.sprint());
62 	u = v - w;		print("v - w = %s\n", u.sprint());
63 	u = (v - w)*0.5;	print("(v - w)*0.5 = %s\n", u.sprint());
64 	a = v * w;		print("v * w = %g\n", a);
65 	a = v | w;		print("v | w = %g\n", a);
66 	a = ~v * w;		print("~v * w = %g\n", a);
67 	print("\n");
68 
69 	// test functions
70 	c[0]= 0.5; c[1]= 0.5;	print("c[]= {%g, %g}\n", c[0], c[1]);
71 	vx[0]= v;  vx[1]= w;	print("vx[]= {%s, %s}\n", vx[0].sprint(), vx[1].sprint());
72 	u = sum(2,c,vx);	print("sum(2,c,vx) = %s\n", u.sprint());
73 
74 	u = v.len2();		print("v.len2() = %s\n", u.sprint());
75 	u = v.len();		print("v.len()  = %s\n", u.sprint());
76 	v.normalize();		print("v.normalize() = %s\n", v.sprint());
77 	w.normalize();		print("w.normalize() = %s\n", w.sprint());
78 	print("\n");
79 
80 }