3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 var components = [new OpenLayers.Geometry.Point(10,10),
7 new OpenLayers.Geometry.Point(0,0)];
9 function test_Curve_constructor (t) {
11 curve = new OpenLayers.Geometry.Curve();
12 t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
13 t.eq( curve.CLASS_NAME, "OpenLayers.Geometry.Curve", "curve.CLASS_NAME is set correctly");
14 t.eq( curve.components, [], "curve.components is set correctly");
17 function test_Curve_constructor (t) {
19 curve = new OpenLayers.Geometry.Curve(components);
20 t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
21 t.eq( curve.components.length, 2, "curve.components.length is set correctly");
24 function test_Curve_clone (t) {
26 curve = new OpenLayers.Geometry.Curve(components);
27 curve2 = curve.clone();
28 t.ok( curve2 instanceof OpenLayers.Geometry.Curve, "curve.clone() returns curve object" );
29 t.eq( curve2.components.length, 2, "curve2.components.length is set correctly");
32 function test_Curve_calculateBounds(t) {
36 var curve = new OpenLayers.Geometry.Curve();
37 curve.calculateBounds();
38 t.eq(curve.bounds, null, "bounds null when no components");
40 var p1 = new OpenLayers.Geometry.Point(10,20);
41 var p2 = new OpenLayers.Geometry.Point(30,40);
43 var components = [p1, p2];
44 var curve = new OpenLayers.Geometry.Curve(components);
46 curve.calculateBounds();
48 t.eq(curve.bounds.left, 10, "good left bounds");
49 t.eq(curve.bounds.bottom, 20, "good bottom bounds");
50 t.eq(curve.bounds.right, 30, "good right bounds");
51 t.eq(curve.bounds.top, 40, "good top bounds");
53 var newPoint = new OpenLayers.Geometry.Point(60,70);
54 curve.addComponent(newPoint);
55 curve.calculateBounds();
57 t.eq(curve.bounds.left, 10, "good left bounds");
58 t.eq(curve.bounds.bottom, 20, "good bottom bounds");
59 t.eq(curve.bounds.right, 60, "good right bounds");
60 t.eq(curve.bounds.top, 70, "good top bounds");
62 //nullifying the bounds
65 curve = new OpenLayers.Geometry.Curve(components);
67 curve.calculateBounds();
69 t.eq(curve.bounds.left, 10, "good left bounds");
70 t.eq(curve.bounds.bottom, 20, "good bottom bounds");
71 t.eq(curve.bounds.right, 30, "good right bounds");
72 t.eq(curve.bounds.top, 40, "good top bounds");
76 curve.addComponent(newPoint);
77 curve.calculateBounds();
79 t.eq(curve.bounds.left, 10, "good left bounds");
80 t.eq(curve.bounds.bottom, 20, "good bottom bounds");
81 t.eq(curve.bounds.right, 60, "good right bounds");
82 t.eq(curve.bounds.top, 70, "good top bounds");
86 function test_Curve_addComponent (t) {
88 curve = new OpenLayers.Geometry.Curve(components);
89 curve.addComponent(new OpenLayers.Geometry.Point(20,30));
90 bounds = curve.getBounds();
91 t.eq( curve.components.length, 3, "new point added to array" );
92 t.eq( bounds.top, 30, "top bound is 30 after addComponent" );
93 t.eq( bounds.right, 20, "right bound is 20 after addComponent" );
94 curve.addComponent(new OpenLayers.Geometry.Point(-20,-30), 1);
95 bounds = curve.getBounds();
96 t.eq( curve.components.length, 4, "new point added to array" );
97 t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addComponent" );
98 t.eq( bounds.left, -20, "left bound is 20 after 2nd addComponent" );
99 t.eq( curve.components[1].x, -20, "new point.lon is -20 (index worked)" );
100 t.eq( curve.components[1].y, -30, "new point.lat is -30 (index worked)" );
103 function test_Curve_removeComponent (t) {
105 curve = new OpenLayers.Geometry.Curve(components);
106 curve.removeComponent(curve.components[1]);
107 t.eq( curve.components.length, 1, "curve.components.length is smaller after removeComponent" );
108 t.eq( curve.bounds, null, "curve.bounds nullified after removeComponent (for recalculation)" );
109 bounds = curve.getBounds();
110 t.eq( bounds.left, 10, "left bound is 10 after removeComponent" );
111 t.eq( bounds.bottom, 10, "bottom bound is 10 after removeComponent" );
114 function test_Curve_getLength (t) {
118 curve = new OpenLayers.Geometry.Curve();
119 curve.components = null;
120 t.eq(curve.getLength(), 0, "curve with no components has length 0");
123 curve.components = [];
124 t.eq(curve.getLength(), 0, "curve with empty components has length 0");
127 curve.components = [ new OpenLayers.Geometry.Point(0,0) ];
128 t.eq(curve.getLength(), 0, "curve with only one point has length 0");
131 var newcomponents = [ new OpenLayers.Geometry.Point(0,0),
132 new OpenLayers.Geometry.Point(0,10),
133 new OpenLayers.Geometry.Point(20,10),
134 new OpenLayers.Geometry.Point(20,-10)
137 curve = new OpenLayers.Geometry.Curve(newcomponents);
138 t.eq(curve.getLength(), 50, "curve.getLength returns a reasonably accurate length" );
141 function test_Curve_destroy(t) {
144 var curve = new OpenLayers.Geometry.Curve();
145 curve.components = {};
149 t.ok( curve.components == null, "components is cleared well in destruction");