]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/exceptionFuzz/3d-cube.js
4 // http://www.speich.net/computer/moztesting/3d.htm
5 // Created by Simon Speich
8 var MTrans
= new Array(); // transformation matrix
9 var MQube
= new Array(); // position information of qube
10 var I
= new Array(); // entity matrix
11 var Origin
= new Object();
12 var Testing
= new Object();
16 20: 2889.0000000000045,
17 40: 2889.0000000000055,
18 80: 2889.000000000005,
19 160: 2889.0000000000055
22 var DisplArea
= new Object();
23 DisplArea
.Width
= 300;
24 DisplArea
.Height
= 300;
26 function DrawLine(From
, To
) {
31 var dx
= Math
.abs(x2
- x1
);
32 var dy
= Math
.abs(y2
- y1
);
42 if (x2
>= x1
) { IncX1
= 1; IncX2
= 1; }
43 else { IncX1
= -1; IncX2
= -1; }
44 if (y2
>= y1
) { IncY1
= 1; IncY2
= 1; }
45 else { IncY1
= -1; IncY2
= -1; }
63 NumPix
= Math
.round(Q
.LastPx
+ NumPix
);
66 for (; i
< NumPix
; i
++) {
79 function CalcCross(V0
, V1
) {
80 var Cross
= new Array();
81 Cross
[0] = V0
[1]*V1
[2] - V0
[2]*V1
[1];
82 Cross
[1] = V0
[2]*V1
[0] - V0
[0]*V1
[2];
83 Cross
[2] = V0
[0]*V1
[1] - V0
[1]*V1
[0];
87 function CalcNormal(V0
, V1
, V2
) {
88 var A
= new Array(); var B
= new Array();
89 for (var i
= 0; i
< 3; i
++) {
94 var Length
= Math
.sqrt(A
[0]*A
[0] + A
[1]*A
[1] + A
[2]*A
[2]);
95 for (var i
= 0; i
< 3; i
++) A
[i
] = A
[i
] / Length
;
100 function CreateP(X
,Y
,Z
) {
104 // multiplies two matrices
105 function MMulti(M1
, M2
) {
106 var M
= [[],[],[],[]];
111 for (; j
< 4; j
++) M
[i
][j
] = M1
[i
][0] * M2
[0][j
] + M1
[i
][1] * M2
[1][j
] + M1
[i
][2] * M2
[2][j
] + M1
[i
][3] * M2
[3][j
];
116 //multiplies matrix with vector
117 function VMulti(M
, V
) {
118 var Vect
= new Array();
120 for (;i
< 4; i
++) Vect
[i
] = M
[i
][0] * V
[0] + M
[i
][1] * V
[1] + M
[i
][2] * V
[2] + M
[i
][3] * V
[3];
124 function VMulti2(M
, V
) {
125 var Vect
= new Array();
127 for (;i
< 3; i
++) Vect
[i
] = M
[i
][0] * V
[0] + M
[i
][1] * V
[1] + M
[i
][2] * V
[2];
132 function MAdd(M1
, M2
) {
133 var M
= [[],[],[],[]];
138 for (; j
< 4; j
++) M
[i
][j
] = M1
[i
][j
] + M2
[i
][j
];
143 function Translate(M
, Dx
, Dy
, Dz
) {
153 function RotateX(M
, Phi
) {
156 var Cos
= Math
.cos(a
);
157 var Sin
= Math
.sin(a
);
167 function RotateY(M
, Phi
) {
170 var Cos
= Math
.cos(a
);
171 var Sin
= Math
.sin(a
);
181 function RotateZ(M
, Phi
) {
184 var Cos
= Math
.cos(a
);
185 var Sin
= Math
.sin(a
);
195 function DrawQube() {
196 // calc current normals
197 var CurN
= new Array();
200 for (; i
> -1; i
--) CurN
[i
] = VMulti2(MQube
, Q
.Normal
[i
]);
201 if (CurN
[0][2] < 0) {
202 if (!Q
.Line
[0]) { DrawLine(Q
[0], Q
[1]); Q
.Line
[0] = true; };
203 if (!Q
.Line
[1]) { DrawLine(Q
[1], Q
[2]); Q
.Line
[1] = true; };
204 if (!Q
.Line
[2]) { DrawLine(Q
[2], Q
[3]); Q
.Line
[2] = true; };
205 if (!Q
.Line
[3]) { DrawLine(Q
[3], Q
[0]); Q
.Line
[3] = true; };
207 if (CurN
[1][2] < 0) {
208 if (!Q
.Line
[2]) { DrawLine(Q
[3], Q
[2]); Q
.Line
[2] = true; };
209 if (!Q
.Line
[9]) { DrawLine(Q
[2], Q
[6]); Q
.Line
[9] = true; };
210 if (!Q
.Line
[6]) { DrawLine(Q
[6], Q
[7]); Q
.Line
[6] = true; };
211 if (!Q
.Line
[10]) { DrawLine(Q
[7], Q
[3]); Q
.Line
[10] = true; };
213 if (CurN
[2][2] < 0) {
214 if (!Q
.Line
[4]) { DrawLine(Q
[4], Q
[5]); Q
.Line
[4] = true; };
215 if (!Q
.Line
[5]) { DrawLine(Q
[5], Q
[6]); Q
.Line
[5] = true; };
216 if (!Q
.Line
[6]) { DrawLine(Q
[6], Q
[7]); Q
.Line
[6] = true; };
217 if (!Q
.Line
[7]) { DrawLine(Q
[7], Q
[4]); Q
.Line
[7] = true; };
219 if (CurN
[3][2] < 0) {
220 if (!Q
.Line
[4]) { DrawLine(Q
[4], Q
[5]); Q
.Line
[4] = true; };
221 if (!Q
.Line
[8]) { DrawLine(Q
[5], Q
[1]); Q
.Line
[8] = true; };
222 if (!Q
.Line
[0]) { DrawLine(Q
[1], Q
[0]); Q
.Line
[0] = true; };
223 if (!Q
.Line
[11]) { DrawLine(Q
[0], Q
[4]); Q
.Line
[11] = true; };
225 if (CurN
[4][2] < 0) {
226 if (!Q
.Line
[11]) { DrawLine(Q
[4], Q
[0]); Q
.Line
[11] = true; };
227 if (!Q
.Line
[3]) { DrawLine(Q
[0], Q
[3]); Q
.Line
[3] = true; };
228 if (!Q
.Line
[10]) { DrawLine(Q
[3], Q
[7]); Q
.Line
[10] = true; };
229 if (!Q
.Line
[7]) { DrawLine(Q
[7], Q
[4]); Q
.Line
[7] = true; };
231 if (CurN
[5][2] < 0) {
232 if (!Q
.Line
[8]) { DrawLine(Q
[1], Q
[5]); Q
.Line
[8] = true; };
233 if (!Q
.Line
[5]) { DrawLine(Q
[5], Q
[6]); Q
.Line
[5] = true; };
234 if (!Q
.Line
[9]) { DrawLine(Q
[6], Q
[2]); Q
.Line
[9] = true; };
235 if (!Q
.Line
[1]) { DrawLine(Q
[2], Q
[1]); Q
.Line
[1] = true; };
237 Q
.Line
= [false,false,false,false,false,false,false,false,false,false,false,false];
242 if (Testing
.LoopCount
> Testing
.LoopMax
) return;
243 var TestingStr
= String(Testing
.LoopCount
);
244 while (TestingStr
.length
< 3) TestingStr
= "0" + TestingStr
;
245 MTrans
= Translate(I
, -Q
[8].V
[0], -Q
[8].V
[1], -Q
[8].V
[2]);
246 MTrans
= RotateX(MTrans
, 1);
247 MTrans
= RotateY(MTrans
, 3);
248 MTrans
= RotateZ(MTrans
, 5);
249 MTrans
= Translate(MTrans
, Q
[8].V
[0], Q
[8].V
[1], Q
[8].V
[2]);
250 MQube
= MMulti(MTrans
, MQube
);
252 for (; i
> -1; i
--) {
253 Q
[i
].V
= VMulti(MTrans
, Q
[i
].V
);
260 function Init(CubeSize
) {
262 Origin
.V
= [150,150,20,1];
263 Testing
.LoopCount
= 0;
264 Testing
.LoopMax
= 50;
268 Testing
.TimeTemp
= 0;
269 Testing
.TimeTotal
= 0;
270 Testing
.Init
= false;
272 // transformation matrix
280 // position information of qube
297 Q
[0] = new CreateP(-CubeSize
,-CubeSize
, CubeSize
);
298 Q
[1] = new CreateP(-CubeSize
, CubeSize
, CubeSize
);
299 Q
[2] = new CreateP( CubeSize
, CubeSize
, CubeSize
);
300 Q
[3] = new CreateP( CubeSize
,-CubeSize
, CubeSize
);
301 Q
[4] = new CreateP(-CubeSize
,-CubeSize
,-CubeSize
);
302 Q
[5] = new CreateP(-CubeSize
, CubeSize
,-CubeSize
);
303 Q
[6] = new CreateP( CubeSize
, CubeSize
,-CubeSize
);
304 Q
[7] = new CreateP( CubeSize
,-CubeSize
,-CubeSize
);
307 Q
[8] = new CreateP(0, 0, 0);
309 // anti-clockwise edge check
310 Q
.Edge
= [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]];
312 // calculate squad normals
313 Q
.Normal
= new Array();
314 for (var i
= 0; i
< Q
.Edge
.length
; i
++) Q
.Normal
[i
] = CalcNormal(Q
[Q
.Edge
[i
][0]].V
, Q
[Q
.Edge
[i
][1]].V
, Q
[Q
.Edge
[i
][2]].V
);
317 Q
.Line
= [false,false,false,false,false,false,false,false,false,false,false,false];
319 // create line pixels
320 Q
.NumPx
= 9 * 2 * CubeSize
;
321 for (var i
= 0; i
< Q
.NumPx
; i
++) CreateP(0,0,0);
323 MTrans
= Translate(MTrans
, Origin
.V
[0], Origin
.V
[1], Origin
.V
[2]);
324 MQube
= MMulti(MTrans
, MQube
);
328 Q
[i
].V
= VMulti(MTrans
, Q
[i
].V
);
334 // Perform a simple sum-based verification.
336 for (var i
= 0; i
< Q
.length
; ++i
) {
338 for (var j
= 0; j
< vector
.length
; ++j
)
341 if (sum
!= validation
[CubeSize
])
342 throw "Error: bad vector sum for CubeSize = " + CubeSize
+ "; expected " + validation
[CubeSize
] + " but got " + sum
;
345 for ( var i
= 20; i
<= 160; i
*= 2 ) {
359 print("JSC EXCEPTION FUZZ: Caught exception: " + e
);