| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
var curve; |
|---|
| 6 |
var components = [new OpenLayers.Geometry.Point(10,10), |
|---|
| 7 |
new OpenLayers.Geometry.Point(0,0)]; |
|---|
| 8 |
|
|---|
| 9 |
function test_Curve_constructor (t) { |
|---|
| 10 |
t.plan( 3 ); |
|---|
| 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"); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
function test_Curve_constructor (t) { |
|---|
| 18 |
t.plan( 2 ); |
|---|
| 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"); |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
function test_Curve_clone (t) { |
|---|
| 25 |
t.plan( 2 ); |
|---|
| 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"); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
function test_Curve_calculateBounds(t) { |
|---|
| 33 |
t.plan( 17 ); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
var curve = new OpenLayers.Geometry.Curve(); |
|---|
| 37 |
curve.calculateBounds(); |
|---|
| 38 |
t.eq(curve.bounds, null, "bounds null when no components"); |
|---|
| 39 |
|
|---|
| 40 |
var p1 = new OpenLayers.Geometry.Point(10,20); |
|---|
| 41 |
var p2 = new OpenLayers.Geometry.Point(30,40); |
|---|
| 42 |
|
|---|
| 43 |
var components = [p1, p2]; |
|---|
| 44 |
var curve = new OpenLayers.Geometry.Curve(components); |
|---|
| 45 |
|
|---|
| 46 |
curve.calculateBounds(); |
|---|
| 47 |
|
|---|
| 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"); |
|---|
| 52 |
|
|---|
| 53 |
var newPoint = new OpenLayers.Geometry.Point(60,70); |
|---|
| 54 |
curve.addComponent(newPoint); |
|---|
| 55 |
curve.calculateBounds(); |
|---|
| 56 |
|
|---|
| 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"); |
|---|
| 61 |
|
|---|
| 62 |
//nullifying the bounds |
|---|
| 63 |
|
|---|
| 64 |
//before calculation |
|---|
| 65 |
curve = new OpenLayers.Geometry.Curve(components); |
|---|
| 66 |
curve.bounds = null; |
|---|
| 67 |
curve.calculateBounds(); |
|---|
| 68 |
|
|---|
| 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"); |
|---|
| 73 |
|
|---|
| 74 |
//before addComponent |
|---|
| 75 |
curve.bounds = null; |
|---|
| 76 |
curve.addComponent(newPoint); |
|---|
| 77 |
curve.calculateBounds(); |
|---|
| 78 |
|
|---|
| 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"); |
|---|
| 83 |
|
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
function test_Curve_addComponent (t) { |
|---|
| 87 |
t.plan( 8 ); |
|---|
| 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)" ); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
function test_Curve_removeComponent (t) { |
|---|
| 104 |
t.plan( 4 ); |
|---|
| 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" ); |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
function test_Curve_getLength (t) { |
|---|
| 115 |
t.plan( 4 ); |
|---|
| 116 |
|
|---|
| 117 |
//no components |
|---|
| 118 |
curve = new OpenLayers.Geometry.Curve(); |
|---|
| 119 |
curve.components = null; |
|---|
| 120 |
t.eq(curve.getLength(), 0, "curve with no components has length 0"); |
|---|
| 121 |
|
|---|
| 122 |
//empty components |
|---|
| 123 |
curve.components = []; |
|---|
| 124 |
t.eq(curve.getLength(), 0, "curve with empty components has length 0"); |
|---|
| 125 |
|
|---|
| 126 |
//single point curve |
|---|
| 127 |
curve.components = [ new OpenLayers.Geometry.Point(0,0) ]; |
|---|
| 128 |
t.eq(curve.getLength(), 0, "curve with only one point has length 0"); |
|---|
| 129 |
|
|---|
| 130 |
//multipoint |
|---|
| 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) |
|---|
| 135 |
]; |
|---|
| 136 |
|
|---|
| 137 |
curve = new OpenLayers.Geometry.Curve(newcomponents); |
|---|
| 138 |
t.eq(curve.getLength(), 50, "curve.getLength returns a reasonably accurate length" ); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
function test_Curve_destroy(t) { |
|---|
| 142 |
t.plan(1); |
|---|
| 143 |
|
|---|
| 144 |
var curve = new OpenLayers.Geometry.Curve(); |
|---|
| 145 |
curve.components = {}; |
|---|
| 146 |
|
|---|
| 147 |
curve.destroy(); |
|---|
| 148 |
|
|---|
| 149 |
t.ok( curve.components == null, "components is cleared well in destruction"); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
</script> |
|---|
| 154 |
</head> |
|---|
| 155 |
<body> |
|---|
| 156 |
</body> |
|---|
| 157 |
</html> |
|---|