mirror of
https://github.com/rough-stuff/rough.git
synced 2026-04-22 03:00:28 -04:00
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:
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user