testPoint2D.cc

 1 const char *help = "\
 2 progname: testPoint2D.cc\n\
 3 code2html: This program tests Point2D 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 	Point2D	 P1(1, 0), P2(0,1);
39 	Point2D	 Q[3], R;
40 	Vector2D v, w;
41 
42 	print("sizeof Point2D = %d\n", sizeof(Point2D));
43 	print("sizeof double = %d\n", sizeof(double));
44 
45 	// output preset coords of P1 and P2
46 	print("Initial P1 = %s\n", P1.sprint());
47 	print("Initial P2 = %s\n", P2.sprint());
48 
49 	sPoint2D p1 = P1.get();
50 	print("Initial p1 = (%g, %g)\n", p1.x, p1.y);
51 
52 	// input new values for Points P1 and P2
53 	P1.x = x1;
54 	P1.y = y1;
55 
56 	P2.x = x2;
57 	P2.y = y2;
58 
59 	print("P1 = %s\n", P1.sprint());
60 	print("P2 = %s\n", P2.sprint());
61 	
62 	// test all operators
63 	v = P1 - P2;		print("P1 - P2 = %s\n", v.sprint());
64 	R = 2*P1;		print("2*P1 = %s\n", R.sprint());
65 	R = P1/2;		print("P1/2 = %s\n", R.sprint());
66 	R = P1 + P2;		print("P1 + P2 = %s\n", R.sprint());
67 	R = 2*P1 + P2;		print("2*P1 + P2 = %s\n", R.sprint());
68 	R = (P1 + P2)/2;	print("(P1 + P2)/2 = %s\n", R.sprint());
69 	R = (P1 + P2)*0.5;	print("(P1 + P2)*0.5 = %s\n", R.sprint());
70 	print("\n");
71 
72 	// test all functions
73 	a = d(P1,P2);		print("d(P1,P2) = %g\n", a);
74 	a = d2(P1,P2);		print("d2(P1,P2) = %g\n", a);
75 
76 	c[0]= 0.5; c[1]= 0.5;	print("c[]= {%g, %g}\n", c[0], c[1]);
77 	Q[0]= P1;  Q[1]= P2;	print("Q[]= {%s, %s}\n", Q[0].sprint(), Q[1].sprint());
78 	R = asum(2,c,Q);	print("asum(2,c,Q) = %s\n", R.sprint());
79 }