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

Commit 5fa23ca

Browse files
committed
refactor: shorten the code
1 parent 27eadb1 commit 5fa23ca

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/draw/drawCircleOnImage.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export function drawCircleOnImage(
7474
setBlendedVisiblePixel(newImage, center.column, center.row, fill);
7575
}
7676
//Starting points for the top and bottom row of the circle.
77-
let prevBotRow = center.row + radius;
78-
let prevTopRow = center.row - radius;
77+
let prevRow = center.row + radius;
78+
7979
let index = 0;
8080
circle(center.column, center.row, radius, (column: number, row: number) => {
8181
setBlendedVisiblePixel(newImage, column, row, color);
@@ -92,7 +92,7 @@ export function drawCircleOnImage(
9292
}
9393
// The bresenham algorithm is drawing the circle in 4 parts. We are filling the top and bottom part of the circle. Therefore we check whether the point belongs to top or bottom part through indexes. Index must be 1 or 3 to fill the circle.
9494
// Filling bottom half of the circle.
95-
if ((index - 1) % 4 === 0 && prevBotRow !== row) {
95+
if ((index - 1) % 4 === 0 && prevRow !== row) {
9696
newImage.drawLine(
9797
{ row, column: column + 1 },
9898
{
@@ -101,19 +101,16 @@ export function drawCircleOnImage(
101101
},
102102
{ strokeColor: fill, out: newImage },
103103
);
104-
105-
prevBotRow = row;
104+
prevRow = row;
106105
// Filling top half of the circle.
107-
} else if ((index - 3) % 4 === 0 && prevTopRow !== row) {
108106
newImage.drawLine(
109-
{ row, column: column - 1 },
107+
{ row: center.row - (row - center.row), column: column + 1 },
110108
{
111-
row,
112-
column: center.column - (column - center.column - 1),
109+
row: center.row - (row - center.row),
110+
column: center.column - (column - center.column + 1),
113111
},
114112
{ strokeColor: fill, out: newImage },
115113
);
116-
prevTopRow = row;
117114
}
118115

119116
index++;

0 commit comments

Comments
 (0)