Skip to content

Commit f02acad

Browse files
authored
fix ellipse's shell, fix maptalks/issues#552 (#2178)
* fix ellipse's shell, fix maptalks/issues#552 * fix ellipse specs
1 parent b54e2c2 commit f02acad

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/geometry/Ellipse.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Circle from './Circle';
1212
* @instance
1313
*/
1414
const options = {
15-
'numberOfShellPoints': 80
15+
'numberOfShellPoints': 81
1616
};
1717

1818
/**
@@ -102,7 +102,7 @@ class Ellipse extends CenterMixin(Polygon) {
102102
_getShell() {
103103
const measurer = this._getMeasurer(),
104104
center = this.getCoordinates(),
105-
numberOfPoints = this.options['numberOfShellPoints'],
105+
numberOfPoints = this.options['numberOfShellPoints'] - 1,
106106
width = this.getWidth(),
107107
height = this.getHeight();
108108
const shell = [];
@@ -125,6 +125,7 @@ class Ellipse extends CenterMixin(Polygon) {
125125
vertex.z = center.z;
126126
shell.push(vertex);
127127
}
128+
shell.push(shell[0].copy());
128129
return shell;
129130
}
130131

test/geometry/EllipseSpec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ describe('Geometry.Ellipse', function () {
7777
var ellipse = new maptalks.Ellipse([0, 0], 1000, 800);
7878
var shell = ellipse.getShell();
7979

80-
var num = ellipse.options.numberOfShellPoints;
81-
expect(shell).to.have.length(num);
82-
var sumx = 0, sumy = 0, len = shell.length;
80+
var num = ellipse.options.numberOfShellPoints - 1;
81+
expect(shell).to.have.length(ellipse.options.numberOfShellPoints);
82+
var sumx = 0, sumy = 0, len = shell.length - 1;
8383
for (var i = 0; i < len; i++) {
8484
sumx += shell[i].x;
8585
sumy += shell[i].y;
@@ -96,9 +96,9 @@ describe('Geometry.Ellipse', function () {
9696
var ellipse = new maptalks.Ellipse([0, 0, 100], 1000, 800);
9797
var shell = ellipse.getShell();
9898

99-
var num = ellipse.options.numberOfShellPoints;
100-
expect(shell).to.have.length(num);
101-
var sumx = 0, sumy = 0, len = shell.length;
99+
var num = ellipse.options.numberOfShellPoints - 1;
100+
expect(shell).to.have.length(ellipse.options.numberOfShellPoints);
101+
var sumx = 0, sumy = 0, len = shell.length - 1;
102102
for (var i = 0; i < len; i++) {
103103
sumx += shell[i].x;
104104
sumy += shell[i].y;

0 commit comments

Comments
 (0)