Skip to content

Commit

Permalink
fix ellipse's shell, fix maptalks/issues#552 (#2178)
Browse files Browse the repository at this point in the history
* fix ellipse's shell, fix maptalks/issues#552

* fix ellipse specs
  • Loading branch information
fuzhenn authored Jan 3, 2024
1 parent b54e2c2 commit f02acad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/geometry/Ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Circle from './Circle';
* @instance
*/
const options = {
'numberOfShellPoints': 80
'numberOfShellPoints': 81
};

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ class Ellipse extends CenterMixin(Polygon) {
_getShell() {
const measurer = this._getMeasurer(),
center = this.getCoordinates(),
numberOfPoints = this.options['numberOfShellPoints'],
numberOfPoints = this.options['numberOfShellPoints'] - 1,
width = this.getWidth(),
height = this.getHeight();
const shell = [];
Expand All @@ -125,6 +125,7 @@ class Ellipse extends CenterMixin(Polygon) {
vertex.z = center.z;
shell.push(vertex);
}
shell.push(shell[0].copy());
return shell;
}

Expand Down
12 changes: 6 additions & 6 deletions test/geometry/EllipseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('Geometry.Ellipse', function () {
var ellipse = new maptalks.Ellipse([0, 0], 1000, 800);
var shell = ellipse.getShell();

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

var num = ellipse.options.numberOfShellPoints;
expect(shell).to.have.length(num);
var sumx = 0, sumy = 0, len = shell.length;
var num = ellipse.options.numberOfShellPoints - 1;
expect(shell).to.have.length(ellipse.options.numberOfShellPoints);
var sumx = 0, sumy = 0, len = shell.length - 1;
for (var i = 0; i < len; i++) {
sumx += shell[i].x;
sumy += shell[i].y;
Expand Down

0 comments on commit f02acad

Please sign in to comment.