arrows: account for another NaN (#2753)

This would happen when trying to translate a zero-width bound arrow.

### Change Type

- [x] `patch` — Bug fix

### Release Notes

- Fixes zero-width arrow NaN computation when moving the label.
pull/2730/head^2
Mime Čuvalo 2024-02-07 15:11:10 +00:00 zatwierdzone przez GitHub
rodzic 4d0aff8f01
commit 3b47a4574d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
5 zmienionych plików z 60 dodań i 1 usunięć

Wyświetl plik

@ -2838,6 +2838,8 @@ export class Vec {
// (undocumented)
static FromArray(v: number[]): Vec;
// (undocumented)
static IsNaN(A: VecLike): boolean;
// (undocumented)
static Len(A: VecLike): number;
// (undocumented)
len(): number;

Wyświetl plik

@ -45400,6 +45400,55 @@
"isAbstract": false,
"name": "FromArray"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Vec.IsNaN:member(1)",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "static IsNaN(A: "
},
{
"kind": "Reference",
"text": "VecLike",
"canonicalReference": "@tldraw/editor!VecLike:type"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Content",
"text": "boolean"
},
{
"kind": "Content",
"text": ";"
}
],
"isStatic": true,
"returnTypeTokenRange": {
"startIndex": 3,
"endIndex": 4
},
"releaseTag": "Public",
"isProtected": false,
"overloadIndex": 1,
"parameters": [
{
"parameterName": "A",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isOptional": false
}
],
"isOptional": false,
"isAbstract": false,
"name": "IsNaN"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Vec#len:member(1)",

Wyświetl plik

@ -452,6 +452,10 @@ export class Vec {
return (A.y - B.y) / (A.x - B.x)
}
static IsNaN(A: VecLike): boolean {
return isNaN(A.x) || isNaN(A.y)
}
static Angle(A: VecLike, B: VecLike): number {
return Math.atan2(B.y - A.y, B.x - A.x)
}

Wyświetl plik

@ -33,7 +33,7 @@ function getArrowPoints(
: ints[0]
}
if (isNaN(P0.x) || isNaN(P0.y)) {
if (Vec.IsNaN(P0)) {
P0 = info.start.point
}

Wyświetl plik

@ -96,6 +96,10 @@ export class PointingArrowLabel extends StateNode {
nextLabelPosition = getPointInArcT(measure, angleStart, angleEnd, _center.angle(nearestPoint))
}
if (isNaN(nextLabelPosition)) {
nextLabelPosition = 0.5
}
this.editor.updateShape<TLArrowShape>(
{ id: shape.id, type: shape.type, props: { labelPosition: nextLabelPosition } },
{ squashing: true }