From 33ef64c9120ad7ba3ce26951356c2e1bbbc360c9 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Thu, 12 Jul 2018 12:52:05 +0200 Subject: [PATCH 1/2] copy ZM values to polygon in makeRegular --- src/ol/geom/Polygon.js | 3 +++ test/spec/ol/geom/polygon.test.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 94af9ba32a..280405ac91 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -434,6 +434,9 @@ export function makeRegular(polygon, center, radius, opt_angle) { const angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides); flatCoordinates[offset] = center[0] + (radius * Math.cos(angle)); flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle)); + for (let j = 2; j < stride; j++) { + flatCoordinates[offset + j] = center[j]; + } } polygon.changed(); } diff --git a/test/spec/ol/geom/polygon.test.js b/test/spec/ol/geom/polygon.test.js index 1964c0e4e2..2fee739827 100644 --- a/test/spec/ol/geom/polygon.test.js +++ b/test/spec/ol/geom/polygon.test.js @@ -605,6 +605,14 @@ describe('ol/geom/Polygon', function() { expect(coordinates[0][0]).to.roughlyEqual(0, 1e-9); expect(coordinates[0][1]).to.roughlyEqual(1, 1e-9); }); + + it('creates a regular polygon, maintaining ZM values', () => { + const circle = new Circle([0, 0, 1, 1], 1, 'XYZM'); + const polygon = fromCircle(circle); + const coordinates = polygon.getLinearRing(0).getCoordinates(); + expect(coordinates[0][2]).to.eql(1); + expect(coordinates[0][3]).to.eql(1); + }); }); }); From 88fbd6e35d7234ef7b678f9cec041b2edc140665 Mon Sep 17 00:00:00 2001 From: Ben Kuster Date: Thu, 12 Jul 2018 17:25:31 +0200 Subject: [PATCH 2/2] moved copying of ZM values to Polygon.fromCircle --- src/ol/geom/Polygon.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ol/geom/Polygon.js b/src/ol/geom/Polygon.js index 280405ac91..eeca8df751 100644 --- a/src/ol/geom/Polygon.js +++ b/src/ol/geom/Polygon.js @@ -404,14 +404,19 @@ export function fromCircle(circle, opt_sides, opt_angle) { const sides = opt_sides ? opt_sides : 32; const stride = circle.getStride(); const layout = circle.getLayout(); + const center = circle.getCenter(); const arrayLength = stride * (sides + 1); const flatCoordinates = new Array(arrayLength); - for (let i = 0; i < arrayLength; i++) { + for (let i = 0; i < arrayLength; i += stride) { flatCoordinates[i] = 0; + flatCoordinates[i + 1] = 0; + for (let j = 2; j < stride; j++) { + flatCoordinates[i + j] = center[j]; + } } const ends = [flatCoordinates.length]; const polygon = new Polygon(flatCoordinates, layout, ends); - makeRegular(polygon, circle.getCenter(), circle.getRadius(), opt_angle); + makeRegular(polygon, center, circle.getRadius(), opt_angle); return polygon; } @@ -434,9 +439,6 @@ export function makeRegular(polygon, center, radius, opt_angle) { const angle = startAngle + (modulo(i, sides) * 2 * Math.PI / sides); flatCoordinates[offset] = center[0] + (radius * Math.cos(angle)); flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle)); - for (let j = 2; j < stride; j++) { - flatCoordinates[offset + j] = center[j]; - } } polygon.changed(); }