[OpenLayers-Commits] r4200 - in sandbox/tschaub/feature: lib/OpenLayers/Geometry lib/OpenLayers/Handler tests/Handler
commits at openlayers.org
commits at openlayers.org
Fri Sep 7 19:59:38 EDT 2007
Author: tschaub
Date: 2007-09-07 19:59:33 -0400 (Fri, 07 Sep 2007)
New Revision: 4200
Modified:
sandbox/tschaub/feature/lib/OpenLayers/Geometry/Polygon.js
sandbox/tschaub/feature/lib/OpenLayers/Handler/RegularPolygon.js
sandbox/tschaub/feature/tests/Handler/test_RegularPolygon.html
Log:
clear bounds after modifying points - don't mess with the last point of a ring - test for correct bounds
Modified: sandbox/tschaub/feature/lib/OpenLayers/Geometry/Polygon.js
===================================================================
--- sandbox/tschaub/feature/lib/OpenLayers/Geometry/Polygon.js 2007-09-07 22:28:22 UTC (rev 4199)
+++ sandbox/tschaub/feature/lib/OpenLayers/Geometry/Polygon.js 2007-09-07 23:59:33 UTC (rev 4200)
@@ -63,7 +63,7 @@
/**
* APIMethod: createRegularPolygon
* Create a regular polygon around a radius. Useful for creating circles
- * and the like.
+ * and the like.
*
* Parameters:
* origin - {<OpenLayers.Geometry.Point>} center of polygon.
@@ -71,10 +71,11 @@
* sides - {Integer} Number of sides. 20 approximates a circle.
* rotation - {Float} original angle of rotation, in degrees.
*/
-OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) {
+OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius,
+ sides, rotation) {
var angle = Math.PI * ((1/sides) - (1/2));
if(rotation) {
- angle += (rotation / 180) * Math.PI;
+ angle += rotation * (Math.PI / 180);
}
var rotateAngle, x, y;
var points = [];
Modified: sandbox/tschaub/feature/lib/OpenLayers/Handler/RegularPolygon.js
===================================================================
--- sandbox/tschaub/feature/lib/OpenLayers/Handler/RegularPolygon.js 2007-09-07 22:28:22 UTC (rev 4199)
+++ sandbox/tschaub/feature/lib/OpenLayers/Handler/RegularPolygon.js 2007-09-07 23:59:33 UTC (rev 4200)
@@ -122,12 +122,12 @@
this.options = (options) ? options : new Object();
},
- /**
- * APIMethod: setOptions
- *
- * Parameters:
- * newOptions - {Object}
- */
+ /**
+ * APIMethod: setOptions
+ *
+ * Parameters:
+ * newOptions - {Object}
+ */
setOptions: function (newOptions) {
OpenLayers.Util.extend(this.options, newOptions);
OpenLayers.Util.extend(this, newOptions);
@@ -277,9 +277,8 @@
angle = this.angle + (i * 2 * Math.PI / this.sides);
point.x = this.origin.x + (this.radius * Math.cos(angle));
point.y = this.origin.y + (this.radius * Math.sin(angle));
+ point.clearBounds();
}
- ring.components[this.sides].x = ring.components[0].x;
- ring.components[this.sides].y = ring.components[0].y;
},
/**
Modified: sandbox/tschaub/feature/tests/Handler/test_RegularPolygon.html
===================================================================
--- sandbox/tschaub/feature/tests/Handler/test_RegularPolygon.html 2007-09-07 22:28:22 UTC (rev 4199)
+++ sandbox/tschaub/feature/tests/Handler/test_RegularPolygon.html 2007-09-07 23:59:33 UTC (rev 4200)
@@ -1,7 +1,7 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
- <script type="text/javascript"><!--
+ <script type="text/javascript">
function test_Handler_RegularPolygon_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
@@ -56,23 +56,35 @@
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds");
- t.eq(handler.feature.geometry.components[0].components.length, 5, "geometry has 5 components");
- t.eq(handler.feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "geometry is a polygon");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-35.15625,-35.15625,35.15625,35.15625",
+ "correct bounds after move");
+ t.eq(handler.feature.geometry.components[0].components.length, 5,
+ "geometry has 5 components");
+ t.eq(handler.feature.geometry.CLASS_NAME,
+ "OpenLayers.Geometry.Polygon",
+ "geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-35.15625,-35.15625,35.15625,35.15625",
+ "correct bounds after move with a fixed radius");
handler.cancel();
handler.setOptions({radius:2 / Math.sqrt(2)});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-1,-1,1,1", "bounds with manual radius setting");
- var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-1,-1,1,1",
+ "bounds with manual radius setting");
+ var evt = {xy: new OpenLayers.Pixel(175, 90), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-1,-1,1,1", "bounds with manual radius setting and mousemove");
- }
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "34.15625,-22.09375,36.15625,-20.09375",
+ "bounds with manual radius setting and mousemove");
+ }
+
function test_Handler_RegularPolygon_circle(t) {
t.plan(7);
var map = new OpenLayers.Map('map');
@@ -86,27 +98,35 @@
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds");
- t.eq(handler.feature.geometry.components[0].components.length, 41, "geometry has correct numbre of components");
- t.eq(handler.feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "geometry is a polygon");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-35.15625,-35.15625,35.15625,35.15625",
+ "correct bounds after move");
+ t.eq(handler.feature.geometry.components[0].components.length, 41,
+ "geometry has correct numbre of components");
+ t.eq(handler.feature.geometry.CLASS_NAME,
+ "OpenLayers.Geometry.Polygon",
+ "geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-35.823348,-35.823348,35.823348,35.823348",
+ "correct bounds after move with fixed radius");
handler.cancel();
handler.setOptions({radius:1});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-0.996917,-0.996917,0.996917,0.996917", "bounds with manual radius setting");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "-0.996917,-0.996917,0.996917,0.996917",
+ "bounds with manual radius setting");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
- t.eq(handler.feature.geometry.getBounds().toBBOX(), "-0.996917,-0.996917,0.996917,0.996917", "bounds with manual radius setting and mousemove");
+ t.eq(handler.feature.geometry.getBounds().toBBOX(),
+ "34.159333,-8.028167,36.153167,-6.034333",
+ "bounds with manual radius setting and mousemove");
}
-
-
- // -->
</script>
</head>
<body>
More information about the Commits
mailing list