Skip to content

Commit 7b7315e

Browse files
committed
Reverse the arc direction
1 parent 2628f58 commit 7b7315e

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

components/use-rough-arrow.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function useRoughArrow(props: {
101101
lineOptions,
102102
);
103103
const angle =
104-
Math.atan2(point2.y - point1.y, point2.x - point1.x) - Math.PI / 2;
104+
Math.atan2(point2.y - point1.y, point2.x - point1.x) + Math.PI / 2;
105105
return {
106106
svg,
107107
angle1: angle,
@@ -122,10 +122,9 @@ export function useRoughArrow(props: {
122122
const chordLength = Math.hypot(dx, dy);
123123

124124
// Unit vector perpendicular to the chord.
125-
// (Here we use (-dy, dx) for the perpendicular direction.)
126125
const n = {
127-
x: -dy / chordLength,
128-
y: dx / chordLength,
126+
x: dy / chordLength,
127+
y: -dx / chordLength,
129128
};
130129

131130
// Offset for the arc's center from the midpoint.
@@ -173,7 +172,7 @@ export function useRoughArrow(props: {
173172
// So we use .path() instead as below.
174173
const largeArcFlag =
175174
centerPositionParam < -1 || 1 < centerPositionParam ? 1 : 0;
176-
const sweepFlag = centerPositionParam > 0 ? 1 : 0;
175+
const sweepFlag = centerPositionParam > 0 ? 0 : 1;
177176
const svg = roughSvg.path(
178177
`M${point1.x} ${point1.y} A${R} ${R} 0 ${largeArcFlag} ${sweepFlag} ${point2.x} ${point2.y}`,
179178
lineOptions,
@@ -249,14 +248,14 @@ export function useRoughArrow(props: {
249248

250249
arrowHead2.setAttribute(
251250
"transform",
252-
`translate(${point2Ref.value.x},${point2Ref.value.y}) rotate(${(arcData.value.angle2 * 180) / Math.PI + (centerPositionParam >= 0 ? 90 : -90)})`,
251+
`translate(${point2Ref.value.x},${point2Ref.value.y}) rotate(${(arcData.value.angle2 * 180) / Math.PI + (centerPositionParam >= 0 ? -90 : 90)})`,
253252
);
254253
svg.value.appendChild(arrowHead2);
255254

256255
if (twoWay) {
257256
arrowHead1.setAttribute(
258257
"transform",
259-
`translate(${point1Ref.value.x},${point1Ref.value.y}) rotate(${(arcData.value.angle1 * 180) / Math.PI + (centerPositionParam >= 0 ? -90 : 90)})`,
258+
`translate(${point1Ref.value.x},${point1Ref.value.y}) rotate(${(arcData.value.angle1 * 180) / Math.PI + (centerPositionParam >= 0 ? 90 : -90)})`,
260259
);
261260
svg.value.appendChild(arrowHead1);
262261
}

slides.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,57 @@ mdc: true
180180

181181
</div>
182182

183+
---
184+
185+
# Arc
186+
187+
<div id="arc-start" absolute left-300px top-400px style="transform: translate(-50%, -50%);">
188+
<code>#arc-start</code>
189+
</div>
190+
<div id="arc-end" absolute left-300px top-100px style="transform: translate(-50%, -50%);">
191+
<code>#arc-end</code>
192+
</div>
193+
194+
<FancyArrow id1="arc-start" id2="arc-end" arc="1.5" color="red" />
195+
<FancyArrow id1="arc-start" id2="arc-end" arc="1.0" color="orange" />
196+
<FancyArrow id1="arc-start" id2="arc-end" arc="0.5" color="yellow" />
197+
<FancyArrow id1="arc-start" id2="arc-end" arc="0.0" color="green" />
198+
<FancyArrow id1="arc-start" id2="arc-end" arc="-0.5" color="blue" />
199+
<FancyArrow id1="arc-start" id2="arc-end" arc="-1.0" color="purple" />
200+
<FancyArrow id1="arc-start" id2="arc-end" arc="-1.5" color="pink" />
201+
202+
<Arrow x1="50" y1="450" x2="550" y2="450" />
203+
204+
<code absolute left-0px top-460px>arc=</code>
205+
<code absolute left-75px top-460px style="transform: translateX(-50%);">-1.5</code>
206+
<code absolute left-150px top-460px style="transform: translateX(-50%);">-1.0</code>
207+
<code absolute left-225px top-460px style="transform: translateX(-50%);">-0.5</code>
208+
<code absolute left-300px top-460px style="transform: translateX(-50%);">0</code>
209+
<code absolute left-375px top-460px style="transform: translateX(-50%);">0.5</code>
210+
<code absolute left-450px top-460px style="transform: translateX(-50%);">1.0</code>
211+
<code absolute left-525px top-460px style="transform: translateX(-50%);">1.5</code>
212+
213+
<div absolute right-0 top-30 w-100>
214+
215+
```html
216+
<div id="arc-start" absolute left-300px top-400px style="transform: translate(-50%, -50%);">
217+
<code>#arc-start</code>
218+
</div>
219+
<div id="arc-end" absolute left-300px top-100px style="transform: translate(-50%, -50%);">
220+
<code>#arc-end</code>
221+
</div>
222+
223+
<FancyArrow arc="1.5" id1="arc-start" id2="arc-end" color="red" />
224+
<FancyArrow arc="1.0" id1="arc-start" id2="arc-end" color="orange" />
225+
<FancyArrow arc="0.5" id1="arc-start" id2="arc-end" color="yellow" />
226+
<FancyArrow arc="0.0" id1="arc-start" id2="arc-end" color="green" />
227+
<FancyArrow arc="-0.5" id1="arc-start" id2="arc-end" color="blue" />
228+
<FancyArrow arc="-1.0" id1="arc-start" id2="arc-end" color="purple" />
229+
<FancyArrow arc="-1.5" id1="arc-start" id2="arc-end" color="pink" />
230+
```
231+
232+
</div>
233+
183234

184235
---
185236

@@ -193,8 +244,8 @@ mdc: true
193244
<span id="bar">Bar</span>
194245
</div>
195246

196-
<FancyArrow v-click="1" forward:delay-100 id1="foo" pos1="bottomleft" id2="bar" pos2="topleft" color="red" width="2" arc="-0.3" seed="1" roughness="2" >Hey</FancyArrow>
197-
<FancyArrow v-click="1" forward:delay-100 id2="foo" pos2="bottomright" id1="bar" pos1="topright" color="red" width="2" arc="-0.3" seed="1" roughness="2" >
247+
<FancyArrow v-click="1" forward:delay-100 id1="foo" pos1="bottomleft" id2="bar" pos2="topleft" color="red" width="2" arc="0.3" seed="1" roughness="2" >Hey</FancyArrow>
248+
<FancyArrow v-click="1" forward:delay-100 id2="foo" pos2="bottomright" id1="bar" pos1="topright" color="red" width="2" arc="0.3" seed="1" roughness="2" >
198249
<span text-red>Ahoy</span>
199250
</FancyArrow>
200251

0 commit comments

Comments
 (0)