git-svn-id: http://svn.openlayers.org/trunk/openlayers@2931 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
142 lines
4.6 KiB
HTML
142 lines
4.6 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript"><!--
|
|
var point;
|
|
|
|
function test_01_Point_constructor (t) {
|
|
t.plan( 8 );
|
|
|
|
//empty
|
|
point = new OpenLayers.Geometry.Point();
|
|
t.ok( point instanceof OpenLayers.Geometry.Point, "new OpenLayers.Geometry.Point returns point object" );
|
|
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
|
|
|
|
//valid
|
|
var x = 10;
|
|
var y = 20;
|
|
point = new OpenLayers.Geometry.Point(x, y);
|
|
t.ok( point instanceof OpenLayers.Geometry.Point, "new OpenLayers.Geometry.Point returns point object" );
|
|
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
|
|
t.eq( point.x, x, "point.x is set correctly");
|
|
t.eq( point.y, y, "point.y is set correctly");
|
|
t.eq( point.lon, x, "point.lon is set correctly");
|
|
t.eq( point.lat, y, "point.lat is set correctly");
|
|
}
|
|
|
|
function test_02_Point_accessors(t) {
|
|
t.plan( 6 )
|
|
|
|
//valid
|
|
var x = 10;
|
|
var y = 20;
|
|
point = new OpenLayers.Geometry.Point(x, y);
|
|
|
|
t.eq( point.getX(), x, "point.x is get() correctly");
|
|
t.eq( point.getY(), y, "point.y is get() correctly");
|
|
|
|
var x1 = 55;
|
|
var y1 = 73;
|
|
|
|
point.setX(x1);
|
|
point.setY(y1);
|
|
|
|
t.eq( point.x, x1, "point.x is set() correctly");
|
|
t.eq( point.y, y1, "point.y is set() correctly");
|
|
t.eq( point.lon, x1, "point.lon is set() correctly");
|
|
t.eq( point.lat, y1, "point.lat is set() correctly");
|
|
|
|
}
|
|
|
|
function test_03_Point_calculateBounds (t) {
|
|
t.plan(4);
|
|
|
|
var x = 10;
|
|
var y = 20;
|
|
point = new OpenLayers.Geometry.Point(x, y);
|
|
point.calculateBounds();
|
|
t.eq( point.bounds.left, x, "bounds.left is 10" );
|
|
t.eq( point.bounds.right, x, "bounds.right is 10" );
|
|
t.eq( point.bounds.top, y, "bounds.top is 20" );
|
|
t.eq( point.bounds.bottom, y, "bounds.bottom is 20" );
|
|
}
|
|
|
|
function test_04_Point_distanceTo(t) {
|
|
t.plan(2);
|
|
|
|
var x1 = 10;
|
|
var y1 = 20;
|
|
point1 = new OpenLayers.Geometry.Point(x1, y1);
|
|
|
|
var x2 = 100;
|
|
var y2 = 200;
|
|
point2 = new OpenLayers.Geometry.Point(x2, y2);
|
|
|
|
var dist = point1.distanceTo(point2)
|
|
t.eq( dist, 201.24611797498107267682563018581, "distances calculating correctly");
|
|
t.eq( dist, Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)), "distance calculation correct");
|
|
}
|
|
|
|
function test_05_Point_toString(t) {
|
|
t.plan(1);
|
|
|
|
var x = 10;
|
|
var y = 20;
|
|
point = new OpenLayers.Geometry.Point(x, y);
|
|
bounds = point.getBounds();
|
|
t.eq( point.toString(), x + ", " + y, "toString() works" );
|
|
|
|
}
|
|
|
|
function test_06_Point_move(t) {
|
|
t.plan(4);
|
|
|
|
var x = 10;
|
|
var y = 20;
|
|
point = new OpenLayers.Geometry.Point(x, y);
|
|
|
|
var dx = 10 * Math.random();
|
|
var dy = 10 * Math.random();
|
|
point.move(dx, dy);
|
|
t.eq(point.x, x + dx, "move() correctly modifies x");
|
|
t.eq(point.y, y + dy, "move() correctly modifies y");
|
|
t.eq(point.lon, x + dx, "move() correctly modifies lon");
|
|
t.eq(point.lat, y + dy, "move() correctly modifies lat");
|
|
}
|
|
|
|
function test_Point_equals(t) {
|
|
t.plan(3);
|
|
|
|
var x = Math.random() * 100;
|
|
var y = Math.random() * 100;
|
|
var geometry = new OpenLayers.Geometry.Point(x, y);
|
|
var equal = new OpenLayers.Geometry.Point(x, y);
|
|
var offX = new OpenLayers.Geometry.Point(x + 1, y);
|
|
var offY = new OpenLayers.Geometry.Point(x, y + 1);
|
|
t.ok(geometry.equals(equal),
|
|
"equals() returns true for a geometry with equivalent coordinates");
|
|
t.ok(!geometry.equals(offX),
|
|
"equals() returns false for a geometry with offset x");
|
|
t.ok(!geometry.equals(offY),
|
|
"equals() returns false for a geometry with offset y");
|
|
}
|
|
|
|
function test_Point_clone(t) {
|
|
t.plan(2);
|
|
|
|
var x = Math.random() * 100;
|
|
var y = Math.random() * 100;
|
|
var geometry = new OpenLayers.Geometry.Point(x, y);
|
|
var clone = geometry.clone();
|
|
t.ok(clone instanceof OpenLayers.Geometry.Point,
|
|
"clone() creates an OpenLayers.Geometry.Point");
|
|
t.ok(geometry.equals(clone), "clone has equivalent coordinates");
|
|
}
|
|
|
|
// -->
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|