Changeset 2931
- Timestamp:
- 03/30/07 17:42:32 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Geometry/Collection.js (modified) (5 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/Curve.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/LineString.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/MultiLineString.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/MultiPoint.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/MultiPolygon.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Geometry/Polygon.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Handler/Path.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Handler/Polygon.js (modified) (1 diff)
- trunk/openlayers/tests/Geometry/test_Collection.html (modified) (2 diffs)
- trunk/openlayers/tests/Geometry/test_LineString.html (modified) (3 diffs)
- trunk/openlayers/tests/Geometry/test_LinearRing.html (modified) (1 diff)
- trunk/openlayers/tests/Geometry/test_MultiPoint.html (modified) (4 diffs)
- trunk/openlayers/tests/Geometry/test_Point.html (modified) (1 diff)
- trunk/openlayers/tests/Geometry/test_Polygon.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Geometry/Collection.js
r2901 r2931 25 25 /** @type Array(OpenLayers.Geometry) */ 26 26 components: null, 27 28 /** 29 * An array of class names representing the types of components that 30 * the collection can include. A null value means the component types 31 * are not restricted. 32 * @type Array(String) 33 */ 34 componentTypes: null, 27 35 28 36 /** … … 60 68 * @type OpenLayers.Geometry.Collection 61 69 */ 62 clone: function (obj) { 63 if (obj == null) { 64 obj = eval("new " + this.CLASS_NAME + "()"); 65 } 66 67 for (var i = 0; i < this.components.length; i++) { 68 obj.addComponent(this.components[i].clone()); 70 clone: function() { 71 var geometry = eval("new " + this.CLASS_NAME + "()"); 72 for(var i=0; i<this.components.length; i++) { 73 geometry.addComponent(this.components[i].clone()); 69 74 } 70 75 71 76 // catch any randomly tagged-on properties 72 OpenLayers.Util.applyDefaults( obj, this);73 74 return obj;77 OpenLayers.Util.applyDefaults(geometry, this); 78 79 return geometry; 75 80 }, 76 81 … … 122 127 }, 123 128 124 /** Add a new component (geometry) to the collection. 129 /** 130 * Add a new component (geometry) to the collection. If this.componentTypes 131 * is set, then the component class name must be in the componentTypes array. 125 132 * 126 133 * The bounds cache is reset. … … 128 135 * @param {OpenLayers.Geometry} component 129 136 * @param {int} index Index into the array to insert the component 137 * @type Boolean 138 * @return Component was successfully added 130 139 */ 131 140 addComponent: function(component, index) { 132 if (component) { 133 134 if (index) { 135 var components1 = this.components.slice(0, index); 136 var components2 = this.components.slice(index, 137 this.components.length); 138 components1.push(component); 139 this.components = components1.concat(components2); 140 } else { 141 this.components.push(component); 141 var added = false; 142 if(component) { 143 if(this.componentTypes == null || 144 (OpenLayers.Util.indexOf(this.componentTypes, 145 component.CLASS_NAME) > -1)) { 146 147 if(index != null && (index < this.components.length)) { 148 var components1 = this.components.slice(0, index); 149 var components2 = this.components.slice(index, 150 this.components.length); 151 components1.push(component); 152 this.components = components1.concat(components2); 153 } else { 154 this.components.push(component); 155 } 156 component.parent = this; 157 this.clearBounds(); 158 added = true; 142 159 } 143 component.parent = this; 144 this.clearBounds(); 145 } 160 } 161 return added; 146 162 }, 147 163 … … 206 222 }, 207 223 224 /** 225 * Tests for equivalent geometries 226 * @param {OpenLayers.Geometry} 227 * @type Boolean 228 * @return The coordinates are equivalent 229 */ 230 equals: function(geometry) { 231 var equivalent = true; 232 if(!geometry.CLASS_NAME || (this.CLASS_NAME != geometry.CLASS_NAME)) { 233 equivalent = false; 234 } else if(!(geometry.components instanceof Array) || 235 (geometry.components.length != this.components.length)) { 236 equivalent = false; 237 } else { 238 for(var i=0; i<this.components.length; ++i) { 239 if(!this.components[i].equals(geometry.components[i])) { 240 equivalent = false; 241 break; 242 } 243 } 244 } 245 return equivalent; 246 }, 247 208 248 /** @final @type String */ 209 249 CLASS_NAME: "OpenLayers.Geometry.Collection" trunk/openlayers/lib/OpenLayers/Geometry/Curve.js
r2803 r2931 17 17 18 18 /** 19 * An array of class names representing the types of components that 20 * the collection can include. A null value means the component types 21 * are not restricted. 22 * @type Array(String) 23 */ 24 componentTypes: ["OpenLayers.Geometry.Point"], 25 26 /** 19 27 * @constructor 20 28 * … … 24 32 OpenLayers.Geometry.MultiPoint.prototype.initialize.apply(this, 25 33 arguments); 26 },27 28 /**29 * @returns An exact clone of this OpenLayers.Feature30 * @type OpenLayers.Feature31 */32 clone: function (obj) {33 if (obj == null) {34 obj = new OpenLayers.Geometry.Curve();35 }36 37 obj = OpenLayers.Geometry.Collection.prototype.clone.apply(this,38 [obj]);39 return obj;40 34 }, 41 35 trunk/openlayers/lib/OpenLayers/Geometry/LineString.js
r2920 r2931 21 21 */ 22 22 initialize: function(points) { 23 OpenLayers.Geometry.Curve.prototype.initialize.apply(this, 24 arguments); 25 }, 26 27 /** 28 * @returns An exact clone of this OpenLayers.Feature 29 * @type OpenLayers.Feature 30 */ 31 clone: function (obj) { 32 if (obj == null) { 33 obj = new OpenLayers.Geometry.LineString(); 34 } 35 36 for (var i = 0; i < this.components.length; i++) { 37 obj.addComponent(this.components[i].clone()); 38 } 39 40 return obj; 23 OpenLayers.Geometry.Curve.prototype.initialize.apply(this, arguments); 41 24 }, 42 25 … … 48 31 removeComponent: function(point) { 49 32 if ( this.components && (this.components.length > 2)) { 50 OpenLayers.Geometry.C urve.prototype.removeComponent.apply(this,33 OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, 51 34 arguments); 52 35 } trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js
r2901 r2931 20 20 21 21 /** 22 * An array of class names representing the types of components that 23 * the collection can include. A null value means the component types 24 * are not restricted. 25 * @type Array(String) 26 */ 27 componentTypes: ["OpenLayers.Geometry.Point"], 28 29 /** 30 * Linear rings are constructed with an array of points. This array 31 * can represent a closed or open ring. If the ring is open (the last 32 * point does not equal the first point), the constructor will close 33 * the ring. If the ring is already closed (the last point does equal 34 * the first point), it will be left closed. 35 * 22 36 * @constructor 23 *24 37 * @param {Array(OpenLayers.Geometry.Point)} points 25 38 */ … … 28 41 arguments); 29 42 }, 30 43 31 44 /** 32 * @returns An exact clone of this OpenLayers.Geometry.LinearRing 33 * @type OpenLayers.Geometry.LinearRing 34 */ 35 clone: function (obj) { 36 if (obj == null) { 37 obj = new OpenLayers.Geometry.LinearRing(); 38 } 39 40 for (var i = 0; i < this.components.length; i++) { 41 obj.addComponent(this.components[i].clone()); 42 } 43 44 return obj; 45 }, 46 47 /** 48 * Adds a point to geometry components 45 * Adds a point to geometry components. If the point is to be added to 46 * the end of the components array and it is the same as the last point 47 * already in that array, the duplicate point is not added. This has the 48 * effect of closing the ring if it is not already closed, and doing the 49 * right thing if it is already closed. This behavior can be overridden 50 * by calling the method with a non-null index as the second argument. 49 51 * 50 52 * @param {OpenLayers.Geometry.Point} point 51 53 * @param {int} index Index into the array to insert the component 52 */ 54 * @type Boolean 55 * @return Point was successfully added 56 */ 53 57 addComponent: function(point, index) { 58 var added = false; 59 54 60 //remove last point 55 61 var lastPoint = this.components[this.components.length-1]; 56 OpenLayers.Geometry.Curve.prototype.removeComponent.apply(this, 57 [lastPoint]); 58 59 //add our point 60 OpenLayers.Geometry.LineString.prototype.addComponent.apply(this, 61 arguments); 62 OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, 63 [lastPoint]); 64 65 // given an index, add the point 66 // without an index only add non-duplicate points 67 if(index != null || !point.equals(lastPoint)) { 68 added = OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, 69 arguments); 70 } 71 62 72 //append copy of first point 63 73 var firstPoint = this.components[0]; 64 OpenLayers.Geometry.C urve.prototype.addComponent.apply(this,74 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, 65 75 [firstPoint.clone()]); 76 77 return added; 66 78 }, 67 79 … … 76 88 //remove last point 77 89 var lastPoint = this.components[this.components.length-1]; 78 OpenLayers.Geometry.C urve.prototype.removeComponent.apply(this,90 OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, 79 91 [lastPoint]); 80 92 81 93 //remove our point 82 OpenLayers.Geometry. LineString.prototype.removeComponent.apply(this,94 OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this, 83 95 arguments); 84 96 //append copy of first point 85 97 var firstPoint = this.components[0]; 86 OpenLayers.Geometry.C urve.prototype.addComponent.apply(this,98 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this, 87 99 [firstPoint.clone()]); 88 100 } trunk/openlayers/lib/OpenLayers/Geometry/MultiLineString.js
r2920 r2931 15 15 16 16 /** 17 * An array of class names representing the types of components that 18 * the collection can include. A null value means the component types 19 * are not restricted. 20 * @type Array(String) 21 */ 22 componentTypes: ["OpenLayers.Geometry.LineString"], 23 24 /** 17 25 * @constructor 18 26 * … … 24 32 }, 25 33 26 /**27 * adds a component to the MultiPoint, checking type28 *29 * @param {OpenLayers.Geometry.LineString} component lineString to add30 * @param {int} index Index into the array to insert the component31 */32 addComponent: function(component, index) {33 if (!(component instanceof OpenLayers.Geometry.LineString)) {34 throw "component should be an OpenLayers.Geometry.LineString";35 }36 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,37 arguments);38 },39 40 34 /** @final @type String */ 41 35 CLASS_NAME: "OpenLayers.Geometry.MultiLineString" trunk/openlayers/lib/OpenLayers/Geometry/MultiPoint.js
r2920 r2931 15 15 16 16 /** 17 * An array of class names representing the types of components that 18 * the collection can include. A null value means the component types 19 * are not restricted. 20 * @type Array(String) 21 */ 22 componentTypes: ["OpenLayers.Geometry.Point"], 23 24 /** 17 25 * @constructor 18 26 * … … 22 30 OpenLayers.Geometry.Collection.prototype.initialize.apply(this, 23 31 arguments); 24 },25 26 /**27 * adds component to the MultiPoint, checking type28 *29 * @param {OpenLayers.Geometry.Point} component point to add30 * @param {int} index Index into the array to insert the component31 */32 addComponent: function(component, index) {33 if (!(component instanceof OpenLayers.Geometry.Point)) {34 throw "component should be an OpenLayers.Geometry.Point";35 }36 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,37 arguments);38 32 }, 39 33 trunk/openlayers/lib/OpenLayers/Geometry/MultiPolygon.js
r2920 r2931 15 15 16 16 /** 17 * An array of class names representing the types of components that 18 * the collection can include. A null value means the component types 19 * are not restricted. 20 * @type Array(String) 21 */ 22 componentTypes: ["OpenLayers.Geometry.Polygon"], 23 24 /** 17 25 * @constructor 18 26 * … … 23 31 arguments); 24 32 }, 25 26 /**27 * adds component to the MultiPolygon, checking type28 *29 * @param {OpenLayers.Geometry.Polygon} component Polygon to add30 * @param {int} index Index into the array to insert the component31 */32 addComponent: function(component, index) {33 if (!(component instanceof OpenLayers.Geometry.Polygon)) {34 var throwStr = "component should be an " +35 "OpenLayers.Geometry.Polygon but is an " +36 component.CLASS_NAME;37 throw throwStr;38 }39 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,40 arguments);41 },42 33 43 34 /** @final @type String */ trunk/openlayers/lib/OpenLayers/Geometry/Polygon.js
r2920 r2931 18 18 19 19 /** 20 * An array of class names representing the types of components that 21 * the collection can include. A null value means the component types 22 * are not restricted. 23 * @type Array(String) 24 */ 25 componentTypes: ["OpenLayers.Geometry.LinearRing"], 26 27 /** 20 28 * @constructor 21 29 * … … 25 33 OpenLayers.Geometry.Collection.prototype.initialize.apply(this, 26 34 arguments); 27 },28 29 /**30 * adds a component to the Polygon, checking type31 *32 * @param {OpenLayers.Geometry.LinearRing} point to add33 * @param {int} index Index into the array to insert the component34 */35 addComponent: function(component, index) {36 if (!(component instanceof OpenLayers.Geometry.LinearRing)) {37 var throwStr = "component should be an " +38 "OpenLayers.Geometry.LinearRing but is a " +39 component.CLASS_NAME;40 throw throwStr;41 42 }43 OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,44 arguments);45 35 }, 46 36 trunk/openlayers/lib/OpenLayers/Handler/Path.js
r2803 r2931 80 80 81 81 /** 82 * Add point to geometry 82 * Add point to geometry. Send the point index to override 83 * the behavior of LinearRing that disregards adding duplicate points. 83 84 */ 84 85 addPoint: function() { 85 this.line.addComponent(this.point.clone() );86 this.line.addComponent(this.point.clone(), this.line.components.length); 86 87 }, 87 88 trunk/openlayers/lib/OpenLayers/Handler/Polygon.js
r2803 r2931 87 87 }, 88 88 89 /** 90 * Handle double-clicks. Finish the geometry and send it back 91 * to the control. 92 * 93 * @param {Event} evt 94 */ 95 dblclick: function(evt) { 96 if(!this.freehandMode(evt)) { 97 // remove the penultimate point 98 var index = this.line.components.length - 2; 99 this.line.removeComponent(this.line.components[index]); 100 this.finalize(this.line); 101 } 102 return false; 103 }, 104 89 105 /** @final @type String */ 90 106 CLASS_NAME: "OpenLayers.Handler.Polygon" trunk/openlayers/tests/Geometry/test_Collection.html
r2803 r2931 143 143 144 144 function test_07_Collection_addComponent(t) { 145 t.plan( 3);146 147 var coll = new OpenLayers.Geometry.Collection(); 148 149 //null145 t.plan(10); 146 147 var coll = new OpenLayers.Geometry.Collection(); 148 149 //null 150 150 coll.addComponent(null); 151 t.ok(true, "no breakage, no executage from null input") 152 153 //good component 151 t.ok(!coll.addComponent(null), 152 "addComponent returns false for bad component") 153 154 //good component 154 155 var component = new OpenLayers.Geometry.Point(3,4); 155 coll.addComponent(component);156 156 t.ok(coll.addComponent(component), 157 "addComponent returns true for good component"); 157 158 t.ok(coll.bounds == null, "bounds cache correctly cleared"); 158 159 … … 164 165 } 165 166 t.ok(foundComponent, "component added to internal array"); 167 168 // restricted components 169 coll.componentTypes = ["OpenLayers.Geometry.Point", 170 "OpenLayers.Geometry.LineString"]; 171 var point1 = new OpenLayers.Geometry.Point(0,0); 172 var point2 = new OpenLayers.Geometry.Point(1,1); 173 var line = new OpenLayers.Geometry.LineString([point1, point2]); 174 var multipoint = new OpenLayers.Geometry.MultiPoint([point1, point2]); 175 176 t.ok(coll.addComponent(point1), 177 "addComponent returns true for 1st geometry type in componentTypes"); 178 t.ok(OpenLayers.Util.indexOf(coll.components, point1) > -1, 179 "addComponent adds 1st restricted type to components array"); 180 t.ok(coll.addComponent(line), 181 "addComponent returns true for 2nd geometry type in componentTypes"); 182 t.ok(OpenLayers.Util.indexOf(coll.components, point1) > -1, 183 "addComponent adds 2nd restricted type to components array"); 184 t.ok(!coll.addComponent(multipoint), 185 "addComponent returns false for geometry type not in componentTypes"); 186 t.ok(OpenLayers.Util.indexOf(coll.components, multipoint) == -1, 187 "addComponent doesn't add restricted type to component array"); 166 188 167 189 } trunk/openlayers/tests/Geometry/test_LineString.html
r2803 r2931 35 35 t.plan(2); 36 36 37 OpenLayers.Geometry.C urve.prototype._removeComponent =38 OpenLayers.Geometry.C urve.prototype.removeComponent;39 OpenLayers.Geometry.C urve.prototype.removeComponent =37 OpenLayers.Geometry.Collection.prototype._removeComponent = 38 OpenLayers.Geometry.Collection.prototype.removeComponent; 39 OpenLayers.Geometry.Collection.prototype.removeComponent = 40 40 function(point) { g_removeComponent = point; }; 41 41 … … 50 50 t.ok(g_removeComponent, components[0], "point removed if 3 points in components"); 51 51 52 OpenLayers.Geometry.C urve.prototype.removeComponent =53 OpenLayers.Geometry.C urve.prototype._removeComponent;52 OpenLayers.Geometry.Collection.prototype.removeComponent = 53 OpenLayers.Geometry.Collection.prototype._removeComponent; 54 54 } 55 55 … … 74 74 } 75 75 76 function test_LineString_equals(t) { 77 t.plan(3); 78 79 var x0 = Math.random() * 100; 80 var y0 = Math.random() * 100; 81 var x1 = Math.random() * 100; 82 var y1 = Math.random() * 100; 83 var point0 = new OpenLayers.Geometry.Point(x0, y0); 84 var point1 = new OpenLayers.Geometry.Point(x1, y1); 85 var geometry = new OpenLayers.Geometry.LineString([point0, point1]); 86 var equal = new OpenLayers.Geometry.LineString([point0, point1]); 87 var offX = new OpenLayers.Geometry.LineString([ 88 new OpenLayers.Geometry.Point(x0 + 1, y0), 89 new OpenLayers.Geometry.Point(x1 + 1, y1)]); 90 var offY = new OpenLayers.Geometry.LineString([ 91 new OpenLayers.Geometry.Point(x0, y0 + 1), 92 new OpenLayers.Geometry.Point(x1, y1 + 1)]); 93 t.ok(geometry.equals(equal), 94 "equals() returns true for a geometry with equivalent coordinates"); 95 t.ok(!geometry.equals(offX), 96 "equals() returns false for a geometry with offset x"); 97 t.ok(!geometry.equals(offY), 98 "equals() returns false for a geometry with offset y"); 99 } 100 101 function test_LineString_clone(t) { 102 t.plan(2); 103 104 var x0 = Math.random() * 100; 105 var y0 = Math.random() * 100; 106 var x1 = Math.random() * 100; 107 var y1 = Math.random() * 100; 108 var point0 = new OpenLayers.Geometry.Point(x0, y0); 109 var point1 = new OpenLayers.Geometry.Point(x1, y1); 110 var geometry = new OpenLayers.Geometry.LineString([point0, point1]); 111 var clone = geometry.clone(); 112 t.ok(clone instanceof OpenLayers.Geometry.LineString, 113 "clone() creates an OpenLayers.Geometry.LineString"); 114 t.ok(geometry.equals(clone), "clone has equivalent coordinates"); 115 } 76 116 77 117 // --> trunk/openlayers/tests/Geometry/test_LinearRing.html
r2899 r2931 24 24 25 25 function test_02_LinearRing_addComponent(t) { 26 t.plan(1 2);26 t.plan(13); 27 27 28 28 var ring = new OpenLayers.Geometry.LinearRing(); 29 29 30 30 var point = new OpenLayers.Geometry.Point(0,0); 31 ring.addComponent( point ); 31 t.ok(ring.addComponent(point), 32 "addComponent returns true for 1st point"); 32 33 t.eq(ring.components.length, 2, "add first point, correct length"); 33 34 t.ok(ring.components[0].equals(point), "point one correct"); 34 35 t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal"); 36 37 newPoint = new OpenLayers.Geometry.Point(10,10); 38 t.ok(ring.addComponent( newPoint ), 39 "addComponent returns true for unique point"); 40 t.eq(ring.components.length, 3, "correctly adds 3rd point"); 41 t.ok(ring.components[0].equals(point), "point one correct"); 42 t.ok(ring.components[1].equals(newPoint), "point one correct"); 43 t.ok(ring.components[2].equals(ring.components[0]), "first and last point equal"); 35 44 36 ring.addComponent( point ); 37 t.eq(ring.components.length, 3, "add second point, correct length"); 38 t.ok(ring.components[0].equals(point), "point one correct"); 39 t.ok(ring.components[1].equals(point), "point two correct"); 40 t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal"); 45 var length = ring.components.length; 46 var clone = ring.components[length - 1].clone(); 47 t.ok(!ring.addComponent(clone), 48 "addComponent returns false for adding a duplicate last point"); 49 t.eq(ring.components.length, length, 50 "components remains unchanged after trying to add duplicate point"); 51 t.ok(ring.addComponent(clone, length - 1), 52 "addComponent returns true when adding a duplicate with an index"); 53 t.eq(ring.components.length, length + 1, 54 "components increase in length after adding a duplicate point with index"); 41 55 42 newPoint = new OpenLayers.Geometry.Point(10,10);43 ring.addComponent( newPoint );44 t.eq(ring.components.length, 4, "correctly adds 3rd point");45 t.ok(ring.components[0].equals(point), "point one correct");46 t.ok(ring.components[1].equals(point), "point two correct");47 t.ok(ring.components[2].equals(newPoint), "point one correct");48 t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");49 56 } 50 57 trunk/openlayers/tests/Geometry/test_MultiPoint.html
r2803 r2931 8 8 function test_01_MultiPoint_constructor (t) { 9 9 t.plan( 2 ); 10 multipoint = new OpenLayers.Geometry.MultiPoint();10 var multipoint = new OpenLayers.Geometry.MultiPoint(); 11 11 t.ok( multipoint instanceof OpenLayers.Geometry.MultiPoint, "new OpenLayers.Geometry.MultiPoint returns multipoint object" ); 12 12 t.eq( multipoint.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "multipoint.CLASS_NAME is set correctly"); … … 15 15 function test_01a_MultiPoint_constructor (t) { 16 16 t.plan( 3 ); 17 multipoint = new OpenLayers.Geometry.MultiPoint([point]);17 var multipoint = new OpenLayers.Geometry.MultiPoint([point]); 18 18 t.ok( multipoint instanceof OpenLayers.Geometry.MultiPoint, "new OpenLayers.Geometry.MultiPoint returns multipoint object" ); 19 19 t.eq( multipoint.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "multipoint.CLASS_NAME is set correctly"); … … 24 24 t.plan(4); 25 25 26 multipoint = new OpenLayers.Geometry.MultiPoint([point]);26 var multipoint = new OpenLayers.Geometry.MultiPoint([point]); 27 27 var x = point.x; 28 28 var y = point.y; … … 37 37 } 38 38 39 function test_MultiPoint_equals(t) { 40 t.plan(3); 41 42 var x = Math.random() * 100; 43 var y = Math.random() * 100; 44 var geometry = new OpenLayers.Geometry.MultiPoint( 45 [new OpenLayers.Geometry.Point(x, y)]); 46 var equal = new OpenLayers.Geometry.MultiPoint( 47 [new OpenLayers.Geometry.Point(x, y)]); 48 var offX = new OpenLayers.Geometry.MultiPoint( 49 [new OpenLayers.Geometry.Point(x + 1, y)]); 50 var offY = new OpenLayers.Geometry.MultiPoint( 51 [new OpenLayers.Geometry.Point(x, y + 1)]); 52 t.ok(geometry.equals(equal), 53 "equals() returns true for a geometry with equivalent coordinates"); 54 t.ok(!geometry.equals(offX), 55 "equals() returns false for a geometry with offset x"); 56 t.ok(!geometry.equals(offY), 57 "equals() returns false for a geometry with offset y"); 58 } 59 60 function test_MultiPoint_clone(t) { 61 t.plan(2); 62 63 var x = Math.random() * 100; 64 var y = Math.random() * 100; 65 var geometry = new OpenLayers.Geometry.MultiPoint( 66 [new OpenLayers.Geometry.Point(x, y)]); 67 var clone = geometry.clone(); 68 t.ok(clone instanceof OpenLayers.Geometry.MultiPoint, 69 "clone() creates an OpenLayers.Geometry.MultiPoint"); 70 t.ok(geometry.equals(clone), "clone has equivalent coordinates"); 71 } 72 39 73 // --> 40 74 </script> trunk/openlayers/tests/Geometry/test_Point.html
r2803 r2931 104 104 t.eq(point.lat, y + dy, "move() correctly modifies lat"); 105 105 } 106 107 function test_Point_equals(t) { 108 t.plan(3); 109 110 var x = Math.random() * 100; 111 var y = Math.random() * 100; 112 var geometry = new OpenLayers.Geometry.Point(x, y); 113 var equal = new OpenLayers.Geometry.Point(x, y); 114 var offX = new OpenLayers.Geometry.Point(x + 1, y); 115 var offY = new OpenLayers.Geometry.Point(x, y + 1); 116 t.ok(geometry.equals(equal), 117 "equals() returns true for a geometry with equivalent coordinates"); 118 t.ok(!geometry.equals(offX), 119 "equals() returns false for a geometry with offset x"); 120 t.ok(!geometry.equals(offY), 121 "equals() returns false for a geometry with offset y"); 122 } 123 124 function test_Point_clone(t) { 125 t.plan(2); 126 127 var x = Math.random() * 100; 128 var y = Math.random() * 100; 129 var geometry = new OpenLayers.Geometry.Point(x, y); 130 var clone = geometry.clone(); 131 t.ok(clone instanceof OpenLayers.Geometry.Point, 132 "clone() creates an OpenLayers.Geometry.Point"); 133 t.ok(geometry.equals(clone), "clone has equivalent coordinates"); 134 } 106 135 107 136 // --> trunk/openlayers/tests/Geometry/test_Polygon.html
r2862 r2931 106 106 t.eq(polygon.components[1].components[0].y, y2 + dy, "move() correctly modifies second y"); 107 107 } 108 109 function test_Polygon_equals(t) { 110 t.plan(3); 111 112 var x0 = Math.random() * 100; 113 var y0 = Math.random() * 100; 114 var x1 = Math.random() * 100; 115 var y1 = Math.random() * 100; 116 var x2 = Math.random() * 100; 117 var y2 = Math.random() * 100; 118 var point0 = new OpenLayers.Geometry.Point(x0, y0); 119 var point1 = new OpenLayers.Geometry.Point(x1, y1); 120 var point2 = new OpenLayers.Geometry.Point(x2, y2); 121 var pointX = new OpenLayers.Geometry.Point(x0 + 1, y0); 122 var pointY = new OpenLayers.Geometry.Point(x0, y0 + 1); 123 var geometry = new OpenLayers.Geometry.Polygon([ 124 new OpenLayers.Geometry.LinearRing([point0, point1, point2])]); 125 var equal = new OpenLayers.Geometry.Polygon([ 126 new OpenLayers.Geometry.LinearRing([point0, point1, point2])]); 127 var offX = new OpenLayers.Geometry.Polygon([ 128 new OpenLayers.Geometry.LinearRing([pointX, point1, point2])]); 129 var offY = new OpenLayers.Geometry.Polygon([ 130 new OpenLayers.Geometry.LinearRing([pointY, point1, point2])]); 131 t.ok(geometry.equals(equal), 132 "equals() returns true for a geometry with equivalent coordinates"); 133 t.ok(!geometry.equals(offX), 134 "equals() returns false for a geometry with offset x"); 135 t.ok(!geometry.equals(offY), 136 "equals() returns false for a geometry with offset y"); 137 } 138 139 function test_Polygon_clone(t) { 140 t.plan(2); 141 142 var x0 = Math.random() * 100; 143 var y0 = Math.random() * 100; 144 var x1 = Math.random() * 100; 145 var y1 = Math.random() * 100; 146 var x2 = Math.random() * 100; 147 var y2 = Math.random() * 100; 148 var point0 = new OpenLayers.Geometry.Point(x0, y0); 149 var point1 = new OpenLayers.Geometry.Point(x1, y1); 150 var point2 = new OpenLayers.Geometry.Point(x2, y2); 151 var geometry = new OpenLayers.Geometry.Polygon([ 152 new OpenLayers.Geometry.LinearRing([point0, point1, point2])]); 153 var clone = geometry.clone(); 154 t.ok(clone instanceof OpenLayers.Geometry.Polygon, 155 "clone() creates an OpenLayers.Geometry.Polygon"); 156 t.ok(geometry.equals(clone), "clone has equivalent coordinates"); 157 } 108 158 109 159 // -->
