Add tests for regular and irregular transformations
This commit is contained in:
@@ -82,6 +82,44 @@
|
||||
control.box.move(center);
|
||||
t.geom_eq(control.handles[0].geometry, control.box.geometry.components[0], "handle moved with box");
|
||||
}
|
||||
|
||||
function test_handleMove(t) {
|
||||
t.plan(16);
|
||||
var map = new OpenLayers.Map("map", {allOverlays: true});
|
||||
var layer = new OpenLayers.Layer.Vector();
|
||||
var feature = new OpenLayers.Feature.Vector(
|
||||
OpenLayers.Geometry.fromWKT("POLYGON((-1 -1, 1 -1, 1 1, -1 1))"));
|
||||
layer.addFeatures([feature]);
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 18);
|
||||
var control = new OpenLayers.Control.TransformFeature(layer);
|
||||
map.addControl(control);
|
||||
control.setFeature(feature);
|
||||
|
||||
var bottomLeft = new OpenLayers.LonLat(-2, -2);
|
||||
control.handles[0].move(bottomLeft);
|
||||
t.geom_eq(control.handles[0].geometry, new OpenLayers.Geometry.Point(-2, -2), "bottom left handle at -2,-2");
|
||||
t.geom_eq(control.handles[1].geometry, new OpenLayers.Geometry.Point(0, -2), "bottom handle at 0,-2");
|
||||
t.geom_eq(control.handles[2].geometry, new OpenLayers.Geometry.Point(2, -2), "bottom right handle at 2,-2");
|
||||
t.geom_eq(control.handles[3].geometry, new OpenLayers.Geometry.Point(2, 0), "right handle at 2,0");
|
||||
t.geom_eq(control.handles[4].geometry, new OpenLayers.Geometry.Point(2, 2), "top right handle at 2,2");
|
||||
t.geom_eq(control.handles[5].geometry, new OpenLayers.Geometry.Point(0, 2), "top handle at 0,2");
|
||||
t.geom_eq(control.handles[6].geometry, new OpenLayers.Geometry.Point(-2, 2), "top left handle at -2,2");
|
||||
t.geom_eq(control.handles[7].geometry, new OpenLayers.Geometry.Point(-2, 0), "left handle at -2,0");
|
||||
|
||||
control.irregular = true;
|
||||
|
||||
var bottomLeft = new OpenLayers.LonLat(-3, -3);
|
||||
control.handles[0].move(bottomLeft);
|
||||
t.geom_eq(control.handles[0].geometry, new OpenLayers.Geometry.Point(-3, -3), "bottom left handle at -3,-3");
|
||||
t.geom_eq(control.handles[1].geometry, new OpenLayers.Geometry.Point(-0.5, -3), "bottom handle at 0,-3");
|
||||
t.geom_eq(control.handles[2].geometry, new OpenLayers.Geometry.Point(2, -3), "bottom right handle at 2,-3");
|
||||
t.geom_eq(control.handles[3].geometry, new OpenLayers.Geometry.Point(2, -0.5), "right handle at 2,0");
|
||||
t.geom_eq(control.handles[4].geometry, new OpenLayers.Geometry.Point(2, 2), "top right handle at 2,2");
|
||||
t.geom_eq(control.handles[5].geometry, new OpenLayers.Geometry.Point(-0.5, 2), "top handle at 0,2");
|
||||
t.geom_eq(control.handles[6].geometry, new OpenLayers.Geometry.Point(-3, 2), "top left handle at -3,2");
|
||||
t.geom_eq(control.handles[7].geometry, new OpenLayers.Geometry.Point(-3, -0.5), "left handle at -3,0");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -34,6 +34,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function assertFloatEqual
|
||||
* Test two objects for floating point equivalence. Throw an exception
|
||||
* if not equivalent.
|
||||
*
|
||||
* Parameters:
|
||||
* got - {Object}
|
||||
* expected - {Object}
|
||||
* msg - {String} The message to be thrown. This message will be appended
|
||||
* with ": got {got} but expected {expected}" where got and expected are
|
||||
* replaced with string representations of the above arguments.
|
||||
*/
|
||||
function assertFloatEqual(got, expected, msg) {
|
||||
if(got === undefined) {
|
||||
got = "undefined";
|
||||
} else if (got === null) {
|
||||
got = "null";
|
||||
}
|
||||
if(expected === undefined) {
|
||||
expected = "undefined";
|
||||
} else if (expected === null) {
|
||||
expected = "null";
|
||||
}
|
||||
if(Math.abs(got - expected) > 0.000000001) {
|
||||
throw msg + ": got '" + got + "' but expected '" + expected + "'";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function assertGeometryEqual
|
||||
* Test two geometries for equivalence. Geometries are considered
|
||||
@@ -58,9 +86,9 @@
|
||||
|
||||
if(got instanceof OpenLayers.Geometry.Point) {
|
||||
// compare points
|
||||
assertEqual(got.x, expected.x, "x mismatch");
|
||||
assertEqual(got.y, expected.y, "y mismatch");
|
||||
assertEqual(got.z, expected.z, "z mismatch");
|
||||
assertFloatEqual(got.x, expected.x, "x mismatch");
|
||||
assertFloatEqual(got.y, expected.y, "y mismatch");
|
||||
assertFloatEqual(got.z, expected.z, "z mismatch");
|
||||
} else {
|
||||
// compare components
|
||||
assertEqual(
|
||||
@@ -107,4 +135,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user