Skip to content

Commit c5e87ef

Browse files
committed
improve meeting radii
1 parent 1abbd7b commit c5e87ef

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

src/generator.js

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,57 +51,72 @@ export default function generateSvgSquircle(height, width, radius) {
5151
a0xw = a0xF(width),
5252
a0xh = a0xF(height)
5353

54-
/*function mapRange(number, in_min, in_max, out_min, out_max) {
55-
return (number - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
56-
}*/
54+
function mapRange(number, inMin, inMax, outMin, outMax) {
55+
return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
56+
}
5757

58-
// const maxRadius = Math.max(...radius);
58+
function clip(number, min, max) {
59+
return Math.max(min, Math.min(number, max))
60+
}
5961

60-
const yOffsetF = (x) => 0,
61-
hyOffset = yOffsetF(height) || 0,
62-
wyOffset = yOffsetF(width) || 0
62+
const yOffsetF = (r1, r2, l) => {
63+
if (r1 + r2 < l)
64+
return 0
65+
else {
66+
const maximumStraightLengthRatio = 1 / 6
67+
const straightLength = l - (r1 + r2)
68+
const straightLengthRatio = straightLength / l
69+
const clippedStraightLengthRatio = clip(straightLengthRatio, 0, maximumStraightLengthRatio)
70+
const reversedClippedStraightLengthRatio = mapRange(clippedStraightLengthRatio, 0, maximumStraightLengthRatio, maximumStraightLengthRatio, 0)
71+
return reversedClippedStraightLengthRatio * l / 14
72+
}
73+
}
74+
const topYOffset = yOffsetF(radius[1], radius[2], width) || 0
75+
const rightYOffset = yOffsetF(radius[2], radius[3], height) || 0
76+
const bottomYOffset = yOffsetF(radius[3], radius[0], width) || 0
77+
const leftYOffset = yOffsetF(radius[0], radius[1], height) || 0
6378

64-
const startPoint = `${a0xw},${wyOffset}`
79+
const startPoint = `${a0xw},${topYOffset}`
6580

6681
const path = `M${startPoint}
67-
${width / 2 < a0x[1]
82+
${width / 2 < a0x[2]
6883
? ''
6984
: `L${width - a0xw},0`
7085
}
7186
72-
C${width - a1x[1]},0,${width - a2x[1]},0,${width - a3x[1]},${a3y[1]}
73-
C${width - b1x[1]},${b1y[1]},${width - b1y[1]},${b1x[1]},${width - b0y[1]},${b0x[1]}
74-
C${width},${a2x[1]},${width},${a1x[1]},
87+
C${width - a1x[2]},0,${width - a2x[2]},0,${width - a3x[2]},${a3y[2]}
88+
C${width - b1x[2]},${b1y[2]},${width - b1y[2]},${b1x[2]},${width - b0y[2]},${b0x[2]}
89+
C${width},${a2x[2]},${width},${a1x[2]},
7590
76-
${width - hyOffset},${a0xh}
77-
${height / 2 < a0x[2]
91+
${width - rightYOffset},${a0xh}
92+
${height / 2 < a0x[3]
7893
? ''
7994
: `L${width},${height - a0xh}`
8095
}
8196
82-
C${width},${height - a1x[2]},${width},${height - a2x[2]},${width - a3y[2]},${height - a3x[2]}
83-
C${width - b1y[2]},${height - b1x[2]},${width - b1x[2]},${height - b1y[2]},${width - b0x[2]},${height - b0y[2]}
84-
C${width - a2x[2]},${height},${width - a1x[2]},${height},
97+
C${width},${height - a1x[3]},${width},${height - a2x[3]},${width - a3y[3]},${height - a3x[3]}
98+
C${width - b1y[3]},${height - b1x[3]},${width - b1x[3]},${height - b1y[3]},${width - b0x[3]},${height - b0y[3]}
99+
C${width - a2x[3]},${height},${width - a1x[3]},${height},
85100
86-
${width - a0xw},${height - wyOffset}
87-
${width / 2 < a0x[3]
101+
${width - a0xw},${height - bottomYOffset}
102+
${width / 2 < a0x[0]
88103
? ''
89104
: `L${a0xw},${height}`
90105
}
91106
92-
C${a1x[3]},${height},${a2x[3]},${height},${a3x[3]},${height - a3y[3]}
93-
C${b1x[3]},${height - b1y[3]},${b1y[3]},${height - b1x[3]},${b0y[3]},${height - b0x[3]}
94-
C0,${height - a2x[3]},0,${height - a1x[3]},
107+
C${a1x[0]},${height},${a2x[0]},${height},${a3x[0]},${height - a3y[0]}
108+
C${b1x[0]},${height - b1y[0]},${b1y[0]},${height - b1x[0]},${b0y[0]},${height - b0x[0]}
109+
C0,${height - a2x[0]},0,${height - a1x[0]},
95110
96-
${hyOffset},${height - a0xh}
97-
${height / 2 < a0x[0]
111+
${leftYOffset},${height - a0xh}
112+
${height / 2 < a0x[1]
98113
? ''
99114
: `L0,${a0xh}`
100115
}
101116
102-
C0,${a1x[0]},0,${a2x[0]},${a3y[0]},${a3x[0]}
103-
C${b1y[0]},${b1x[0]},${b1x[0]},${b1y[0]},${b0x[0]},${b0y[0]}
104-
C${a2x[0]},0,${a1x[0]},0,${startPoint}
117+
C0,${a1x[1]},0,${a2x[1]},${a3y[1]},${a3x[1]}
118+
C${b1y[1]},${b1x[1]},${b1x[1]},${b1y[1]},${b0x[1]},${b0y[1]}
119+
C${a2x[1]},0,${a1x[1]},0,${startPoint}
105120
Z`
106121
.replace(/[\n ]/g, '')
107122
.replace(/NaN/g, '0')

0 commit comments

Comments
 (0)