From 319a905ec05ce02b513475720bf453eab99d5612 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Tue, 9 Apr 2019 16:58:36 +0200 Subject: [PATCH] Implement rotate function for circle geometry --- src/ol/geom/Circle.js | 14 ++++++++++++++ test/spec/ol/geom/circle.test.js | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ol/geom/Circle.js b/src/ol/geom/Circle.js index 7ee4ffab44..3b74d5de72 100644 --- a/src/ol/geom/Circle.js +++ b/src/ol/geom/Circle.js @@ -5,6 +5,8 @@ import {createOrUpdate, forEachCorner, intersects} from '../extent.js'; import GeometryType from './GeometryType.js'; import SimpleGeometry from './SimpleGeometry.js'; import {deflateCoordinate} from './flat/deflate.js'; +import {rotate} from './flat/transform.js'; + /** * @classdesc @@ -212,6 +214,18 @@ class Circle extends SimpleGeometry { this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius; this.changed(); } + + /** + * @inheritDoc + * @api + */ + rotate(angle, anchor) { + const center = this.getCenter(); + const stride = this.getStride(); + this.setCenter(rotate(center, 0, center.length, stride, angle, anchor, center)); + this.changed(); + } + } diff --git a/test/spec/ol/geom/circle.test.js b/test/spec/ol/geom/circle.test.js index 7efcf99755..1695f37736 100644 --- a/test/spec/ol/geom/circle.test.js +++ b/test/spec/ol/geom/circle.test.js @@ -263,6 +263,24 @@ describe('ol.geom.Circle', function() { }); + describe('#rotate', function() { + + it('rotates the center around the anchor', function() { + circle.setCenter([1, 0]); + circle.rotate(Math.PI / 2, [2, 0]); + expect(circle.getCenter()).to.eql([2, -1]); + expect(circle.getExtent()).to.eql([1, -2, 3, 0]); + }); + + it('does not change if the anchor equals the center', function() { + const center = [1, 0]; + circle.setCenter(center); + const extent = circle.getExtent(); + circle.rotate(Math.PI / 2, center); + expect(circle.getCenter()).to.eql(center); + expect(circle.getExtent()).to.eql(extent); + }); + }); }); });