Skip to content

Commit 1ca55a1

Browse files
authored
Merge pull request #563 from ibillingsley/oval-fix-2
Oval fix asymmetry
2 parents 95cbadc + 868a6bb commit 1ca55a1

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

runtimes/native/src/framebuffer.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void w4_framebufferRect (int x, int y, int width, int height) {
384384
// Javatpoint has a in depth academic explanation that mostly went over my head:
385385
// https://www.javatpoint.com/computer-graphics-midpoint-ellipse-algorithm
386386
//
387-
// Draws the eliipse by "scanning" along the edge in one quadrant, and mirroring
387+
// Draws the ellipse by "scanning" along the edge in one quadrant, and mirroring
388388
// the movement for the other four quadrants.
389389
//
390390
// There are a lot of details to get correct while implementing this algorithm,
@@ -402,12 +402,11 @@ void w4_framebufferOval (int x, int y, int width, int height) {
402402
uint8_t strokeColor = (dc1 - 1) & 0x3;
403403
uint8_t fillColor = (dc0 - 1) & 0x3;
404404

405-
int a = width;
406-
int b = height;
407-
int b1 = (height + 1) % 2; // Compensates for precision loss when dividing
405+
int a = width - 1;
406+
int b = height - 1;
407+
int b1 = b % 2; // Compensates for precision loss when dividing
408408

409-
int north = y;
410-
north += b / 2; // Precision loss here
409+
int north = y + height / 2; // Precision loss here
411410
int west = x;
412411
int east = x + width - 1;
413412
int south = north - b1; // Compensation here. Moves the bottom line up by

runtimes/web/src/framebuffer.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class Framebuffer {
151151
// Javatpoint has a in depth academic explanation that mostly went over my head:
152152
// https://www.javatpoint.com/computer-graphics-midpoint-ellipse-algorithm
153153
//
154-
// Draws the eliipse by "scanning" along the edge in one quadrant, and mirroring
154+
// Draws the ellipse by "scanning" along the edge in one quadrant, and mirroring
155155
// the movement for the other four quadrants.
156156
//
157157
// There are a lot of details to get correct while implementing this algorithm,
@@ -169,12 +169,11 @@ export class Framebuffer {
169169
const strokeColor = (dc1 - 1) & 0x3;
170170
const fillColor = (dc0 - 1) & 0x3;
171171

172-
let a = width;
173-
const b = height;
174-
let b1 = (height + 1) % 2; // Compensates for precision loss when dividing
172+
let a = width - 1;
173+
const b = height - 1;
174+
let b1 = b % 2; // Compensates for precision loss when dividing
175175

176-
let north = y;
177-
north += Math.floor(b / 2); // Precision loss here
176+
let north = y + Math.floor(height / 2); // Precision loss here
178177
let west = x;
179178
let east = x + width - 1;
180179
let south = north - b1; // Compensation here. Moves the bottom line up by

0 commit comments

Comments
 (0)