Check-in [e9599cdacc]
Not logged in
Overview
Comment:starting basic work on wireframe_model.js wrote some test cases in seperate page
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9599cdacc73364bfca699076b4884b2ae6169ce
User & Date: Derek on 2013-01-03 20:26:41
Other Links: manifest | tags
Context
2013-01-05
03:08
got the draw function working. Leaf check-in: 4ceaad09ba user: Derek tags: trunk
2013-01-03
20:26
starting basic work on wireframe_model.js wrote some test cases in seperate page check-in: e9599cdacc user: Derek tags: trunk
2013-01-02
17:22
started moving around code in files to factor stuff. check-in: 1514d83c29 user: Derek tags: trunk
Changes

Added test_wireframe_model.html version [d11af1c4b7].




































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

<html>
<head>

<script src="wireframe_model.js"></script>



<script>

////
//  Some helper stuff for running tests.
////


var testcount = 0;

function mustThrowError(func, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	var threwsomething = false;
	try{ func(); }
	catch(excpt){ threwsomething = true; }
	if(!threwsomething)
		throw "'" + testname + "' did not throw an error, it was supposed to throw an error!";
}

function mustNotThrowError(func, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	try{ func(); }
	catch(excpt){
		throw "'" + testname + "' failed and threw an error: " + excpt; }}
		

function assert(value, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	
	if(!value) throw "Assertion " + testname + " failed"; }
	
	
	
////
//
//  WireframeModel test cases.
//
//  You should play around with these to convince yourself that they work the way they are supposed to.
//
////
	
	
var model = new WireframeModel();

mustThrowError(function(){ model.addPoint("hippo"); }, "addpoint hippo");
mustThrowError(function(){ model.addPoint([1, 2, 3, 0]); }, "addpoint too long");
mustThrowError(function(){ model.addPoint(7); });
mustThrowError(function(){ model.addPoint([1, 2, "a"]); });

assert(0 == model.addPoint([1.3845, -0.110, 7]));
assert(1 == model.addPoint([1.3845, -0.110, -7]));

mustThrowError(function(){ model.addLine("dolphin"); }, "addline dolphin");
mustThrowError(function(){ model.addLine([1]); }, "addline too short");
mustThrowError(function(){ model.addLine([-1, 0]); }, "addline out of bounds negative");
mustThrowError(function(){ model.addLine([0, 7]); }, "addline out of bounds");

assert(0 == model.addLine([0, 1]));
assert(1 == model.addLine([1, model.addPoint([-1.3845, -0.110, 7])]));





alert("Tests completed.");

// uncomment when you want to prove must throw error actually does something
// mustThrowError(function(){ }, "check mustthrowerror works. have it do nothing.");






</script>


</head>

<body>
<p>
This is a test page that encapsulates scripts for testing wireframe_model.js
</p>
<p>
If tests are successful, a message will say so and no errors will be thrown.
</p>
</body>

</html>

Modified wireframe_model.js from [0b9640f7fc] to [ba994e1850].

1




2
3
4
5
6
7
8


9
10

11


12




13
14
15
16
17
18
19

































































20


21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27




28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

+
+
+
+







+
+


+

+
+
-
+
+
+
+



-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+









// requires matrix_vector_lib.js
// TODO we could make some libraryless way of checking dependencies and versions.


// global namespace object
var WireframeModel;


(function(){



//  A wireframe model and all the controls needed to move the camera and draw.
//  despite the name, it may also include polygon surfaces.
function __WireframeModel(){

	var WFMObj = this;
	
var origin = [0, 0, 0];
	var view_origin = [0, 0, 0];
	var view_transform = [[1, 0, 0],
	                      [0, 1, 0],
						  [0, 0, 1]];



var points = []; //global
var solo_points = {};
var lines = [];

	var points = []; //global
	var solo_points = {};
	var lines = [];
	
	
	// just because these actual objects is returned
	// doesn't mean you should modify it externally if you can help it.
	
	WFMObj.getPoints = function getPoints(){
		return points; }
	
	WFMObj.getLines = function getLines(){
		return lines; }
	
	WFMObj.getViewTransform = function getViewTransform(){
		return view_transform; }
	
	
	
	WFMObj.addPoint = function addPoint(pt){
		
		//  Check type of passed object.
		if(Array.isArray && !Array.isArray(pt)){  // only check if Array.isArray function is available
			throw "pt object is not an array"; }
			
		if(pt.length != 3){
			throw "pt array object not length 3"; }
		
		for(var i = 0; i < 3; ++i){
			if(isNaN(pt[i])) throw "pt object array does not store a number at index " + i; }
			
		points.push(pt);
		return points.length - 1; }
	
	
	
	WFMObj.addLine = function addLine(line){
		if(Array.isArray && !Array.isArray(line)){
			throw "line object is not an array" }
		
		if(line.length != 2){
			throw "line object must be between 2 points.  line object has length: " + line.length; }
		
		for(var i = 0; i < 2; ++i){
			var ptindex = line[i];
			if(isNaN(ptindex) || Math.floor(ptindex) != ptindex){
				throw "pt ref at index " + i + " of line was not an integer: " + ptindex; }
			
			if(ptindex < 0 || ptindex >= points.length){
				throw "pt ref at index " + i + " of line was not in bounds: " + ptindex; }}
		
		lines.push(line);
		return lines.length - 1; }
				
	
}

//  use constructor as global namespace object.
WireframeModel = __WireframeModel;


})();

/*

var point_projections = [];


var line_midpoint_projections = [];


var highlight_object = null;
var mouse_dragging = false;
var last_mouse_down = null;
var mouse_loc = null;
335
336
337
338
339
340
341
342

343
344
345
410
411
412
413
414
415
416

417
418









-
+

-
-
				ctx.rect(minx, miny, maxx - minx, maxy - miny);
				ctx.stroke(); }}
	}
    
    ctx.fillStyle = "rgb(0,0,0)";
	writeMsg(canvas, msg); }
	
	
*/


})();