Fix rounding errors when generating ellipse (#198)

* .

* fix for solid arc fill when arc angle is > 180

* fix dot rendering when roughness < 1

* fix rounding error when computing ellipse points
This commit is contained in:
Preet
2021-12-01 11:52:26 -08:00
committed by GitHub
parent eaa2576968
commit e5372d11ae
2 changed files with 4 additions and 2 deletions

View File

@@ -74,7 +74,7 @@ export function ellipse(x: number, y: number, width: number, height: number, o:
export function generateEllipseParams(width: number, height: number, o: ResolvedOptions): EllipseParams {
const psq = Math.sqrt(Math.PI * 2 * Math.sqrt((Math.pow(width / 2, 2) + Math.pow(height / 2, 2)) / 2));
const stepCount = Math.max(o.curveStepCount, (o.curveStepCount / Math.sqrt(200)) * psq);
const stepCount = Math.ceil(Math.max(o.curveStepCount, (o.curveStepCount / Math.sqrt(200)) * psq));
const increment = (Math.PI * 2) / stepCount;
let rx = Math.abs(width / 2);
let ry = Math.abs(height / 2);

View File

@@ -17,7 +17,9 @@
rc.ellipse(300, 350, 380, 280, { roughness: 2 });
rc.ellipse(200, 150, 380, 280, { roughness: 1 });
rc.ellipse(400, 150, 380, 280, { roughness: 0 });
rc.ellipse(400, 150, 100.65800865800863, 17.70129870129859, { roughness: 0 });
rc.ellipse(200, 150, 100, 17, { roughness: 0, fill: 'red' });
rc.ellipse(200, 50, 100, 17, { roughness: 0, fill: 'pink', fillStyle: 'solid' });
</script>
</body>