Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit d0424f1

Browse files
committed
fix(getFilledCirclePoints): remove duplicates
1 parent 810c368 commit d0424f1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed
Loading

src/utils/geometry/__tests__/getCirclePoints.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ test('filled circle with radius 1', () => {
8383

8484
expect(points.length).toBe(5);
8585
expect(points).toStrictEqual([
86-
{ row: 0, column: 0 },
87-
{ row: 0, column: 1 },
88-
{ row: 1, column: 0 },
8986
{ row: 0, column: -1 },
9087
{ row: -1, column: 0 },
88+
{ row: 0, column: 0 },
89+
{ row: 1, column: 0 },
90+
{ row: 0, column: 1 },
9191
]);
9292
});
9393

@@ -114,7 +114,7 @@ test('filled circle with radius 5', () => {
114114

115115
test('check for points twice in array', () => {
116116
const emptyImage = new Image(5, 5, { colorModel: ImageColorModel.GREY });
117-
const points = getFilledCirclePoints(2, { column: 0, row: 0 });
117+
const points = getFilledCirclePoints(2, { column: 2, row: 2 });
118118

119119
expect(points.length).toBe(21);
120120
expect(

src/utils/geometry/getCirclePoints.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { circle, line } from 'bresenham-zingl';
22

3+
import { deleteDuplicates } from '../../draw/utils/deleteDuplicates';
34
import { Point } from '../../geometry';
45

6+
import { sortByColumnRow } from './points';
7+
58
/**
69
* Get the coordinates of the points on a circle. The reference is the center of the circle.
710
* The first point is the right one and they are then sorted clockwise.
@@ -31,7 +34,7 @@ export function getCirclePoints(radius: number): Point[] {
3134
}
3235

3336
/**
34-
* Get the coordinates of the points in a circle of given radius.
37+
* Get the coordinates of the points in a circle of given radius. The points are sorted by column then row.
3538
*
3639
* @param radius - Radius of the circle.
3740
* @param center - Center of the cirlce.
@@ -69,7 +72,9 @@ export function getFilledCirclePoints(
6972
}
7073
});
7174

72-
return circlePoints;
75+
const sorted = sortByColumnRow(circlePoints);
76+
77+
return deleteDuplicates(sorted);
7378
}
7479

7580
/**

0 commit comments

Comments
 (0)