Ticket #1192: getVertice_getEdges.01.patch
| File getVertice_getEdges.01.patch, 13.6 kB (added by fredj, 1 year ago) |
|---|
-
tests/test_Geometry.html
old new 172 172 173 173 } 174 174 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 175 189 function test_06_Geometry_getLength(t) { 176 190 t.plan(1); 177 191 -
tests/Geometry/test_Rectangle.html
old new 67 67 t.eq(rect.getArea(), testArea, "testArea() works"); 68 68 } 69 69 70 function test_Rectangle_getVertices(t) { 71 t.plan(1); 70 72 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 } 71 77 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 72 86 </script> 73 87 </head> 74 88 <body> -
tests/Geometry/test_Point.html
old new 52 52 t.eq( dist, 201.24611797498107267682563018581, "distances calculating correctly"); 53 53 t.eq( dist, Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)), "distance calculation correct"); 54 54 } 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 } 55 72 56 73 function test_05_Point_toString(t) { 57 74 t.plan(1); -
tests/Geometry/test_Collection.html
old new 225 225 ]; 226 226 t.eq( coll.getArea(), 65, "coll with valid components correctly sums getArea"); 227 227 } 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 } 228 238 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 229 250 function test_99_Collection_destroy(t) { 230 251 t.plan( 1 ); 231 252 coll = new OpenLayers.Geometry.Collection(); -
tests/Feature/test_Vector.html
old new 46 46 "geometry.y property set properly"); 47 47 } 48 48 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)]); 49 54 55 feature = new OpenLayers.Feature.Vector(geometry); 56 57 t.eq(feature.getEdges().length, 3, "getEdges returns the geometry edges"); 50 58 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 51 77 </script> 52 78 </head> 53 79 <body> -
lib/OpenLayers/Geometry/Rectangle.js
old new 89 89 return area; 90 90 }, 91 91 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 92 129 CLASS_NAME: "OpenLayers.Geometry.Rectangle" 93 130 }); -
lib/OpenLayers/Geometry/Polygon.js
old new 38 38 arguments); 39 39 }, 40 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; i++) { 51 edges = edges.concat(this.components[i].getEdges()); 52 } 53 return edges; 54 }, 55 41 56 /** 42 57 * APIMethod: getArea 43 58 * Calculated by subtracting the areas of the internal holes from the -
lib/OpenLayers/Geometry/Point.js
old new 116 116 toShortString: function() { 117 117 return (this.x + ", " + this.y); 118 118 }, 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 }, 119 131 120 132 /** 121 133 * APIMethod: move -
lib/OpenLayers/Geometry/LinearRing.js
old new 81 81 82 82 return added; 83 83 }, 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 84 96 85 97 /** 86 98 * APIMethod: removeComponent -
lib/OpenLayers/Geometry/Collection.js
old new 98 98 }, 99 99 100 100 /** 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 /** 101 131 * APIMethod: calculateBounds 102 132 * Recalculate the bounds by iterating through the components and 103 133 * calling calling extendBounds() on each item. -
lib/OpenLayers/Geometry/LineString.js
old new 28 28 }, 29 29 30 30 /** 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 /** 31 59 * APIMethod: removeComponent 32 60 * Only allows removal of a point if there are three or more points in 33 61 * the linestring. (otherwise the result would be just a single point) -
lib/OpenLayers/Feature/Vector.js
old new 179 179 }, 180 180 181 181 /** 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 /** 182 212 * Method: destroyPopup 183 213 * HACK - we need to decide if all vector features should be able to 184 214 * delete popups -
lib/OpenLayers/Geometry.js
old new 186 186 }, 187 187 188 188 /** 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 /** 189 213 * Method: toString 190 214 * Returns the Well-Known Text representation of a geometry 191 215 *
