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.
This commit is contained in:
Mime Čuvalo 2024-02-07 15:11:10 +00:00 committed by GitHub
parent 4d0aff8f01
commit 3b47a4574d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 1 deletions

View file

@ -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;

View file

@ -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)",

View file

@ -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)
}

View file

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

View file

@ -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 }