@@ -61,11 +61,7 @@ export function useRoughArrow(props: {
61
61
twoWay,
62
62
centerPositionParam,
63
63
} = props ;
64
- const options = {
65
- stroke : "currentColor" ,
66
- strokeWidth : width ,
67
- fill : "currentColor" ,
68
- fillStyle : "solid" ,
64
+ const baseOptions = {
69
65
// We don't support the `bowing` param because it's not so effective for arc.
70
66
...( roughness !== undefined && { roughness } ) ,
71
67
...( seed !== undefined && { seed } ) ,
@@ -88,6 +84,12 @@ export function useRoughArrow(props: {
88
84
return ;
89
85
}
90
86
87
+ const lineOptions = {
88
+ ...baseOptions ,
89
+ stroke : "currentColor" ,
90
+ strokeWidth : width ,
91
+ } ;
92
+
91
93
if ( centerPositionParam === 0 ) {
92
94
// Straight line.
93
95
// This can be interpreted as the arc's center is at infinity.
@@ -96,7 +98,7 @@ export function useRoughArrow(props: {
96
98
point1 . y ,
97
99
point2 . x ,
98
100
point2 . y ,
99
- options ,
101
+ lineOptions ,
100
102
) ;
101
103
const angle =
102
104
Math . atan2 ( point2 . y - point1 . y , point2 . x - point1 . x ) - Math . PI / 2 ;
@@ -163,16 +165,18 @@ export function useRoughArrow(props: {
163
165
endAngle += 2 * Math . PI ;
164
166
}
165
167
166
- const D = 2 * R ;
167
- const svg = roughSvg . arc (
168
- center . x ,
169
- center . y ,
170
- D ,
171
- D ,
172
- startAngle ,
173
- endAngle ,
174
- false ,
175
- options ,
168
+ // RoughJS has .arc() method as follows with which we can more easily understand what arc we are drawing (that's why we left it commented out),
169
+ // however, it doesn't work well in our case as https://github.com/whitphx/slidev-addon-fancy-arrow/issues/17
170
+ // because large arcs are drawn too rough with it.
171
+ // const D = 2 * R;
172
+ // const svg = roughSvg.arc(center.x, center.y, D, D, startAngle, endAngle, false, lineOptions);
173
+ // So we use .path() instead as below.
174
+ const largeArcFlag =
175
+ centerPositionParam < - 1 || 1 < centerPositionParam ? 1 : 0 ;
176
+ const sweepFlag = centerPositionParam > 0 ? 1 : 0 ;
177
+ const svg = roughSvg . path (
178
+ `M${ point1 . x } ${ point1 . y } A${ R } ${ R } 0 ${ largeArcFlag } ${ sweepFlag } ${ point2 . x } ${ point2 . y } ` ,
179
+ lineOptions ,
176
180
) ;
177
181
178
182
return {
@@ -197,22 +201,28 @@ export function useRoughArrow(props: {
197
201
return ( 30 * Math . log ( line . value . lineLength ) ) / Math . log ( 200 ) ;
198
202
} ) ;
199
203
200
- const arrowHead1 = computed ( ( ) =>
201
- createArrowHeadSvg (
204
+ const arrowHeads = computed ( ( ) => {
205
+ const arrowHeadOptions = {
206
+ ...baseOptions ,
207
+ stroke : "currentColor" ,
208
+ strokeWidth : width ,
209
+ fill : "currentColor" ,
210
+ fillStyle : "solid" ,
211
+ } ;
212
+ const arrowHead1 = createArrowHeadSvg (
202
213
rc . value as RoughSVG ,
203
214
computedArrowHeadSize . value ,
204
215
arrowHeadType ,
205
- options ,
206
- ) ,
207
- ) ;
208
- const arrowHead2 = computed ( ( ) =>
209
- createArrowHeadSvg (
216
+ arrowHeadOptions ,
217
+ ) ;
218
+ const arrowHead2 = createArrowHeadSvg (
210
219
rc . value as RoughSVG ,
211
220
computedArrowHeadSize . value ,
212
221
arrowHeadType ,
213
- options ,
214
- ) ,
215
- ) ;
222
+ arrowHeadOptions ,
223
+ ) ;
224
+ return [ arrowHead1 , arrowHead2 ] ;
225
+ } ) ;
216
226
217
227
return computed ( ( ) => {
218
228
svg . value . innerHTML = "" ;
@@ -227,18 +237,21 @@ export function useRoughArrow(props: {
227
237
228
238
svg . value . appendChild ( line . value . svg ) ;
229
239
230
- arrowHead2 . value . setAttribute (
240
+ const arrowHead1 = arrowHeads . value [ 0 ] ;
241
+ const arrowHead2 = arrowHeads . value [ 1 ] ;
242
+
243
+ arrowHead2 . setAttribute (
231
244
"transform" ,
232
245
`translate(${ point2Ref . value . x } ,${ point2Ref . value . y } ) rotate(${ ( line . value . angle2 * 180 ) / Math . PI + ( centerPositionParam >= 0 ? 90 : - 90 ) } )` ,
233
246
) ;
234
- svg . value . appendChild ( arrowHead2 . value ) ;
247
+ svg . value . appendChild ( arrowHead2 ) ;
235
248
236
249
if ( twoWay ) {
237
- arrowHead1 . value . setAttribute (
250
+ arrowHead1 . setAttribute (
238
251
"transform" ,
239
252
`translate(${ point1Ref . value . x } ,${ point1Ref . value . y } ) rotate(${ ( line . value . angle1 * 180 ) / Math . PI + ( centerPositionParam >= 0 ? - 90 : 90 ) } )` ,
240
253
) ;
241
- svg . value . appendChild ( arrowHead1 . value ) ;
254
+ svg . value . appendChild ( arrowHead1 ) ;
242
255
}
243
256
244
257
return svg . value . innerHTML ;
0 commit comments