1 | #include <cassert> |
---|
2 | #include <iostream> |
---|
3 | #include <vector> |
---|
4 | #include "sphere.h" |
---|
5 | #include "cylinder.h" |
---|
6 | #include "hollow_sphere.h" |
---|
7 | #include "ellipsoid.h" |
---|
8 | #include "single_helix.h" |
---|
9 | #include "iq.h" |
---|
10 | |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | void TestGetFormFactor_sphere() { |
---|
14 | Sphere sphere(1.0); |
---|
15 | |
---|
16 | IQ iq1(10,0.001, 0.3); |
---|
17 | sphere.GetFormFactor(&iq1); |
---|
18 | |
---|
19 | for (int i = 0; i< iq1.iq_data.dim1(); i++) |
---|
20 | cout << iq1.iq_data[i][0]<< " " << iq1.iq_data[i][1] <<endl; |
---|
21 | } |
---|
22 | |
---|
23 | void TestGetShapeType_sphere() { |
---|
24 | Sphere sphere; |
---|
25 | //if (assert(sphere.GetShapeType() == SPHERE)) |
---|
26 | // cout << " it is a sphere" << endl; |
---|
27 | cout << sphere.GetShapeType() << endl; |
---|
28 | } |
---|
29 | |
---|
30 | void TestGetShapeType(GeoShape &gs){ |
---|
31 | cout <<gs.GetShapeType() << endl; |
---|
32 | } |
---|
33 | |
---|
34 | void TestGetVolume_sphere() { |
---|
35 | Sphere s(1); |
---|
36 | cout << "volume is " << s.GetVolume(); |
---|
37 | } |
---|
38 | |
---|
39 | void TestGetAPoint_sphere(){ |
---|
40 | Sphere asphere(10); |
---|
41 | cout << asphere.GetAPoint(1) << endl; |
---|
42 | } |
---|
43 | |
---|
44 | void TestGetFormFactor_HS(){ |
---|
45 | |
---|
46 | HollowSphere hs(10, 2); |
---|
47 | |
---|
48 | IQ iq1(10, 0.001, 0.3); |
---|
49 | hs.GetFormFactor(&iq1); |
---|
50 | |
---|
51 | for (int i = 0; i< iq1.iq_data.dim1(); i++) |
---|
52 | cout << iq1.iq_data[i][0]<< " " << iq1.iq_data[i][1] <<endl; |
---|
53 | |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | void TestGetShapeType_HS(){ |
---|
58 | HollowSphere hs1; |
---|
59 | assert(hs1.GetShapeType() == HOLLOWSPHERE); |
---|
60 | } |
---|
61 | |
---|
62 | void TestIsInside_sphere(){ |
---|
63 | cout << "Testing IsInside(): "; |
---|
64 | Sphere s1(10); |
---|
65 | Point3D pp(20,30,30); |
---|
66 | Point3D pp2(1,1,1); |
---|
67 | |
---|
68 | cout << s1.IsInside(pp) <<" " << s1.IsInside(pp2) << " "; |
---|
69 | cout << "Finished testing IsInside()" <<endl; |
---|
70 | } |
---|
71 | |
---|
72 | void TestCylinder(){ |
---|
73 | Cylinder c1(10,20); |
---|
74 | Point3D p1 = c1.GetAPoint(1); |
---|
75 | Point3D p4 = c1.GetAPoint(1); |
---|
76 | cout << "Got two points inside the cylinder" << endl; |
---|
77 | cout << "the distance is: " << p1.distanceToPoint(p4); |
---|
78 | cout << p1 << endl; |
---|
79 | cout << "is this point inside?:" << c1.IsInside(p1) << endl; |
---|
80 | |
---|
81 | Point3D p2(20,20,20); |
---|
82 | cout << "this point should be outside:" << c1.IsInside(p2) <<endl; |
---|
83 | |
---|
84 | c1.SetOrientation(10,10,10); |
---|
85 | c1.SetCenter(20,20,20); |
---|
86 | |
---|
87 | vector<double> ori; |
---|
88 | ori.push_back(10); |
---|
89 | ori.push_back(10); |
---|
90 | ori.push_back(20); |
---|
91 | |
---|
92 | vector<double> cen; |
---|
93 | cen.push_back(20); |
---|
94 | cen.push_back(20); |
---|
95 | cen.push_back(20); |
---|
96 | |
---|
97 | p1.Transform(ori,cen); |
---|
98 | cout << "is the p1 still inside after orientation?" << c1.IsInside(p1) << endl; |
---|
99 | cout << "p1 p2 distance: " <<p1.distanceToPoint(p4) << endl; |
---|
100 | |
---|
101 | Point3D p3(0,0,0); |
---|
102 | cout <<" this origin point should be outside after transformation:" << c1.IsInside(p3) <<endl; |
---|
103 | |
---|
104 | Point3D pp1(6.8,-2.11,11); |
---|
105 | cout <<"is pp1 inside? "<< c1.IsInside(pp1) << endl; |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void TestEllipsoid(){ |
---|
110 | Ellipsoid e1(5,10,15); |
---|
111 | cout << "generated an ellipsoid:"<<e1.GetRadiusX()<<" "; |
---|
112 | cout <<e1.GetRadiusY()<<" " << e1.GetRadiusZ() << endl; |
---|
113 | cout << "maximum radius is: " << e1.GetMaxRadius() << endl; |
---|
114 | cout << "volume is : " << e1.GetVolume() << endl; |
---|
115 | cout << "Get a point: " << e1.GetAPoint(1.0) << endl; |
---|
116 | |
---|
117 | Point3D p1(1,2,3); |
---|
118 | Point3D p2(6,11,16); |
---|
119 | Point3D p3(100,100,100); |
---|
120 | cout <<"is " << p1 << " inside? " << e1.IsInside(p1) << endl; |
---|
121 | cout <<"is " << p2 << " inside? " << e1.IsInside(p2) << endl; |
---|
122 | |
---|
123 | e1.SetCenter(10,10,10); |
---|
124 | Point3D p4(11,12,13); |
---|
125 | cout <<"is " << p2 << " inside after moved? " << e1.IsInside(p2) << endl; |
---|
126 | |
---|
127 | e1.SetOrientation(90,90,90); |
---|
128 | cout <<"is " << p3 << " inside after rotated? " << e1.IsInside(p3) << endl; |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | void TestSingleHelix(){ |
---|
133 | |
---|
134 | cout <<" Testing single helix" << endl; |
---|
135 | SingleHelix sh(10,3,30,1); |
---|
136 | cout << "Get a point" << sh.GetAPoint(1.0) << endl; |
---|
137 | |
---|
138 | Point3D p1(1,1,-50); //cannot be in sh(10,3,30,1) |
---|
139 | cout <<"is " << p1 <<" inside?" << sh.IsInside(p1)<< endl; |
---|
140 | Point3D p2(-3.15922, -11.6193, 20.5302); //should be inside |
---|
141 | cout <<"is " << p2 <<" inside?" << sh.IsInside(p2)<< endl; |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | int main(){ |
---|
146 | |
---|
147 | //cout << "testing sphere :\n" ; |
---|
148 | //TestGetAPoint_sphere(); |
---|
149 | //TestGetShapeType_sphere(); |
---|
150 | //testing getting shape type from parent |
---|
151 | //Sphere ss(1); |
---|
152 | //TestGetShapeType(ss); |
---|
153 | //TestGetVolume_sphere(); |
---|
154 | //TestIsInside_sphere(); |
---|
155 | |
---|
156 | //cout << "testing hollowsphere: \n" ; |
---|
157 | //TestGetFormFactor_HS(); |
---|
158 | //TestGetShapeType_HS(); |
---|
159 | // TestGetVolume(); |
---|
160 | |
---|
161 | //cout << "testing cylinder:\n"; |
---|
162 | //TestCylinder(); |
---|
163 | |
---|
164 | //cout << "testing ellipsoid :\n"; |
---|
165 | //TestEllipsoid(); |
---|
166 | |
---|
167 | TestSingleHelix(); |
---|
168 | printf("PASS.\n"); |
---|
169 | |
---|
170 | return 0; |
---|
171 | } |
---|