kopia lustrzana https://github.com/Tldraw/Tldraw
Fix arrows with weird bends crashing (#1540)
This PR prevents a crash when you try to curve an arrow that is pointing a very small distance. Fixes #1533 ### Change Type - [x] `patch` — Bug Fix ### Test Plan 1. Draw a line. 2. Draw an arrow from one point on the line to another point on the line. 3. It might look weird or flicker (that's ok - that's a *different* issue - we can fix it another time). 4. Move the middle handle of the arrow. 5. It should curve the arrow. --- 1. Open this snapshot link: https://www.tldraw.com/s/v2_c_LtB3kVSYEyWuR-aCCrrUn 2. Copy its contents onto your own tldraw. 3. Click on the frog. 4. Drag the handle that's on the frog's face. 5. It shouldn't crash the app. - [ ] Unit Tests - [ ] Webdriver tests ### Release Notes - Fixed a rare crash that could happen when you try to curve an arrow with zero distance.pull/1528/head^2
rodzic
1753190f5c
commit
5d826c926d
|
@ -4,6 +4,7 @@ import {
|
|||
getPointOnCircle,
|
||||
intersectCirclePolygon,
|
||||
intersectCirclePolyline,
|
||||
isSafeFloat,
|
||||
lerpAngles,
|
||||
Matrix2d,
|
||||
PI,
|
||||
|
@ -48,6 +49,15 @@ export function getCurvedArrowInfo(editor: Editor, shape: TLArrowShape, extraBen
|
|||
|
||||
const handleArc = getArcInfo(a, b, c)
|
||||
|
||||
if (
|
||||
handleArc.length === 0 ||
|
||||
handleArc.size === 0 ||
|
||||
!isSafeFloat(handleArc.length) ||
|
||||
!isSafeFloat(handleArc.size)
|
||||
) {
|
||||
return getStraightArrowInfo(editor, shape)
|
||||
}
|
||||
|
||||
const arrowPageTransform = editor.getPageTransform(shape)!
|
||||
|
||||
if (startShapeInfo && !startShapeInfo.isExact) {
|
||||
|
|
|
@ -315,6 +315,9 @@ export function intersectPolygonPolygon(polygonA: VecLike[], polygonB: VecLike[]
|
|||
// @public
|
||||
export function isAngleBetween(a: number, b: number, c: number): boolean;
|
||||
|
||||
// @public
|
||||
export const isSafeFloat: (n: number) => boolean;
|
||||
|
||||
// @public (undocumented)
|
||||
export function isSelectionCorner(selection: string): selection is SelectionCorner;
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ export {
|
|||
getSweep,
|
||||
getWidth,
|
||||
isAngleBetween,
|
||||
isSafeFloat,
|
||||
lerpAngles,
|
||||
longAngleDist,
|
||||
perimeterOfEllipse,
|
||||
|
|
|
@ -674,3 +674,11 @@ export function toDomPrecision(v: number) {
|
|||
export function toFixed(v: number) {
|
||||
return +v.toFixed(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a float is safe to use. ie: Not too big or small.
|
||||
* @public
|
||||
*/
|
||||
export const isSafeFloat = (n: number) => {
|
||||
return Math.abs(n) < Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue