1
|
<html>
|
2
|
<head>
|
3
|
<script src="../lib/OpenLayers.js"></script>
|
4
|
<script type="text/javascript"><!--
|
5
|
var bounds;
|
6
|
function test_01_Bounds_constructor (t) {
|
7
|
t.plan( 11 );
|
8
|
bounds = new OpenLayers.Bounds(0,2,10,4);
|
9
|
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
10
|
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
|
11
|
t.eq( bounds.left, 0, "bounds.left is set correctly" );
|
12
|
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
13
|
t.eq( bounds.right, 10, "bounds.right is set correctly" );
|
14
|
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
15
|
t.eq( bounds.getWidth(), 10, "bounds.getWidth() returns correct value" );
|
16
|
t.eq( bounds.getHeight(), 2, "bounds.getHeight() returns correct value" );
|
17
|
|
18
|
var sz = bounds.getSize();
|
19
|
var size = new OpenLayers.Size(10,2);
|
20
|
t.ok(sz.equals(size),"bounds.getSize() has correct value" );
|
21
|
|
22
|
var center = new OpenLayers.Pixel(5,3);
|
23
|
var boundsCenter = bounds.getCenterPixel();
|
24
|
t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" );
|
25
|
|
26
|
var center = new OpenLayers.LonLat(5,3);
|
27
|
var boundsCenter = bounds.getCenterLonLat();
|
28
|
t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" );
|
29
|
}
|
30
|
|
31
|
function test_02_Bounds_toBBOX(t) {
|
32
|
t.plan( 1 );
|
33
|
bounds = new OpenLayers.Bounds(1,2,3,4);
|
34
|
t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." );
|
35
|
}
|
36
|
|
37
|
function test_03_Bounds_toString(t) {
|
38
|
t.plan( 1 );
|
39
|
bounds = new OpenLayers.Bounds(1,2,3,4);
|
40
|
t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." );
|
41
|
}
|
42
|
|
43
|
function test_04_Bounds_contains(t) {
|
44
|
t.plan( 4 );
|
45
|
bounds = new OpenLayers.Bounds(10,10,40,40);
|
46
|
t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" );
|
47
|
t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" );
|
48
|
t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" );
|
49
|
t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" );
|
50
|
}
|
51
|
|
52
|
function test_05_Bounds_fromString(t) {
|
53
|
t.plan( 10 );
|
54
|
bounds = OpenLayers.Bounds.fromString("1,2,3,4");
|
55
|
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
56
|
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
57
|
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
58
|
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
59
|
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
60
|
|
61
|
bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4");
|
62
|
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
63
|
t.eq( bounds.left, 1.1, "bounds.left is set correctly" );
|
64
|
t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" );
|
65
|
t.eq( bounds.right, 3.3, "bounds.right is set correctly" );
|
66
|
t.eq( bounds.top, 4.4, "bounds.top is set correctly" );
|
67
|
|
68
|
}
|
69
|
|
70
|
function test_06_Bounds_getSize(t) {
|
71
|
t.plan( 1 );
|
72
|
var bounds = new OpenLayers.Bounds(0,10,100,120);
|
73
|
|
74
|
t.ok( bounds.getSize().equals(new OpenLayers.Size(100, 110)), "getCenterPixel() works correctly");
|
75
|
}
|
76
|
|
77
|
function test_07_Bounds_clone(t) {
|
78
|
t.plan( 6 );
|
79
|
var oldBounds = new OpenLayers.Bounds(1,2,3,4);
|
80
|
var bounds = oldBounds.clone();
|
81
|
t.ok( bounds instanceof OpenLayers.Bounds, "clone returns new OpenLayers.Bounds object" );
|
82
|
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
83
|
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
84
|
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
85
|
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
86
|
|
87
|
oldBounds.left = 100;
|
88
|
t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" );
|
89
|
}
|
90
|
|
91
|
function test_08_Bounds_containsBounds(t) {
|
92
|
t.plan( 35 );
|
93
|
containerBounds = new OpenLayers.Bounds(10,10,40,40);
|
94
|
|
95
|
//totally outside
|
96
|
bounds = new OpenLayers.Bounds(0,0,5,5);
|
97
|
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
98
|
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
99
|
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
100
|
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
101
|
t.eq( containerBounds.containsBounds(bounds, true) , false , "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true" );
|
102
|
t.eq( containerBounds.containsBounds(bounds, true, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
103
|
t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
104
|
|
105
|
//totally outside on border
|
106
|
bounds = new OpenLayers.Bounds(15,0,30,10);
|
107
|
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
108
|
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
109
|
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
110
|
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
111
|
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
112
|
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
113
|
t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
114
|
|
115
|
//partially inside
|
116
|
bounds = new OpenLayers.Bounds(20,20,50,30);
|
117
|
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
118
|
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
119
|
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
120
|
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
121
|
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
122
|
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
123
|
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
124
|
|
125
|
//totally inside on border
|
126
|
bounds = new OpenLayers.Bounds(10,20,30,30);
|
127
|
t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")");
|
128
|
t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" );
|
129
|
t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
130
|
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
131
|
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
132
|
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
133
|
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
134
|
|
135
|
//totally inside
|
136
|
bounds = new OpenLayers.Bounds(20,20,30,30);
|
137
|
t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")");
|
138
|
t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" );
|
139
|
t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
140
|
t.eq( containerBounds.containsBounds(bounds, false, false), true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
141
|
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
142
|
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
143
|
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
144
|
}
|
145
|
|
146
|
function test_09_Bounds_determineQuadrant(t) {
|
147
|
|
148
|
t.plan( 4 );
|
149
|
var bounds = new OpenLayers.Bounds(0,0,100,100);
|
150
|
|
151
|
var tl = new OpenLayers.LonLat(25, 75);
|
152
|
var tr = new OpenLayers.LonLat(75, 75);
|
153
|
var bl = new OpenLayers.LonLat(25, 25);
|
154
|
var br = new OpenLayers.LonLat(75, 25);
|
155
|
|
156
|
t.eq( bounds.determineQuadrant(tl), "tl", "bounds.determineQuadrant correctly identifies a coordinate in the top left quadrant");
|
157
|
t.eq( bounds.determineQuadrant(tr), "tr", "bounds.determineQuadrant correctly identifies a coordinate in the top right quadrant");
|
158
|
t.eq( bounds.determineQuadrant(bl), "bl", "bounds.determineQuadrant correctly identifies a coordinate in the bottom left quadrant");
|
159
|
t.eq( bounds.determineQuadrant(br), "br", "bounds.determineQuadrant correctly identifies a coordinate in the bottom right quadrant");
|
160
|
}
|
161
|
|
162
|
function test_10_Bounds_oppositeQuadrant(t) {
|
163
|
|
164
|
t.plan( 4 );
|
165
|
|
166
|
t.eq( OpenLayers.Bounds.oppositeQuadrant("tl"), "br", "OpenLayers.Bounds.oppositeQuadrant returns 'br' for 'tl'");
|
167
|
t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'");
|
168
|
t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'");
|
169
|
t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'");
|
170
|
}
|
171
|
|
172
|
function test_11_Bounds_equals(t) {
|
173
|
t.plan( 3 );
|
174
|
var boundsA = new OpenLayers.Bounds(1,2,3,4);
|
175
|
var boundsB = new OpenLayers.Bounds(1,2,3,4);
|
176
|
var boundsC = new OpenLayers.Bounds(1,5,3,4);
|
177
|
|
178
|
t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." );
|
179
|
t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." );
|
180
|
t.ok( !boundsA.equals(null), "equals() returns false on comparison to null");
|
181
|
}
|
182
|
|
183
|
function test_12_Bounds_getHeight_getWidth(t) {
|
184
|
t.plan( 2 );
|
185
|
var bounds = new OpenLayers.Bounds(10,20,100,120);
|
186
|
|
187
|
t.eq( bounds.getWidth(), 90, "getWidth() works" );
|
188
|
t.eq( bounds.getHeight(), 100, "getHeight() works" );
|
189
|
|
190
|
}
|
191
|
|
192
|
function test_13_Bounds_getCenters(t) {
|
193
|
t.plan( 2 );
|
194
|
var bounds = new OpenLayers.Bounds(0,20,100,120);
|
195
|
|
196
|
t.ok( bounds.getCenterPixel().equals(new OpenLayers.Pixel(50, 70)), "getCenterPixel() works correctly");
|
197
|
t.ok( bounds.getCenterLonLat().equals(new OpenLayers.LonLat(50, 70)), "getCenterLonLat() works correctly");
|
198
|
}
|
199
|
|
200
|
function test_14_Bounds_fromArray(t) {
|
201
|
t.plan( 5 );
|
202
|
|
203
|
var bbox = [1,2,3,4];
|
204
|
bounds = OpenLayers.Bounds.fromArray(bbox);
|
205
|
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
206
|
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
207
|
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
208
|
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
209
|
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
210
|
}
|
211
|
|
212
|
function test_14_Bounds_fromSize(t) {
|
213
|
t.plan( 5 );
|
214
|
|
215
|
var height = 15;
|
216
|
var width = 16;
|
217
|
var size = new OpenLayers.Size(width, height);
|
218
|
bounds = OpenLayers.Bounds.fromSize(size);
|
219
|
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
220
|
t.eq( bounds.left, 0, "bounds.left is set correctly" );
|
221
|
t.eq( bounds.bottom, height, "bounds.bottom is set correctly" );
|
222
|
t.eq( bounds.right, width, "bounds.right is set correctly" );
|
223
|
t.eq( bounds.top, 0, "bounds.top is set correctly" );
|
224
|
}
|
225
|
|
226
|
// -->
|
227
|
</script>
|
228
|
</head>
|
229
|
<body>
|
230
|
</body>
|
231
|
</html>
|
232
|
|