OpenLayers OpenLayers

Ticket #1192: getVertice_getEdges.01.patch

File getVertice_getEdges.01.patch, 13.6 kB (added by fredj, 1 year ago)

updated version, still not complete.

  • tests/test_Geometry.html

    old new  
    172172     
    173173    } 
    174174     
     175    function test_Geometry_getVertices(t) { 
     176        t.plan(1); 
     177 
     178        var geom = new OpenLayers.Geometry() 
     179        t.eq(geom.getVertices(), [], "getVertices is []"); 
     180    } 
     181 
     182    function test_Geometry_getEdges(t) { 
     183        t.plan(1); 
     184 
     185        var geom = new OpenLayers.Geometry() 
     186        t.eq(geom.getEdges(), [], "getEdges is []"); 
     187    } 
     188 
    175189    function test_06_Geometry_getLength(t) { 
    176190        t.plan(1); 
    177191         
  • tests/Geometry/test_Rectangle.html

    old new  
    6767        t.eq(rect.getArea(), testArea, "testArea() works"); 
    6868    } 
    6969 
     70    function test_Rectangle_getVertices(t) { 
     71        t.plan(1); 
    7072 
     73        var rect = new OpenLayers.Geometry.Rectangle(1, 2, 10, 20); 
     74        var vertices = rect.getVertices(); 
     75        t.eq(vertices.length, 4, "getVertices returns 4 elements"); 
     76    } 
    7177 
     78    function test_Rectangle_getEdges(t) { 
     79        t.plan(1); 
     80 
     81        var rect = new OpenLayers.Geometry.Rectangle(1, 2, 10, 20); 
     82        var edges = rect.getEdges(); 
     83        t.eq(edges.length, 4, "getEdges returns 4 elements"); 
     84    } 
     85 
    7286  </script> 
    7387</head> 
    7488<body> 
  • tests/Geometry/test_Point.html

    old new  
    5252        t.eq( dist, 201.24611797498107267682563018581, "distances calculating correctly"); 
    5353        t.eq( dist, Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)), "distance calculation correct"); 
    5454    } 
     55 
     56    function test_Point_getVertices(t) { 
     57        t.plan(2); 
     58 
     59        point = new OpenLayers.Geometry.Point(0, -50); 
     60        var vertices = point.getVertices(); 
     61 
     62        t.eq(vertices.length, 1, "getVertices returns 1 element"); 
     63        t.ok(point.equals(vertices[0]), "getVertices returned element is ok"); 
     64    } 
     65 
     66    function test_Point_getEdges(t) { 
     67        t.plan(1); 
     68 
     69        point = new OpenLayers.Geometry.Point(-59, 200); 
     70        t.eq(point.getEdges(), [], "getEdges returns []"); 
     71    } 
    5572     
    5673    function test_05_Point_toString(t) { 
    5774        t.plan(1); 
  • tests/Geometry/test_Collection.html

    old new  
    225225        ]; 
    226226        t.eq( coll.getArea(), 65, "coll with valid components correctly sums getArea"); 
    227227    } 
     228 
     229    function test_Collection_getVertices(t) { 
     230        t.plan(1); 
     231         
     232        var coll = new OpenLayers.Geometry.Collection(); 
     233        for (var i = 0; i < 8; i++) { 
     234            coll.addComponents(new OpenLayers.Geometry.Point(Math.random(), Math.random())); 
     235        } 
     236        t.eq(coll.getVertices().length, 8, "getVertices returned element is ok"); 
     237    } 
    228238     
     239    function test_Point_getEdges(t) { 
     240        t.plan(1); 
     241 
     242        var coll = new OpenLayers.Geometry.Collection(); 
     243        for (var i = 0; i < 8; i++) { 
     244            coll.addComponents(new OpenLayers.Geometry.Rectangle(Math.random(), Math.random(),  
     245                                                                 Math.random(), Math.random())); 
     246        } 
     247        t.eq(coll.getEdges().length, (8 * 4), "getEdges returned element is ok"); 
     248    } 
     249 
    229250    function test_99_Collection_destroy(t) { 
    230251        t.plan( 1 ); 
    231252        coll = new OpenLayers.Geometry.Collection(); 
  • tests/Feature/test_Vector.html

    old new  
    4646             "geometry.y property set properly"); 
    4747    } 
    4848         
     49    function test_Feature_Vector_getEdges(t) { 
     50        t.plan(2); 
     51        var geometry = new OpenLayers.Geometry.LinearRing([new OpenLayers.Geometry.Point(10,-20),  
     52                                                           new OpenLayers.Geometry.Point(50,50), 
     53                                                           new OpenLayers.Geometry.Point(-5,3)]); 
    4954 
     55        feature = new OpenLayers.Feature.Vector(geometry); 
     56         
     57        t.eq(feature.getEdges().length, 3, "getEdges returns the geometry edges"); 
    5058 
     59        feature = new OpenLayers.Feature.Vector(); 
     60        t.eq(feature.getEdges(), [], "getEdges returns [] if the geometry is not set"); 
     61    } 
     62 
     63    function test_Feature_Vector_getVertices(t) { 
     64        t.plan(2); 
     65        var geometry = new OpenLayers.Geometry.LinearRing([new OpenLayers.Geometry.Point(10,14),  
     66                                                           new OpenLayers.Geometry.Point(50,50), 
     67                                                           new OpenLayers.Geometry.Point(5,3)]); 
     68 
     69        feature = new OpenLayers.Feature.Vector(geometry); 
     70         
     71        t.eq(feature.getVertices().length, 3, "getVertices returns the geometry edges"); 
     72 
     73        feature = new OpenLayers.Feature.Vector(); 
     74        t.eq(feature.getVertices(), [], "getVertices returns [] if the geometry is not set"); 
     75    } 
     76 
    5177  </script> 
    5278</head> 
    5379<body> 
  • lib/OpenLayers/Geometry/Rectangle.js

    old new  
    8989        return area; 
    9090    },     
    9191 
     92    /** 
     93     * Method: getVertices 
     94     * Returns all the vertices of the geometry. 
     95     * 
     96     * Return: 
     97     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     98     */ 
     99    getVertices: function() { 
     100        return [new OpenLayers.Geometry.Point(this.x, this.y), 
     101                new OpenLayers.Geometry.Point(this.x + this.width, this.y), 
     102                new OpenLayers.Geometry.Point(this.x + this.width,  
     103                                              this.y + this.height), 
     104                new OpenLayers.Geometry.Point(this.x, this.y + this.height)]; 
     105    }, 
     106     
     107    /** 
     108     * Method: getEdges 
     109     * Returns all the edges of the geometry. 
     110     * 
     111     * Return: 
     112     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     113     */ 
     114    getEdges: function() { 
     115        return [new OpenLayers.Geometry.LineString( 
     116                   [new OpenLayers.Geometry.Point(this.x, this.y), 
     117                    new OpenLayers.Geometry.Point(this.x + this.width, this.y)]),  
     118                new OpenLayers.Geometry.LineString( 
     119                    [new OpenLayers.Geometry.Point(this.x + this.width, this.y),  
     120                     new OpenLayers.Geometry.Point(this.x + this.width, this.y + this.height)]),  
     121                new OpenLayers.Geometry.LineString( 
     122                    [new OpenLayers.Geometry.Point(this.x + this.width, this.y + this.height), 
     123                     new OpenLayers.Geometry.Point(this.x, this.y + this.height)]),  
     124                new OpenLayers.Geometry.LineString( 
     125                    [new OpenLayers.Geometry.Point(this.x, this.y + this.height),  
     126                     new OpenLayers.Geometry.Point(this.x, this.y)])]; 
     127    }, 
     128 
    92129    CLASS_NAME: "OpenLayers.Geometry.Rectangle" 
    93130}); 
  • lib/OpenLayers/Geometry/Polygon.js

    old new  
    3838                                                                  arguments); 
    3939    }, 
    4040     
     41    /** 
     42     * Method: getEdges 
     43     * Returns all the edges of the geometry. 
     44     * 
     45     * Return: 
     46     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     47     */ 
     48    getEdges: function() { 
     49        var edges = []; 
     50        for (var i = 0; i < this.components.length; i++) { 
     51            edges = edges.concat(this.components[i].getEdges()); 
     52        } 
     53        return edges; 
     54    }, 
     55 
    4156    /**  
    4257     * APIMethod: getArea 
    4358     * Calculated by subtracting the areas of the internal holes from the  
  • lib/OpenLayers/Geometry/Point.js

    old new  
    116116    toShortString: function() { 
    117117        return (this.x + ", " + this.y); 
    118118    }, 
     119 
     120 
     121    /** 
     122     * Method: getVertices 
     123     * Returns all the vertices of the geometry. 
     124     * 
     125     * Return: 
     126     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     127     */ 
     128    getVertices: function() { 
     129        return [this]; 
     130    }, 
    119131     
    120132    /** 
    121133     * APIMethod: move 
  • lib/OpenLayers/Geometry/LinearRing.js

    old new  
    8181         
    8282        return added; 
    8383    }, 
     84 
     85    /** 
     86     * Method: getVertices 
     87     * Returns all the vertices of the geometry. 
     88     * 
     89     * Return: 
     90     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     91     */ 
     92    getVertices: function() { 
     93        return this.components.slice(0, this.components.length - 1); 
     94    }, 
     95 
    8496     
    8597    /** 
    8698     * APIMethod: removeComponent 
  • lib/OpenLayers/Geometry/Collection.js

    old new  
    9898    }, 
    9999 
    100100    /** 
     101     * Method: getVertices 
     102     * Returns all the vertices of the geometry. 
     103     * 
     104     * Return: 
     105     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     106     */ 
     107    getVertices: function() { 
     108        var vertices = []; 
     109        for(var i = 0; i < this.components.length; i++) { 
     110            vertices = vertices.concat(this.components[i].getVertices());  
     111        } 
     112        return vertices; 
     113    }, 
     114 
     115    /** 
     116     * Method: getEdges 
     117     * Returns all the edges of the geometry. 
     118     * 
     119     * Return: 
     120     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     121     */ 
     122    getEdges: function() { 
     123        var edges = []; 
     124        for(var i = 0; i < this.components.length; i++) { 
     125            edges = edges.concat(this.components[i].getEdges());  
     126        } 
     127        return edges; 
     128    }, 
     129 
     130    /** 
    101131     * APIMethod: calculateBounds 
    102132     * Recalculate the bounds by iterating through the components and  
    103133     * calling calling extendBounds() on each item. 
  • lib/OpenLayers/Geometry/LineString.js

    old new  
    2828    }, 
    2929 
    3030    /** 
     31     * Method: getVertices 
     32     * Returns all the vertices of the geometry. 
     33     * 
     34     * Return: 
     35     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     36     */ 
     37    getVertices: function() { 
     38        return this.components; 
     39    }, 
     40 
     41    /** 
     42     * Method: getEdges 
     43     * Returns all the edges of the geometry. 
     44     * 
     45     * Return: 
     46     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     47     */ 
     48    getEdges: function() { 
     49        var edges = []; 
     50        for (var i = 0; i < this.components.length - 1; i++) { 
     51            var start = this.components[i].clone(); 
     52            var stop = this.components[i + 1].clone(); 
     53            edges = edges.concat(new OpenLayers.Geometry.LineString([start, stop])); 
     54        } 
     55        return edges; 
     56    }, 
     57 
     58    /** 
    3159     * APIMethod: removeComponent 
    3260     * Only allows removal of a point if there are three or more points in  
    3361     * the linestring. (otherwise the result would be just a single point) 
  • lib/OpenLayers/Feature/Vector.js

    old new  
    179179    }, 
    180180 
    181181    /** 
     182     * Method: getVertices 
     183     * Returns all the vertices of the geometry. 
     184     * 
     185     * Return: 
     186     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     187     */ 
     188    getVertices: function() { 
     189        if (this.geometry) { 
     190            return this.geometry.getVertices(); 
     191        } else { 
     192            return []; 
     193        } 
     194    }, 
     195 
     196    /** 
     197     * Method: getEdges 
     198     * Returns all the edges of the geometry. 
     199     * 
     200     * Return: 
     201     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     202     */ 
     203    getEdges: function() { 
     204        if (this.geometry) { 
     205            return this.geometry.getEdges(); 
     206        } else { 
     207            return []; 
     208        } 
     209    }, 
     210 
     211    /** 
    182212     * Method: destroyPopup 
    183213     * HACK - we need to decide if all vector features should be able to 
    184214     * delete popups 
  • lib/OpenLayers/Geometry.js

    old new  
    186186    }, 
    187187 
    188188    /** 
     189     * Method: getVertices 
     190     * Returns all the vertices of the geometry. This method is  
     191     * defined in subclasses. 
     192     * 
     193     * Return: 
     194     * {Array(<OpenLayers.Geometry.Point>)} Vertices 
     195     */ 
     196    getVertices: function() { 
     197        return []; 
     198    }, 
     199     
     200    /** 
     201     * Method: getEdges 
     202     * Returns all the edges of the geometry. This method is  
     203     * defined in subclasses. 
     204     * 
     205     * Return: 
     206     * {Array(<OpenLayers.Geometry.LineString>)} Edges 
     207     */ 
     208    getEdges: function() { 
     209        return []; 
     210    }, 
     211 
     212    /** 
    189213     * Method: toString 
    190214     * Returns the Well-Known Text representation of a geometry 
    191215     *