OpenLayers OpenLayers

Ticket #1085: Geometry_Rectangle_move.00.patch

File Geometry_Rectangle_move.00.patch, 1.6 kB (added by fredj, 1 year ago)

add the move() function to OpenLayers.Geometry.Rectangle and unit tests

  • tests/Geometry/test_Rectangle.html

    old new  
    7979        t.eq(rect.getArea(), testArea, "testArea() works"); 
    8080    } 
    8181 
     82    function test_Rectangle_move(t) { 
     83        t.plan(5); 
    8284 
     85        var x = 1; 
     86        var y = - 2; 
     87        var w = 10; 
     88        var h = 20; 
     89        var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h); 
    8390 
     91        var dx = 10 * Math.random(); 
     92        var dy = 10 * Math.random(); 
     93 
     94        rect.bounds = "foo"; 
     95        rect.move(dx, dy); 
     96         
     97        t.eq(rect.x, x + dx, "move() correctly modifies x"); 
     98        t.eq(rect.y, y + dy, "move() correctly modifies y"); 
     99        t.eq(rect.width, w, "move() don't modifies width"); 
     100        t.eq(rect.height, h, "move() don't modifies height"); 
     101         
     102        t.ok(rect.bounds == null, "bounds is cleared after a move()"); 
     103    } 
     104 
    84105  </script> 
    85106</head> 
    86107<body> 
  • lib/OpenLayers/Geometry/Rectangle.js

    old new  
    8989        return area; 
    9090    },     
    9191 
     92    /** 
     93     * APIMethod: move 
     94     * Moves a rectangle 
     95     * 
     96     * Parameters: 
     97     * x - {Float} 
     98     * y - {Float} 
     99     */ 
     100    move: function(x, y) { 
     101        this.x = this.x + x; 
     102        this.y = this.y + y; 
     103        this.clearBounds(); 
     104    }, 
     105 
    92106    CLASS_NAME: "OpenLayers.Geometry.Rectangle" 
    93107});